You are on page 1of 3

Experiment No – 2 & 3

AIM – To study DDL and DML commands


THEORY
DDL Commands
Data Definition Language (DDL) is a standard for commands that define the different
structures in a database. DDL statements create, modify, and remove database objects such
as tables, indexes, and users. Common DDL statements are CREATE, ALTER, and DROP.
CREATE – used to create a table with a name by giving specifications like column name, data
types and size.
ALTER – used to edit the existing table by adding, dropping and modifying(only data types)
columns.
RENAME – used to rename the table.
TRUNCATE – used to delete the contents of the table. It deletes all the rows.
DROP – used to delete the schema.

DML Commands
DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify,
delete, insert and update data in database. Examples: SELECT, UPDATE, INSERT statements.
DDL is abbreviation of Data Definition Language. It is used to create and modify the
structure of database objects in database.
SELECT – used to view the contents of the table.
INSERT – used to insert content to the table.
DELETE – used to delete rows.
UPDATE – used to update existing values of the column.
STEPS
1. CREATE TABLE stu (sno number(1), name char(10), gender char(5), cgpa varchar(4),
out char(4));

2. A. INSERT INTO stu (sno,name,gender,cgpa,out) values (‘1’, ‘abc’, ‘M’, ‘10’, ‘PASS’);
B. INSERT INTO stu (sno,name,gender,cgpa,out) values (‘2’, ‘def’, ‘F’, ‘9’, ‘PASS’);
C. INSERT INTO stu (sno,name,gender,cgpa,out) values (‘3’, ‘mno’, ‘M’, ‘9.4’, ‘PASS’);
D. INSERT INTO stu (sno,name,gender,cgpa,out) values (‘4’, ‘pqr’, ‘F’, ‘3’, ‘FAIL’);
E. INSERT INTO stu (sno,name,gender,cgpa,out) values (‘5’, ‘xyz’, ‘M’, ‘10’, ‘PASS’);

3. SELECT * FROM stu;

SNO NAME GENDE CGPA OUT


------ -------- ------ ------ -----
1 abc M 10 PASS
2 def F 9 PASS
3 mno M 9.4 PASS
4 pqr F 3 FAIL
5 xyz M 10 PASS

4. ALTER TABLE stu add promoted char(10);

SNO NAME GENDE CGPA OUT PROMOTED


------ -------- ------ ------ ----- ----------
1 abc M 10 PASS
2 def F 9 PASS
3 mno M 9.4 PASS
4 pqr F 3 FAIL
5 xyz M 10 PASS

5. ALTER TABLE stu DROP COLUMN out;

SNO NAME GENDE CGPA PROMOTED


------ -------- ------ ------ ----------
1 abc M 10 PASS
2 def F 9 PASS
3 mno M 9.4 PASS
4 pqr F 3 FAIL
5 xyz M 10 PASS
6. ALTER TABLE stu MODIFY cgpa char(4);

7. UPDATE stu SET cgpa=’A’ WHERE sno=5;

SNO NAME GENDE CGPA PROMOTED


------ -------- ------ ------ ----------
1 abc M 10 PASS
2 def F 9 PASS
3 mno M 9.4 PASS
4 pqr F 3 FAIL
5 xyz M A PASS

8. DELETE FROM stu WHERE sno=4;

SNO NAME GENDE CGPA PROMOTED


------ -------- ------ ------ ----------
1 abc M 10 PASS
2 def F 9 PASS
3 mno M 9.4 PASS
5 xyz M A PASS

9. RENAME stu TO student;

10. TRUNCATE TABLE student;


Table renamed.
SQL>TRUNCATE TABLE student;

Table truncated.
SQL>SELECT * FROM student;
no rows selected

11. DROP TABLE student;


SQL>DROP TABLE student;

Table dropped.

You might also like