Data Definition Language

Data Definition Language (DDL) is the language of the DBMS (Database Management System) which is used to create or define the objects in the database. In other words, the DDL is used to define the framework of the database.  
Statement which is often used from DDL include the following :

  • Create database, drop database
  • Create table, drop table, alter table
  • Create view, drop view 
Implementation:


Create database :
Syntax : CREATE DATABASE db_name;
e.g : CREATE DATABASE sentra;

Create table :

Syntax : CREATE TABLE table_name
(column1_name, column1_type,
column2_name, column2_type,…);
e.g : CREATE TABLE MHS
(NRM char(8) not null,
Name char(25) not null,
Address char(30) not null);
Note :
Not null are optional.

Create view :

Syntax : CREATE VIEW view_name [(column1, column2,… )]
AS SELECT statement FROM table_name [WITH CHECK OPTION];
e.g : CREATE VIEW MHSv AS SELECT * FROM MHS;
Note :
View_name: a view which will be made.
Column: name attribute for the view.
Statement: attributes that will be selected from a database table.
Table_name: database table name.

Drop database :

Syntax : Drop database db_name;
e.g : Drop database sentra;

Drop table :

Syntax : Drop table table_name;
e.g : Drop table MHS;

Drop view :
Syntax : Drop view view_name;
e.g : Drop view MHSv;

Alter table : to change the table

Syntax : ALTER TABLE table_name
ADD (column_name_new type_column
[BEFORE column_name])
MODIFY (column_name _ previous type_column)
DROP (nama_kolom_lama type_kolom);
e.g : ALTER TABLE MHS ADD (PHONE number(15));

source : DDL

0 comments

Posting Komentar