Selasa, 27 September 2016

Resume Pemograman SQL, 27 September 2016


1. Create Table
Contoh Dengan Perintah Constraints :
 

CREATE TABLE barang (
       kode_barang char(6),
       nama_barang varchar(25),
       satuan_barang varchar(20),
       stok_barang numeric(4)

constraint pk_barang primary key (kode_barang);
);

CREATE TABLE pasok(

kode_pasok char(10),
kode_barang char(6),
kode_supplier char(10),
tanggal_pasok date,
jumlah_pasok numeric,

constraint pk_pasok primary key(kode_pasok),
constraint fk_pasok_barang foreign key (kode_barang) references barang(kode_barang),
constraint fk_pasok_supplier foreign key (kode_supplier) references supplier(kode_supplier)
);

drop table pasok
sp_columns pasok
2.ALTER TABLE
Modifikasi pendefinisian tabel :
Beberapa sistem database tidak mendukung penghapusan (dropping) suatu kolom pada tabel
Tipe data saat dimodifikasi jika suatu kolom tidak memiliki nilai

ALTER TABLE nama_tabel
    ADD/MODIFY nama_field tipe_data(lebar_field)
ALTER TABLE suplier
    ADD Alamat_Suplier varchar(5
ATAU
ALTER TABLE suplier
    MODIFY Nama_Suplier varchar(25);



DDL
3. Remove Table
Perintah yang digunakan untuk menghapus tabel secara keseluruhan
DROP TABLE table_name;
DROP TABLE pasok