0% found this document useful (0 votes)
26 views3 pages

Chapter DDL

The document discusses four basic SQL data definition language (DDL) commands: CREATE is used to create databases and tables, ALTER modifies existing databases and tables by adding, deleting, or changing columns, DROP removes databases, tables, or columns, and TRUNCATE empties the contents of a table but retains the structure.

Uploaded by

Deepness Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views3 pages

Chapter DDL

The document discusses four basic SQL data definition language (DDL) commands: CREATE is used to create databases and tables, ALTER modifies existing databases and tables by adding, deleting, or changing columns, DROP removes databases, tables, or columns, and TRUNCATE empties the contents of a table but retains the structure.

Uploaded by

Deepness Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Basic Data Definition Language (DDL) 1. 2. 3. 4.

Create Alter Drop Truncate

1. CREATE i. SQL CREATE DATABASE Syntax: CREATE DATABASE database_name; Example: CREATE DATABASE my_db; ii. SQL CREATE TABLE Syntax: CREATE TABLE table_name ( column_name1 data_type, column_name2 data_type, column_name3 data_type, ) Example: CREATE TABLE Persons ( P_Id int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255) ); 2. ALTER i. Adding column

ALTER TABLE table_name ADD column_name datatype; Example: ALTER TABLE Persons ADD DateOfBirth date;

FNAME VARCHAR2(25) = 20 ----- ii. Deleting column ALTER TABLE table_name DROP COLUMN column_name;

Example: ALTER TABLE Persons DROP COLUMN DateOfBirth; iii. Change Data Type ALTER TABLE table_name MODIFY column_name new_data_type; Example: ALTER TABLE Persons MODIFY Firstname varchar(50); iv. Rename a column ALTER TABLE table_name RENAME COLUMN old_column_name to new_column_name; Example: ALTER TABLE Persons RENAME COLUMN firstname to FIRST_NAME;

3. DROP i. The DROP TABLE Statement: DROP Table table_name; ii. The DROP DATABASE Statement: DROP DATABASE database_name;

iii. The DROP COLUMN statement: ALTER TABLE table_name DROP COLUMN column_name; 4. TRUNCATE TRUNCATE Syntax: TRUNCATE TABLE table_name

You might also like