Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

UNIVERSITY SCHOOL OF INFORMATION AND

COMMUNICATION TECHNOLOGY
GURU GOBIND SINGH INDRAPRASTHA
UNIVERSITY, NEW DELHI-110078
(2020-2024)

PRACTICAL FILE
OF
DATABASE MANAGEMENT SYSTEMS
IT - 259

Submitted in partial fulfilment of the requirements


for the award of the degree of

BACHELOR OF TECHNOLOGY
IN
INFORMATION TECHNOLOGY

Submitted to: - NAME: AKSHAT KUMAR


Prof. SK Malik
IT-259 ENROLLMENT NO: 00716401520
B.Tech IT 3rd SEM
INDEX

S. Name of the Remarks


No Practical
1. ER DIAGRAM FOR LIBRARY
MANAGEMENT SYSTEM

2. ER DIAGRAM FOR BANK


MANAGEMENT SYSTEM

3. BASIC SQL QUERIES

4. SQL PRACTICAL QUESTION 1

5. SQL PRACTICAL QUESTION 2

6. SQL PRACTICAL QUESTION 3


LAB-1
ER DIAGRAM FOR LIBRARY MANAGEMENT SYSTEM
LAB-2
ER DIAGRAM FOR BANK MANAGEMENT SYSTEM
LAB-3
BASIC SQL QUERIES

1. DATA DEFINATION LANGUAGE (DDL)

DDL or Data Definition Language actually consists of the SQL


commands that can be used to define the database schema. DDL
changes the structure of the table like creating a table, deleting a
table, altering a table, etc.

(i) CREATE- It is used to create a new table in the database.


Syntax:
CREATE TABLE table_name (column_name
datatypes[,....]);
Example:
CREATE TABLE student (
Name varchar(20),
studentID int,
Address varchar(20));

(ii) ALTER: It is used to alter the structure of the database. This


change could be either to modify the characteristics of an existing
attribute or probably to add a new attribute or to rename a column.
Syntax:
ALTER TABLE table_name ADD column_name datatype;

ALTER TABLE table_name MODIFY(column_definitions....);

(iii) DROP: It is used to delete both the structure and record stored
in the table.

Syntax:
DROP TABLE table_name;

(iv) TRUNCATE: It is used to delete all the rows from the table and
free the space containing the table

Syntax:
TRUNCATE TABLE table_name;

2. DATA MANIPULATION LANGUAGE (DML)


The SQL commands that deal with the manipulation of data present
in the database belong to DML or Data Manipulation Language and
this includes most of the SQL statements. Such queries are insert,
delete, update.
(i) INSERT: It is used to insert data into the row of a table.

Syntax:
INSERT INTO TABLE_NAME (col1, col2, col3,.... col N)
VALUES (value1, value2, value3, .... valueN);

INSERT INTO TABLE_NAME VALUES (value1, value2,


value3, .... valueN);

(ii) UPDATE: This command is used to update or modify the value


of a column in the table.
Syntax:
UPDATE table_name SET [column_name1=
value1,...column_nameN = valueN] [WHERE CONDITION];

(iii) DELETE: It is used to remove one or more row from a table.


Syntax:
DELETE FROM table_name [WHERE condition];

3. TRANSACTION CONTROL LANGUAGE(TCL)


Transaction control language commands are used to manage
transaction in the database. These are used to manage the changes
made by DML statements. Such as commit, rollback, savepoint.
(i) COMMIT: It is used to save all the transactions to the database.
Syntax:
COMMIT;

(ii) ROLLBACK: It is used to restores the database to origin state


since the last commit.
Syntax:
ROLLBACK;

(iii) SAVEPOINT: Identify a point in a transaction to which you can


roll back later.
Syntax:
SAVEPOINT savepoint_name;

4. DATA CONTROL LANGUAGE(DCL)


DCL commands are used to grant and take back authority from any
database user. It is very important for security point of view. Such
queries are grant and revoke.

(i) GRANT: It is used to give user access privileges to a database.


Syntax:
GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER,
ANOTHER_USER;
(ii) REVOKE: It withdraws access privileges given with the grant
command.
Syntax:
REVOKE SELECT, UPDATE ON MY_TABLE FROM USER1,
USER2;

5. DATA QUERY LANGUAGE(DQL)


DQL is used to fetch the data from the database. Such as select
command.

SELECT: This is the same as the projection operation of relational


algebra. It is used to select the attribute based on the condition
described by WHERE clause.

Syntax:
SELECT expressions
FROM TABLES
WHERE conditions;

select * from Table; --this is use for fetch the whole data from table.
LAB-4

Perform the following:


1. Creating a database
2. Viewing all databases.
3. Creating Tables (with and without constraints).
4. Viewing all the tables in a database.
5. Inserting/Updating/Deleting Record in a Table.
6. Altering a table.
7. Saving(commit) and Undoing(rollback)
8. Dropping and Truncating Tables.

Creating and viewing a database


Creating and viewing all the tables

Inserting/Updating/Deleting Record in a Table.


Altering a table (Adding a column and renaming a column)
Commit and rollback commands
Drop and truncate
LAB-5
Create a table EMPLOYEE (EmpNo, Name, Salary, Designation,
Department) and write the following SQL queries:-

1. Find the name of highest paid employee.


2. Find name, designation and salary of employees of a
department.
3. Find the names of employees in ascending order.
4. Find the name of second highest paid employee.
5. Find the name of employees whose salary is between 50000 to
100000.
6. Find the name of employees whose name starting from A.
1.

2.
3.

4.

5.
6.
LAB-6
Consider Insurance database given below and answer the following
queries in SQL. Consider the insurance database given below. The
primary keys are made bold and the data types are specified.

PERSON (driver_id:string , name:string , address:string )


CAR (regno:string , model:string , year:int )
ACCIDENT (report_number:int , accd_date:date , location:string )
OWNS (driver_id:string , regno:string )
PARTICIPATED (driver_id:string , regno:string , report_number:int ,
damage_amount:int)

1. Create the above tables by properly specifying the primary keys


and foreign keys.
2. Enter at least five tuples for each relation.
3. Demonstrate how you Add a new accident to the database.
4. Find the total number of people who owned cars that were
involved in accidents in the year 2008.
5. Find the number of accidents in which cars belonging to a specific
model were involved.
Creating the tables

Showing all the tables


Add new accident in database
Total accidents in 2008

Total accidents of I20 car

You might also like