0% found this document useful (0 votes)
5 views

SQL 2 A

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

SQL 2 A

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 17

DDL Statements

DBMS InfyTq
DDL Statements

• DDL or Data Definition Language actually consists of the SQL


commands that can be used to define the database schema. It
simply deals with descriptions of the database schema and is
used to create and modify the structure of database objects in
the database.
Examples of DDL STATEMENTS

•CREATE – is used to create the database or its objects (like


table, index, function, views, store procedure and triggers).
•DROP – is used to delete objects from the database.
•ALTER-is used to alter the structure of the database.
•TRUNCATE–is used to remove all records from a table,
including all spaces allocated for the records are removed.
•COMMENT –is used to add comments to the data dictionary.
•RENAME –is used to rename an object existing in the database.
CREATE STATEMENT

• This DDL command is used to create any database with its


different objects such as tables, indexes, triggers, views, stored
procedures, built-in functions etc.
• The CREATE statement is written using the following syntax:

 CREATE TABLE TableName (Column1 Datatype1, Column2


Datatype2,…,ColumnNDatatypeN);
DATA TYPE Oracle

• SQL Character Data Types


• Numeric
• Date
EXAMPLE

• Create a Table with the following Schema


• Employee(EmpId, Name, Address, DOJ, Salary)
• Student(Name, Roll Number, Address, Branch)
DESCRIBE TABLE

• Describe table structure


• Syntax:
• DESCRIBE TABLE NAME;
COMMENT

• This Comment query is beneficial to add required comments to


the data dictionary
• Single Line Comments: The comment here begins with –.
• Multi-Line Comments: This comment begins with /* and lasts
with */.
RENAME Statement

• The Rename DDL command query allows renaming any database


objects in the server if needed for any admin works.
• RENAME table_name to new table_name
• ALTER TABLE TableName_A RENAME TO TableName_B;
ALTER STATEMENT

• Oracle ALTER statement is used when you want to change the name
of your table or any table field. It is also used to add or delete an
existing column in a table.
• The ALTER statement is always used with "ADD", "DROP" and
"MODIFY" commands according to the situation.
• The ALTER TABLE statement is also used to add and drop various
constraints on an existing table.
ADD a column in the table
Add multiple columns in the table
MODIFY column in the table
DROP column in table

• ALTER TABLE table_name DROP COLUMN column_name;


RENAME column in table
TRUNCATE statement

• The TRUNCATE statement in MySQL removes the complete data


without removing its structure. It is a part of DDL or data definition
language command. Generally, we use this command when we want
to delete an entire data from a table without removing the table
structure.
• Syntax:
• TRUNCATE TABLE table name;
Example
customer (Id, Name, Country, Year);
DROP Table

• DROP Table name;

You might also like