0% found this document useful (0 votes)
15 views4 pages

Structured Query Language DDL - Data Definition Language: 14CS440 / Database Management Systems

The document discusses the SQL Data Definition Language (DDL) which defines database structures like tables and indexes. It describes the main DDL commands: CREATE is used to create new database objects; ALTER modifies existing objects by adding, dropping, or changing columns and constraints; DROP removes objects from the database. Examples are provided for creating tables with column and table constraints using the CREATE command and modifying tables using ALTER and DROP.

Uploaded by

MOHITSHARMA 0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
15 views4 pages

Structured Query Language DDL - Data Definition Language: 14CS440 / Database Management Systems

The document discusses the SQL Data Definition Language (DDL) which defines database structures like tables and indexes. It describes the main DDL commands: CREATE is used to create new database objects; ALTER modifies existing objects by adding, dropping, or changing columns and constraints; DROP removes objects from the database. Examples are provided for creating tables with column and table constraints using the CREATE command and modifying tables using ALTER and DROP.

Uploaded by

MOHITSHARMA 0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

14CS440 / Database Management Systems 2018

Structured Query Language

DDL - Data Definition Language


 The SQL data-definition language allows the specification of
information about relations, including:
o The schema for each relation.
o The domain of values associated with each attribute.
o Integrity constraints
 DDL is a standard for commands that define the different structures
(database objects) like Table, Index, View, Synonym, Sequence in a
database.
 DDL statements create, modify, and remove database objects such as
tables, indexes, and users.
 Common DDL statements are CREATE, ALTER, and DROP.

1. CREATE command:
 The CREATE statement is used to create an object with the description
like the domain (column), domain_type (data type) and integrity
constraints .
 Objects: Table, Index, View, Synonym, Sequence.
 Domain type: char, varchar, date, number, integer, lob, etc.
Rajeswari A.M. Page 1 of 4
14CS440 / Database Management Systems 2018

Example:
1. STUDENT( regno, name, branch )
2. MARK ( regno, test_no, sub1, sub2, sub3, result )

 CREATE TABLE student


(regno char(6) constraint p2 primary key, // column level constraint

name varchar(20) not null,


branch char(4), constraint c1 check (regno='%c%'));

 CREATE TABLE mark


(regno char(6), sub1 number(4,2), sub2 number(4,2),
sub3 number(4,2), result char(4) ,
constraint f2 foreign key(regno) references student2(regno) on delete
cascade / on delete set null); // table level constraint

 SELECT constraint_name, constraint_type, search_condition from


user_constraints where table_name= 'STUDENT';

CONSTRAINT_NAME C SEARCH_CONDITION
--------------------------------------------------------------------------------
SYS_C001362 C "NAME" IS NOT NULL
P2 P

Rajeswari A.M. Page 2 of 4


14CS440 / Database Management Systems 2018

 CREATE TABLE student1


(regno char(6) constraint u1 unique ,
name varchar(20) not null,
branch char(4), constraint c1 check(regno='%c%')); // table level constraint

 SELECT constraint_name,constraint_type,search_condition from


user_constraints where table_name= 'STUDENT1';

CONSTRAINT_NAME C SEARCH_CONDITION
--------------------------------------------------------------------------------
SYS_C001368 C "NAME" IS NOT NULL
F2 R
U1 U

2. DROP command:
 The SQL DROP statement is used to remove an object from the
database.
 If you drop a table, all the rows in the table are deleted and the table
structure is removed from the database.
 Once a table is dropped we cannot get it back.
 Example:
o DROP TABLE student;
o DROP TABLE mark;

Rajeswari A.M. Page 3 of 4


14CS440 / Database Management Systems 2018

3. ALTER command:
 The ALTER TABLE statement is used to add, delete, or modify
columns in an existing table.
 The ALTER TABLE statement is also used to add and drop various
constraints on an existing table.
 ALTER – ADD option
ALTER TABLE table_name ADD (column_1 column-definition,
column_2 column-definition, ... column_n column_definition);
 ALTER – MODIFY option
ALTER TABLE table_name MODIFY (column_1 column_type,
column_2 column_type, ... column_n column_type);
 ALTER – DROP option
ALTER TABLE table_name DROP COLUMN column_name;
(not able to drop multiple columns at a time)
Example:
 ALTER table student DROP primary key cascade;
 CREATE TABLE student1
(regno char(6),name varchar(20),branch char(4));
 ALTER TABLE student1 ADD constraint p1 primary key (regno);
**************

Rajeswari A.M. Page 4 of 4

You might also like