0% found this document useful (0 votes)
3 views

Task 4

good

Uploaded by

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

Task 4

good

Uploaded by

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

Air University - Aerospace and Aviation Campus,

Kamra Department of Computer Science

Database Systems Lab (CS230)


Lab # 04
[CLO-5, Taxonomy Level-C]

Course: BSCYS-5 Semester: 5st (Fall 2024)

Due Date: 08/10/2024 Total Marks: 50


Instructions
1. Plagiarism, copy & past material will lead to the cancellation of your assignment.
2. Write your Name, Reg# on the first page (title page) of your submission.
3. [No late submission]

Implementation of Data Manipulation Language – Insert, Select, Update, Delete


Objective:

Students shall be able to do the following:

🞂 Learn commands that make changes in relational database and transaction management.
🞂 Gains the knowledge to perform transactions like updating, deleting, inserting and selecting
data from a database.
Software Tools:

🞂 MySQL Workbench (Oracle Enterprise Edition)


Theory:

DATA MANIPULATION LANGUAGE (DML): The Data Manipulation Language (DML)


is used to retrieve, insert and modify database information. These commands will be used by
all database users during the routine operation of the database. Let's take a brief look at the
basic DML commands:

1. INSERT 2. SELECT 3. UPDATE 4. DELETE

Insert Command: this is used to add one or more rows to a table. The values are separated by
commas and the data types char and date are enclosed in apostrophes. The values must be
entered in the same order as they are defined.
Select Commands: It is used to retrieve information from the table. It is generally referred to
as querying the table. We can either display all columns in a table or only specify column from
the table.
Update Command: It is used to alter the column values in a table. A single column may be
updated or more than one column could be updated.

Delete command: After inserting row in a table we can also delete them if required. The delete
command consists of a ‘from’ clause followed by an optional ‘where’ clause.

1.INSERT INTO: This is used to add records into a relation. These are three type
of INSERT INTO queries which are as
a)Inserting a single record
Syntax: INSERT INTO < relation/table name> (field_1,field_2……
field_n)VALUES (data_1,data_2,. data_n);
Example: SQL>INSERT INTO student(sno,sname,class,address)VALUES
(1,’Ravi’,’M.Tech’,’Palakol’);
b)Inserting a single record
Syntax: INSERT INTO < relation/table name>VALUES (data_1,data_2,.......data_n);
Example: SQL>INSERT INTO student VALUES (1,’Ravi’,’M.Tech’,’Palakol’);
c)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: SQL>INSERT INTO std SELECT sno,sname FROM
student WHERE name = ‘Ramu‘;
d)Inserting multiple records
Syntax: INSERT INTO relation_name field_1,field_2,......field_n) VALUES
(&data_1,&data_2,.. . .&data_n);
Example: SQL>INSERT INTO student (sno, sname, class,address)
VALUES (&sno,’&sname’,’&class’,’&address’);
Enter value for sno: 101
Enter value for name: Ravi
Enter value for class: M.Tech
Enter value for name: Palakol

2.UPDATE-SET-WHERE: This is used to update the content of a record in a relation.


Syntax: SQL>UPDATE relation name SET Field_name1=data,field_name2=data,
WHERE field_name=data;
Example: SQL>UPDATE student SET sname = ‘kumar’ WHERE sno=1;

3.DELETE-FROM: This is used to delete all the records of a relation but it will retain the
structure of that relation.
a)DELETE-FROM: This is used to delete all the records of relation.
Syntax: SQL>DELETE FROM relation_name;
Example: SQL>DELETE FROM std;
b)DELETE -FROM-WHERE: This is used to delete a selected record from a relation.
Syntax: SQL>DELETE FROM relation_name WHERE condition;
Example: SQL>DELETE FROM student WHERE sno = 2;

4.TRUNCATE: This command will remove the data permanently. But structure will not be
removed.
Difference between Truncate & Delete:-
by using truncate command data will be removed permanently & will not get back where as
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 whereas by using
truncate command there is no condition.
Truncate is a DDL command & delete is a DML command.

Syntax: TRUNCATE TABLE <Table name>


Example TRUNCATE TABLE student;

To retrieve data from one or more tables.

1.SELECT FROM: To display all fields for all records.


Syntax : SELECT * FROM relation_name;
Example : select * from dept;
DEPTNO DNAME LOC

10 ACCOUNTING NEW YORK


20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON

2.SELECT FROM: To display a set of fields for all records of relation.


Syntax: SELECT a set of fields FROM relation_name;
Example: select deptno, dname from dept;
DEPTNO DNAME

10 ACCOUNTING
20 RESEARCH
30 SALES

3.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 dept WHERE deptno<=20;
DEPTNO DNAME LOC

10 ACCOUNTING NEW YORK


20 RESEARCH DALLAS
LAB TASK:

Create a table EMPLOYEE with following schema:


(Emp_no, E_name, E_address, E_ph_no, Dept_no, Dept_name,Job_id , Salary)
Write SQL queries for following question:
1. Insert at least 5 rows in each table. (Data is shown in figure
bellow) CUSTOMERS
Custome FirstNa LastNa EmailAddress PhoneNu Stree City Sta ZipCo
rID me me mber t te de
1 John Doe [email protected] 123-456- 456 Los CA 90001
m 7890 Mapl Angel
e es
Aven
ue
2 Alice Smith alice.smith@example. 555-111- 789 Chicag IL 60601
com 2222 Oak o
St
3 Bob Johnso bob.johnson@exampl 555-333- 321 Houst TX 77001
n e.com 4444 Pine on
St
4 Charlie Brown charlie.brown@exam 555-555- 987 San CA 94101
ple.com 6666 Mapl Franci
e St sco
5 Diana Evans diana.evans@example 555-777- 654 Miami FL 33101
.com 8888 Spru
ce St

BOOKS
BookID Title Author Publisher Price StockQuantity
1 The Great Gatsby F. Scott Scribner 10.99 48
Fitzgerald
2 To Kill a Harper Lee J.B. Lippincott & 21.45 100
Mockingbird Co.
3 1984 George Orwell Secker & Warburg 15.99 150
4 Moby Dick Herman Melville Harper & Brothers 25.90 120
5 Pride and Prejudice Jane Austen T. Egerton 9.99 80

Orders
OrderID OrderDate CustomerID TotalAmount
1 2024-10-08 1 21.98
2 2024-10-09 3 35.67
Order_Details
OrderDetailID OrderID BookID Quantity Subtotal
1 1 1 2 21.98
2 2 2 1 11.20
2 2 4 1 24.47

2. Display all the information of CUSTOMERS and BOOKS tables.


3. Display the record of customers who lives in Houston.
4. Update the city of customer id 5, city with Los Angles with Miami.
5. Display the title, author, and price of all books whose price is greater than $20.
6. Delete the records of customer id 4.
7. Display the order details of order id 2.

You might also like