Konversi implisit

Fungsi untuk Memanipulasi Data di SQL Server

Ana Voicu

Data Engineer

Perbandingan data

Perlu diingat: untuk membandingkan dua nilai, keduanya harus bertipe sama.

Jika tidak:

  • SQL Server mengonversi dari satu tipe ke tipe lain (IMPLISIT)
  • Pengembang mengonversi data secara eksplisit (EKSPLISIT)
Fungsi untuk Memanipulasi Data di SQL Server

Contoh konversi yang mungkin

SELECT 
    company
    bean_type,
    cocoa_percent
FROM ratings;
Fungsi untuk Memanipulasi Data di SQL Server

Contoh konversi yang mungkin

SELECT 
    company
    bean_type,
    cocoa_percent
FROM ratings
WHERE cocoa_percent > 0.5; 

| company | bean_type  | cocoa_percent |
|---------|------------|---------------|
| Amedei  | Blend      | 0.7000        |
| Bonnat  | Trinitario | 0.7500        |
| ...     | ...        | ...           |
Fungsi untuk Memanipulasi Data di SQL Server

Contoh konversi yang mungkin

SELECT 
    company
    bean_type,
    cocoa_percent
FROM ratings
WHERE cocoa_percent > -2; 

| company | bean_type  | cocoa_percent |
|---------|------------|---------------|
| Amedei  | Blend      | 0.7000        |
| Bonnat  | Trinitario | 0.7500        |
| ...     | ...        | ...           |
Fungsi untuk Memanipulasi Data di SQL Server

Contoh konversi yang mungkin

SELECT 
    company
    bean_type,
    cocoa_percent
FROM ratings
WHERE cocoa_percent > GETDATE();

| company | bean_type  | cocoa_percent |
|---------|------------|---------------|
| ...     | ...        | ...           |
Fungsi untuk Memanipulasi Data di SQL Server

Contoh konversi yang mungkin

SELECT 
    company
    bean_type,
    cocoa_percent
FROM ratings
WHERE cocoa_percent > 'A';


| result                                         | 
|------------------------------------------------|
| Error converting data type varchar to numeric. |
Fungsi untuk Memanipulasi Data di SQL Server

Contoh konversi yang mungkin

SELECT 
    company
    bean_type,
    cocoa_percent
FROM ratings
WHERE cocoa_percent > '0.5';
| company | bean_type  | cocoa_percent |
|---------|------------|---------------|
| Amedei  | Blend      | 0.7000        |
| Bonnat  | Trinitario | 0.7500        |
| ...     | ...        | ...           |
Fungsi untuk Memanipulasi Data di SQL Server

Prioritas tipe data

Prioritas tipe data

Fungsi untuk Memanipulasi Data di SQL Server

Prioritas tipe data

Fungsi untuk Memanipulasi Data di SQL Server

Konversi implisit antar tipe data

Tabel konversi implisit

Fungsi untuk Memanipulasi Data di SQL Server

Dampak kinerja dari konversi implisit

  • Konversi implisit dilakukan per baris kueri
  • Dapat dicegah dengan desain skema basis data yang baik.
Fungsi untuk Memanipulasi Data di SQL Server

Ayo berlatih!

Fungsi untuk Memanipulasi Data di SQL Server

Preparing Video For Download...