0% found this document useful (0 votes)
10 views18 pages

Assgnmnt 3

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

Assgnmnt 3

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

Name: Sonu Garg

PRN: 22070122215
Batch:- 2022-26
Sem:- IV
Division: CS (C2)

1
DBMS Lab Assignment -3

Introduction to DDL and DML commands and its execution.

Data Definition Language defines the schema for the database by specifying entities and the
relationship among them. In addition to this, DDL even defines certain security constraints.
The execution of DDL statements results in new tables which are stored in “system catalog”
also called data dictionary or data directory.

Data Manipulation Language is a language that provides a set of operations to support the
basic data manipulation operations on the data held in the databases. It allows users to insert,
update, delete and retrieve data from the database. Data manipulations are applied at internal,
conceptual, and external levels of schemas. However, the level of complexity at each schema
level varies from one another.

Data Control Language statements control access to data and the database using statements
such as GRANT and REVOKE. A privilege can either be granted to a User with the help of
GRANT statement. The privileges assigned can be SELECT, ALTER, DELETE, EXECUTE,
INSERT, INDEX etc. In addition to granting of privileges, you can also revoke (taken back) it
by using REVOKE command.

2
SECTION – 1:

Q1: Explain DDL commands and their syntax.


ANS: The first DDL command is CREATE. CREATE is a DDL command used to create databases,
tables, triggers, and other database objects.
CREATE command is used to create tables. To create a table, the following syntax is used:
CREATE TABLE table_name
(
column_Name1 data_type (size of the column ) ,
column_Name2 data_type ( size of the column) ,
column_Name3 data_type ( size of the column) ,
...

3
column_NameN data_type ( size of the column )
);

Example

CREATE TABLE Student


(
Roll_No. Int ,
First_Name Varchar (20) ,
Last_Name Varchar (20) ,
Age Int ,
Marks Int ,
);

Q2: Create tables for the following relational model of library management. Apply
constraints on the columns and alter the structure according to your requirements.

ANS:

1. SIULIBRARY (Slid,lname,location,noofbranches)

2. Ilibrary(Lid, lname, city, area, slid)

3. BOOKS(Bid, Bname, Price , Lid)

4
4. Noofcopies(bnid,bid,blid)

5. AUTHOR(Aid, Aname,email,phoneno)

6. Writes(Bid, Aid, pid)

5
7. PUBLISHER(Pid, Pname)

8. SELLER(Sid, slname, city)

9. DEPARTMENT (Deptid,deptname, Iname,lid)

10. STUDENT(Stuid, Sname, email,memid deptid)

6
11. STAFF(Stid, stname, email, deptid,memid)

12. PURCHASE(prid , lid, sid, pid, bid, quantity ,date, totalcost)

13. ISSUE(lssueid, memid, bid, lid, issuedate, returndate)

14. SELLS (sid, bid,pid)

7
15. Employee(eid,empname,email,salary,lid)

16. A_specialization(spec_id,spec_name,Aid)

17. Member(memid,lid)

Conclusion:
In this experiment, we learnt how to install MYSQL, what is DDL and its commands, and how to
create tables and display tables in MYSQL.

8
SECTION – 2:
Introduction to DML and its commands

Q1: Explain DML commands and their syntax.


ANS: There are 4 basic commands in DML. They are:
 DELETE: Delete is used to delete rows and columns in the table. Records in the
table can be deleted in one go or one by one.
Syntax:
DELETE is DELETE FROM table_name.
 INSERT: Insert is used to insert new records into database tables. Data can be
inserted in all columns or in specific columns.
Syntax:
INSERT INTO TABLE_NAME ( column_Name1 , column_Name2 , column_Name3
, .... column_NameN ) VALUES (value_1, value_2, value_3, ..... value_N ) ;
 SELECT: Select is used to retrieve data from a database. It can be structured to
retrieve data in a way that doesn't alter the data in the database.
Syntax:
SELECT column_Name_1, column_Name_2, ...... , column_Name_N FROM
Name_of_table;

 UPDATE: Update is used to update existing records in a database. It sets specified


values in a tuple and changes the data inside the table.
Syntax:
UPDATE Employees NET Salary

Q2: Insert 5 tuples in each of their created tables.


ANS:

9
1. SIULIBRARY (Slid,lname,location,noofbranches)

2. Ilibrary(Lid, lname, city, area, slid)

3. BOOKS(Bid, Bname, Price , Lid)

10
4. Noofcopies(bnid,bid,blid)

11
5. AUTHOR(Aid, Aname,email,phoneno)

6. Writes(Bid, Aid, pid)

7. PUBLISHER(Pid, Pname)

12
8. SELLER(Sid, slname, city)

9. DEPARTMENT (Deptid,deptname, Iname,lid)

10. STUDENT(Stuid, Sname, email,memid deptid)

13
11. STAFF(Stid, stname, email, deptid,memid)

12. PURCHASE(prid , lid, sid, pid, bid, quantity ,date, totalcost)

13. ISSUE(lssueid, memid, bid, lid, issuedate, returndate)

14
14. SELLS (sid, bid,pid)

15. Employee(eid,empname,email,salary,lid)

16. A_specialization(spec_id,spec_name,Aid)

17. Member(memid,lid)

15
Q3: Execute following queries on the library database.
ANS:
1. Which institute libraries are located in Pune city?

2. To which institute CS department belongs to?

3. Find all the books whose price is between 800 to 12000?

16
4. Find out such employees whose salaries are not greater than 50,000/-

5. Find out such sellers who's name end with "ta"

6. Find out such institute libraries where their area information is missing.

7. Find out such staff members who's name doesn't starts with "A"

8. Find out such SIU libraries which have institute libraries located in
Bangalore.

17
9. Which students belong to civil department?

10. Find out books which are written by "shruti" and published by Macgraw
hill.

Conclusion:
In this experiment, we learnt how to use DML commands in SQL and how to
insert and select table values in SQL.

18

You might also like