0% found this document useful (0 votes)
3 views13 pages

Database Lab Session-3

Uploaded by

minyiluhseifu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views13 pages

Database Lab Session-3

Uploaded by

minyiluhseifu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

IMPLEMENTATION OF DML

COMMANDS OF SQL

INFOLINK UNIVERSITY COLLEGE, DEPARTMENT OF COMPUTER


SCIENCE
PREPARED BY MEKIA D.(MSc)
UPDATE

If you omit the WHERE clause, all records in the table will be
updated!
INSERT

• Inserting a single record: INSERT INTO table_name VALUES (value1, value2,


value3, ...);
• For Example: insert into student values(123,'abebe');
Syntax: INSERT INTO relation_name (field_1,field_2, ....field_n) VALUES
(value1,value2,.......valuen);
Example: INSERT INTO student (sno, sname, class,address)
VALUES(112,’abush’,2,’Hawassa’);

• Inserting all records from another relation:

Syntax: INSERT INTO relation_name_1 SELECT Field_1,field_2,field_n


FROM relation_name_2 WHERE field_x=data;
• Example: INSERT INTO std SELECT sno,sname FROM student

WHERE name = ‘Ramu’;


INSERT DATA ONLY IN SPECIFIED COLUMNS

• insert into student (sno,sname,name)


values(13,'sara','Abebe');
INSERT MULTIPLE ROWS

• insert into student


• values(15,'sara','babi',69),
(16,'Birku','babi',89),(17,'Hana','babi', 99);
DELETE

• DELETE FROM table_name WHERE condition;


E.g. delete from stud where snam=‘abebe’;
• If you omit the WHERE clause, all records in
the table will be deleted!
• E.g delete from stud ;
DIFFERENCE BETWEEN TRUNCATE & DELETE

• By using truncate command data will be removed permanently & will not get
back.
• by using delete command data will be removed temporally & get back by
using roll back command.
• By using delete command data will be removed based on the condition.
• where as by using truncate command there is no condition.
• Truncate is a DDL command & delete is a DML command.
TO RETRIEVE DATA FROM ONE OR MORE
TABLES.
• SELECT FROM: To display all fields for all records.
• Syntax : SELECT * FROM relation_name;
• Example : select * from student;
• SELECT FROM: To display a set of fields for all records of relation.
• Syntax: SELECT a set of fields FROM relation_name;
• Example: select sno, sname from student;
SELECT - FROM -WHERE:

• This query is used to display a selected set of fields for a selected set of
records of a relation.
• Syntax: SELECT a set of fields FROM relation_name WHERE condition;
• Example: select * FROM student WHERE grade <=20;
SQL SELECT DISTINCT STATEMENT

• Syntax: SELECT DISTINCT column1, column2, ...FROM table_name;


• Select all the different department from the “student" table:
• SELECT DISTINCT dept FROM student;
SELECT-AS-FROM

• E.g. SELECT fname AS sname from student;


• E.g. SELECT fname AS sname, dep AS studinfo from student;
EMPLOYEE TABLE
Emp_n E_nam city Dept_ Dept_name Salary
o e no _in_ $
1 John USA D1 ICT 5000
2 Smith Canad D2 Web Developer 6000
a
3 James Englan D3 Software Engineer 9000
d
4 Hana Ethiopi D1 ICT 5000
a
5 Sara Dubai D4 Database 7500
Administrator
LAB PRACTICE QUIZ(15 MINUTES)
• Create a table EMPLOYEE with following schema:
• (Emp_no, E_name, City, Dept_no, Dept_name, Salary)

Write SQL queries for following question:


1. Insert at least 5 rows in the table.
2. Display all the information of EMP table.
3. Display name of employee who works in department D1.
4. Update the city of Emp_no-5 with current city as Hawassa.
5. Display the details of Employee who works in department ICT.
6. Display the salary of Employee who has distinct salary.
7. Display the complete record of employees with salary less than or equal to 5000 $.
8. Delete the record of employee Hana.

You might also like