You are on page 1of 4

DDL Commands:

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

1.Create
Table name is Student
Column name Data type Size
Reg_no varchar2 10
Name Char 30
DOB Date
Address varchar2 50

Example:

CREATE TABLE Student


(Reg_no varchar2(10),
Name char(30),
DOB date,
Address varchar2(50));

After the table created use SQL> desc Student;

2. The ALTER Table Command

By The use of ALTER TABLE Command we can modify our exiting table.

Adding New Columns

Syntax:
ALTER TABLE <table_name>
ADD (<NewColumnName> <Data_Type>(<size>),......n)

Example:
ALTER TABLE Student ADD (Age number(2), Marks number(3));

The Student table is already exist and then we added two more
columns Age and Marks respectively, by the use of above command.

3. The DROP Command


Syntax:
DROP TABLE <table_name>

Example:
DROP TABLE Student;
It will destroy the table and all data which will be recorded in it.

4. The TRUNCATE Command

Syntax:
TRUNCATE TABLE <Table_name>

Example:
TRUNCATE TABLE Student;

5. The RENAME Command

Syntax:
RENAME <OldTableName> TO <NewTableName>

Example:
RENAME <Student> TO <Stu>

The old name table was Student now new name is the Stu.

DML Commands:

1. SELECT
2. INSERT
3.UPDATE
4.DELETE

2. INSERT

More than one are there to Insert data into a table

eg: SQL> insert into student values(123,'Rajesh','12-Mar-88','First Cross Street',23);


eg : SQL> insert into student values(124,'Vishnu','12-April-88','Second Cross Street',23);

Note : Character expression placed within the insert into statement must be enclosed in single quotes (').

Note: After inserting the values SQL> Select * from student;


3. UPDATE Operation:

The UPDATE command is used to change or modify data values in a table and UPDATE
command can Update all the rows from the table or a set of rows from the table.

eg : UPDATE Student SET course='MCA';

4. DELETE Operation:

The DELETE command can remove all the rows from the table or a set of rows from the table.

eg: DELETE FROM student; It will DELETE all the rows from student table.

eg: DELETE FROM student WHERE reg_no='A101'; If condition will be satisfied then it will delete
a row from the table Register number A101 will be deleted from the table

If you want to delete table column then use ALTER TABLE command.
eg : ALTER TABLE student DROP COLUMN dob; The DOB column will be
deleted from the student table.