CH 2
CH 2
DDL Commands:
1 CREATE
2 DESC
3 ALTER
4 RENAME
5 TRUNCATE
6 DROP
1. CREATE command
It is used to create a new table in the database.
Syntax:
Create table table_name(col_name1 datatype(size),col_name2
datatype(size)……..);
Example:
Example:
1. desc student;
2. desc employee;
3. ALTER command
It is used to alter the structure of the database. This change could be either
to modify the characteristics of an existing attribute or probably to add a new
attribute.
Syntax :
ALTER TABLE table_name ADD (column_name datatype);
Example:
alter table student add(marks number(10,5);
alter table employee add(department varchar(20));
2. To modify existing column in the table:
we can change data type and size of column.
EXAMPLE
Example:
It is used to delete all the rows from the table and free the space
containing the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE EMPLOYEE;
Truncate table student;
6. DROP command
It is used to delete both the structure and record stored in the
table.
Syntax
DROP TABLE ;
Example
1. DROP TABLE EMPLOYEE;
2. Drop table student;
Assignment -1 on DDL Commands
DML commands are used to modify the database. It is responsible for all
form of changes in the database. The command of DML is not auto-committed that
means it can't permanently save all the changes in the database. They can be
rollback.
DML Commands:
1. INSERT
2. UPDATE
3. DELETE
1. INSERT command
The INSERT statement is a SQL query. It is used to insert data into the
row of a table.
Syntax:
INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES
(value 1, value2, value3, .... valueN);
Example :
Syntax:
For example:
Syntax:
DELETE FROM table_name [WHERE condition];
For example: