Professional Documents
Culture Documents
Assignment (DDL, DML AND DQL)
Assignment (DDL, DML AND DQL)
1. Data Definition Language (DDL): IS used to changes the structure of the table like creating a table, deleting a
table, altering a table, etc.
Here are some commands that come under DDL:
1. CREATE - is used to create a new table in a database.
SYNTAX- CREATE TABLE farmer (Fname char (10) primary key, Fage int, Fsubject char (10));
2. ALTER - Once a table is created, Alter includes To Modify, add column(s), drop column(s), and
change column definitions.
- It is also used to establish relationship between tables.
SYNTAX- To add column - ALTER TABLE FARMER add COLUMN address char (10);
SYNTAX- To drop column - ALTER TABLE FARMER DROP COLUMN address;
SYNTAX – to add R/P (foreign key) - ALTER TABLE FARMER ADD FOREIGN KEY (F_SUBJECT)
REFERENCES DEPARTMENT (D_Number);
3. DROP - It is used to delete/remove the created table.
Syntax - To delete table - DROP TABLE FARMER;
2. Data Manipulation Language (DML): are used to manage/modify the database by performing operations
such as inserting, updating, deleting, and navigating through data.
Some commands that come under DML:
1. INSERT- command helps to insert new records to a table.
Syntax 1- INSERT INTO COURSE VALUES (3, ‘Chemistry’, ‘Organic chemistry’,‘105’, ‘NS1421’);
Syntax 2- INSERT INTO DEPARTMENT (D_Number, D_Name, D_Location) VALUES (‘D101’, ‘Biology’, ‘NBR
First Floor’)
2. UPDATE- It simply Updates/MODIFY existing records in the table.
Syntax - UPDATE Teacher SET T_Salary = 15000 WHERE T_Salary<10000;
- UPDATE Teacher SET T_Salary = 20000 WHERE T_sex=’female’;
3. DELETE- command is used to delete a record or multiple records from the database.
- Delete command does not remove the table structure, rather it only deletes the data.
To delete 1 record - DELETE FROM Teacher WHERE T_IDNO =’Teach/2312/91’;
To delete all records - DELETE FROM teacher; or DELETE * FROM teacher;
3. Data Query Language/DQL – SELECT Command - is used to fetch/filter the data from the database and is used
for querying or selecting all or subsets of data from a database.
Syntax - SELECT S_Fname, S_MName, S_LName, S_sex
FROM STUDENT
WHERE s_sex = ‘male’;
Syntax - Asce and Descen order - SELECT T_First_Name, T_Middle_Name, T_Sex, T_Salary
FROM Teacher
ORDER BY T_Salary Desc/ASC
ACTIVITY 1
I. DDL
1. Insert the following records in the Student, Teacher and Grade tables.
- Teacher table (001, Abebe, M, 31, chemistry),(002, HANA, F,22,ICT) ,(003, Gebre, M, 45,
Geography).
- Grade Table(10/16, 001,NS1,80), (11/16,002,NS2,90),(12/16,003,NS3,100).
- Course table (1, ‘Chemistry’, ‘Organic chemistry’, ‘101’, ‘NS1’),(2, ICT, SQL, 102, NS2), (1,
PHYSICS, MOTION, 103, NS3).
2. UPDATE/change the teacher name Abebe to Danial in name column.
3. Change the Grade table mark 80 to 55 in mark column.
4. Delete Hana from Teacher table.
5. Delete all records from teacher table.
III. DQL
5. Select all students whose marks are above 80 from grade table. [Hint: marks>80]
6. Select all courses and order them by their names.