Thanks to visit codestin.com
Credit goes to www.scribd.com

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

DDL Commands

The document outlines Data Definition Language (DDL) commands used for defining and modifying database schemas, including commands such as CREATE, ALTER, DROP, TRUNCATE, and RENAME. It provides syntax examples for creating tables, adding attributes, deleting relations, and modifying existing structures. Additionally, it includes sample data manipulation operations and their outputs.
Copyright
© © All Rights Reserved
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)
8 views4 pages

DDL Commands

The document outlines Data Definition Language (DDL) commands used for defining and modifying database schemas, including commands such as CREATE, ALTER, DROP, TRUNCATE, and RENAME. It provides syntax examples for creating tables, adding attributes, deleting relations, and modifying existing structures. Additionally, it includes sample data manipulation operations and their outputs.
Copyright
© © All Rights Reserved
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/ 4

DDL COMMANDS

The DDL provides commands for defining relation schemas, deleting relations and
modifying relation schemas.

DDL is used to:


 Create an object
 Alter the structure of an object
 To drop the object created.

The commands used are:


1. Create
2. Alter
3. Drop
4. Truncate
5. Rename

1. CREATE COMMAND

This command is used to create a table

Syntax:

Create table table name (column_name1 data_ type, column_name2 data_ type …)

2.ALTER COMMAND

This command is to add attributes to an existing relation

Syntax:

Alter table r add A D;

Where r -name of the existing relation,


A - Name of the attribute to be added
D-type of the added attribute

3. DROP COMMAND

Drop command deletes all information about the dropped relation from the database

Syntax:

DROP TABLE <Table name>;

4.TRUNCATE COMMAND
Truncate command removes all the records from the table
Syntax:
TRUNCATE TABLE <Table name>

5. RENAME COMMAND
Rename command is used to rename the objects
RENAME <OldTableName> To < NewTableName>

CREATE TABLE:
CREATE TABLE EMPLOYEES (EMPNO NUMBER (5), NAME VARCHAR2(15),
DESIGNATION VARCHAR2(10), SALARY NUMBER (20));

INSERT VALUES:

1. INSERT INTO EMPLOYEES VALUES(111,'ANBU','PROFESSOR',10000);


2. INSERT INTO EMPLOYEES VALUES(112,'KUMAR','OA',7000);
3. INSERT INTO EMPLOYEES VALUES(113,'SAKTHI','VAO',12000);

SELECT*FROM EMPLOYEES;

OUTPUT:

NAME DESIGNATION SALARY


EMPNO
111 ANBU PROFESSOR 10000

112 KUMAR OA 7000

113 SAKTHI VAO 12000

MODIFY TABLE:
ALTER TABLE EMPLOYEES MODIFY DESIGNATION VARCHAR2(20);

DESC EMPLOYEES;

OUTPUT:
Precisi Commen
Tabl Column Data Type Length on Scale Primary Key Nullable Default t
e
EMP
LOY EMPNO Number - 5 0 - - -
EES

NAME Varchar2 15 - - - - -

DESIGNATION Varchar2 20 - - - - -

SALARY Number - 20 0 - - -

1-4

ADD COLUMN:
ALTER TABLE EMPLOYEES ADD QUALIFICATION VARCHAR2(20);

NAME DESIGNATION SALARY QUALIFICATION


EMPNO
111 ANBU PROFESSOR 10000 -

112 KUMAR OA 7000 -

113 SAKTHI VAO 12000 -

RENAME:
RENAME EMPLOYEES TO STAFFS;

TABLE ObjectSTAFFS
Object Type
Com
Table Column Data Type Length Precision Scale Primary Key Nullable Default ment

STAFFS EMPNO Number - 5 0 - - -

NAME Varchar2 15 - - - - -

DESIGNATION Varchar2 20 - - - - -

SALARY Number - 20 0 - - -

1-4

DROP TABLE:
ALTER TABLE STAFFS DROP(QUALIFICATION);

SELECT*FROM STAFFS;

OUTPUT:

NAME DESIGNATION SALARY


EMPNO
111 ANBU PROFESSOR 10000

112 KUMAR OA 7000

113 SAKTHI VAO 12000

TRUNCATE:
TRUNCATE TABLE STAFFS;

SELECT*FROM STAFFS;

OUTPUT:

You might also like