You are on page 1of 9

DDL – Data Definition Language

A data definition language (DDL) is a computer language used to


create and modify the structure of database objects in a database.
These database objects include views, schemas, tables, indexes, etc.

This term is also known as data description language in some


contexts, as it describes the fields and records in a database table.
The DDL used in the SQL queries are
• Create
• Alter (Rename, Add, Modify, Drop)
• Rename
• Drop
• Truncate
Syntax for creating table:
CREATE TABLE table_name
(
Columnname datatype n()
) ;
Types of data type :
• Char()
• Int()
• Long
• Varchar()
• Varchar2()
• Date
• Float()
• Raw()
• Long raw
Each Column name should have its appropriate data type according to
the value to be entered.
Query: Create a table for a batch of employees

Create table tab_emp21


(
Emp_id varchar(5),
Emp_name Char(10),
Emp_cont number(10)
) ;

Query result:

Alter:
ALTER TABLE statement is used to add, delete, rename, drop and
modify the column in the table.
Syntax for adding a column:
AFTER TABLE table_name
Add column_name datatype ();
Query:
Add a new column Emp_sal in the existing table.

ALTER TABLE tab_emp21


Add Emp_sal number(10);

Result:

Syntax for Modifying table:


To modify the datatype.
ALTER TABLE tablename
Modify column_name newdatatype();

Query:
Modify thw Emp_sal from number() to varchar2()
ALTER TABLE tab_emp21
Modify Emp_id varchar2(10);
Result:

Rename a column name:


ALTER TABLE tablename
RENAME COLUMN old name TO new name

Query:
Rename column Emp_cont to Emp_ph
ALTER TABLE tab_ emp21
RENAME COLUMN Emp_cont TO Emp_ph
Result:

Dropping a column:

ALTER TABLE table_name


DROP COLUMN column name;
Query:
Drop Emp_mail
ALTER TABLE tab_batch DROP
COLUMN Emp_mail;
Result:

Renaming the table:


Syntax:
RENAME old table_name to new table_name;

Query: Change the old table name RENAME


tab_emp21 TO tb_emp;
Result:

Truncate: Clears all the data in the database table Syntax:


TRUNCATE TABLE table_name;

Drop: Deletes the entire table itself Syntax:


DROP TABLE table_name;

DML- DATA MANIPULATING LANGUAGE


This is used to insert, update, delete and merge data in the database
table.
Insert value in table Method
1:
Syntax:
INSERT INTO table_name(column name1, column name2, column
name n)
VALUES (v1, v2, vn);
Query:
To insert values for the tb_emp.
INSERT INTO tb_batch(Emp_id,Emp_name,Emp_ph,Emp_sal)
VALUES (‘OM1001’, ‘Arun’, ‘94879’, ‘50,000’);
Result:

Method 2:
Syntax:
INSERT INTO table_name Values (v1,v2,vn);

Update:
Used to enter new value

Syntax:
UPDATE table_name
SET column name = New value
WHERE condition;
QUERY:
INSERT INTO tb_emp (Emp_id,Emp_name,Emp_sal)
VALUES ('102','Neil','10000');

UPDATE tb_emp
Emp_ph='989898989
SET
8'
WHERE Emp_id='102';

SELECT *
FROM tb_emp;
Result:
Delete:
To delete particular data.
Syntax:
DELETE FROM table_name;
WHERE condition;

Query:
DELETE FROM tb_emp WHERE
emp_name='Adam';
Result:

You might also like