Sintaks DDL

Lagi bingung ngerjain praktikum basdat modul 2?? Jangan bingung-bingung lagi.. karena telah ada ringkasan formula tentang sintaks-sintaks DDL..

Ringkasan ini secara tidak sengaja Aryu temukan di folder seseorang di share2 an Kikulu…

Thx a lot yha…
1. Membuat tabel

CREATE TABLE <namatabel> (
<namafield1> <tipedata> <aturan>,
<namafield2> <tipedata> <aturan>,

<namafieldn> <tipedata> <aturan>,
);

Contoh macam2 aturan :
a) DEFAULT ‘L’
b) CHECK (JenisKel = ‘L’ OR JenisKel = ‘P’)
c) NOT NULL
d) NULL

2. Tambahkan field

ALTER TABLE <namatabel>
ADD <namafield> <tipedata> <aturan>

3. Hapus field

ALTER TABLE <namatabel>
DROP COLUMN <namafield>

4. Ganti nama tabel

RENAME <namatabel_lama> TO <namatabel_baru>

5. Ganti nama field

ALTER TABLE <namatabel>
RENAME COLUMN <namafield_lama> TO <namafield_baru>

6. Hapus tabel

DROP TABLE <namatabel>

7. Ubah properti field

ALTER TABLE <namatabel>
MODIFY <namafield> <tipedata> <aturan>

8. Tambahkan constraint primary key

ALTER TABLE <namatabel>
ADD CONSTRAINT <namaconstraint> PRIMARY KEY (namafield)

9. Tambahkan constraint foreign key

ALTER TABLE <namatabel>
ADD CONSTRAINT <namaconstraint> FOREIGN KEY (namafield) REFERENCES <namatabel_referensi> (namafield_referensi)

10. Hapus constraint (primary key maupun foreign key)

ALTER TABLE <namatabel>
DROP CONSTRAINT <namaconstraint>

11. Disable constraint (primary key maupun foreign key)

ALTER TABLE <namatabel>
DISABLE CONSTRAINT <namaconstraint>

12. Enable constraint (primary key maupun foreign key)

ALTER TABLE <namatabel>
ENABLE CONSTRAINT <namaconstraint>

13. Set record

UPDATE <namatabel>
SET <namafield1> = <value> WHERE <namafield2> = <value>

14. Hapus record

DELETE FROM <namatabel>
WHERE <namafield> = <value>

15. Membuat view

CREATE VIEW <namaview> AS <sintaksSQL>

16. Membuat index

CREATE INDEX <nama index> on <nama tabel> (<nama_field>) ;

 

ada yang mau menambahkan?? 😀

Advertisements

2 comments on “Sintaks DDL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s