Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
83 views

SQL Data Definition Language PDF

DDL stands for Data Definition Language and is used to define and modify database structures and schemas. The main DDL commands are CREATE, DROP, ALTER, RENAME, and TRUNCATE. CREATE is used to create new tables, DROP deletes tables, ALTER modifies existing tables, RENAME renames tables, and TRUNCATE empties all records from a table.

Uploaded by

Rohini AI&DS
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

SQL Data Definition Language PDF

DDL stands for Data Definition Language and is used to define and modify database structures and schemas. The main DDL commands are CREATE, DROP, ALTER, RENAME, and TRUNCATE. CREATE is used to create new tables, DROP deletes tables, ALTER modifies existing tables, RENAME renames tables, and TRUNCATE empties all records from a table.

Uploaded by

Rohini AI&DS
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

SQL Data Definition Language (DDL):

Introduction to DDL

• DDL stands for Data Definition Language.


• It is a language used for defining and modifying the data and its
structure.
• It is used to build and modify the structure of your tables and other
objects in the database.
DDL commands are as follows,
1. CREATE
2. DROP
3. ALTER
4. RENAME
5. TRUNCATE

• These commands can be used to add, remove or modify tables within a


database.
• DDL has pre-defined syntax for describing the data.
1. CREATE COMMAND

• CREATE command is used for creating objects in the database.


• It creates a new table.

Syntax:
CREATE TABLE <table_name>
( column_name1 datatype,
column_name2 datatype,
.
.
.
column_name_n datatype
);

Example : CREATE command

CREATE TABLE employee


(
empid INT,
ename CHAR,
age INT,
city CHAR(25),
phone_no VARCHAR(20)
);
. DROP COMMAND

• DROP command allows to remove entire database objects from the


database.
• It removes entire data structure from the database.
• It deletes a table, index or view.

Syntax:
DROP TABLE <table_name>;
OR
DROP DATABASE <database_name>;

Example : DROP Command

DROP TABLE employee;


OR
DROP DATABASE employees;

• If you want to remove individual records, then use DELETE command of


the DML statement
3. ALTER COMMAND

• An ALTER command allows to alter or modify the structure of the


database.
• It modifies an existing database object.
• Using this command, you can add additional column, drop existing
column and even change the data type of columns.
Syntax:
ALTER TABLE <table_name>
ADD <column_name datatype>;

OR

ALTER TABLE <table_name>


CHANGE <old_column_name> <new_column_name>;

OR

ALTER TABLE <table_name>


DROP COLUMN <column_name>;

Example : ALTER Command

ALTER TABLE employee


ADD (address varchar2(50));

OR

ALTER TABLE employee


CHANGE (phone_no) (contact_no);

OR

ALTER TABLE employee


DROP COLUMN age;

To view the changed structure of table, use 'DESCRIBE' command.


For example:
DESCRIBE TABLE employee;
4. RENAME COMMAND

• RENAME command is used to rename an object.


• It renames a database table.
Syntax:
RENAME TABLE <old_name> TO <new_name>;

Example:
RENAME TABLE emp TO employee;
5. TRUNCATE COMMAND

• TRUNCATE command is used to delete all the rows from the table
permanently.
• It removes all the records from a table, including all spaces allocated for
the records.
• This command is same as DELETE command, but TRUNCATE command
does not generate any rollback data.
Syntax:
TRUNCATE TABLE <table_name>;

Example:
TRUNCATE TABLE employee;

You might also like