Hu21csen0101379 DBMS Lab Record

You might also like

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

GITAM

Deemed to be University
(Estd. u/s of UGC Act, 1950)
Hyderabad Campus

Laboratory Record Book

Name of the Student: K. SANTHANA GOPALA KRISHNAN


Pin No: HU21CSEN0101379
Department: Computer Science Engineering
Laboratory: DBMS LABORATORY Section: CSE (H) SET-3

i
GITAM
Deemed to be University
(Estd. u/s of UGC Act, 1950)
Hyderabad Campus

CERTIFICATE

Certified that this is the bonafide record of practical work done by


Mr./Ms. K. SANTHANA GOPALA KRISHNAN with Reg.
HU21CSEN0101379 of B. Tech Computer Science Engineering
branch in DATABASE MANAGEMENT SYSTEM Laboratory of
Department of during the academic year 2023-2024.

Faculty I/c.
Date: Head of the Department

ii
INDEX

S.No Topic Date Page No Marks Remarks


1 SQL Commands
25-07-2023 1-4

2 ER DIAGRAM 01-08-2023 5-13


3 SQL Queries Using Alter 08-08-2023 14-17
Command
4 Views SQL Queries
22-08-2023 18-21

5 View, save point, Commit 19-09-2023 22-26


&Rollback (WEEK-5)
6 Privileges (WEEK-6) 19-09-2023 27-29
7 Joins And Sets (WEEK-7) 20-09-2023 30-34
8 PL/SQL (WEEK – 8) 26-09-2023 35- 38
9 TRIGGERS AND CURSORS (WEEK-9) 26-09-2023 39 - 42

iii
DBMS LAB ASSIGNMENT -1
NAME: K. Santhana Gopala Krishnan ROLLNO: HU21CSEN0101379
write the SQL queries for the following
1.Create an employee table with (id, name, salary, dob, deptno) attributes. consider id as the primary
key
A.

2. Insert 5 rows of data into employee table


A.

3. Retrieve all the rows from the employee table


A.

4. Update the employee name for empid 111 to 'Blake'.


A

iv
5. Delete the employees having null values for salary;
A.

6. Retrieve the employees having name of 5 characters length


A.

7. Retrieve the employee names starting with S and ending with e


A.

v
8. Retrieve employee data from deptnos 10 and 20;
A.

9. Retrieve the employees whose salary is not null


A.

10. Delete the employees having deptno 20


A.

vi
vii
viii
9
10
12
13
15
DBMS LAB ASSIGNMENT – 3

NAME: K. Santhana Gopala Krishnan PIN NO: HU21CSEN0101379

1. Create a relation with name student with following fields


Sid, name, age, address, coursed, course fee with suitable domains, Sid-primary key
A.

2. alter the table structure to add the column dob


A.

3. alter the table structure to drop the column address


A.

17
4. alter the table structure to add not null constraint on dob, default constraint on course fee with
defaultvalue of 5000.
A.

5. alter the table structure to add user defined constraint on course fee to allow the values between 3000
and15000
A.

6. create the table course with the attributes course id, name, instructor name with suitable domains
andprimary key.
A.

18
7. alter the student table structure to add foreign key referencing to course table
A.

8. alter the table student structure to disable primary key


A.

19
9. alter the student table structure to modify the datatype of course fee to take real values.
A.

10. alter the table structure of course to rename the column instructor name to faculty name.
A.

20
DBMS LAB ASSIGNMENT – 4
NAME: K. Santhana Gopala Krishnan PIN NO: HU21CSEN0101379
Write SQL queries for the following

1. To retrieve all the information from the employee table in the descending order of employee names

A. Before

After descending order the table looks like:

21
2. to retrieve all the employees information in the ascending order of salaries A.

3. to retrieve the departmentwise sum of salaries A.

4. to display the maximum salary, minimum salary, average salary of all employees A.

5. to display the number of employees in each department A.

22
6. to display the departmentwide average salaries A.

7. to display the difference of average salary and his own earnings for each employee, give the alias name as
sal_diff

A.

23
24
DBMS LAB ASSIGNMENT – 5
NAME: K. Santhana Gopala Krishnan PIN NO: HU21CSEN0101379
Table Creation

1. create a view with name max_sal_view from employee table as department wise
maximum salaries
A.

2. create an updatable view salrange_view from employee table having salaries


between 10000 and 50000
A.

25
3. insert a row into salrange_view and check that row inserted in employee table or
not.
A.

4. create a view salrange_view1 from employee table having salaries between 10000
and 50000 with check option
A.

5. insert a row into salrange_view1 with salaries 40000 and 60000. what did you
observe.
A.

26
the second row will not be inserted because it violates the view's filter condition.

6. delete max_sal_view
A.

7. create a savepoint with name SPA


A.

8. insert four rows into employee table and commit the changes
A.

27
9. create a savepoint with name SPB
A.

10. delete two rows from employee table and dont commit
A.

11. rollback to SPB, what did you observe


A

28
After rollback deletion is undone.

12. write short notes on commit, rollback and save point


A. 1. COMMIT:
• Purpose: The COMMIT statement is used to permanently make changes during the current
relational database transaction.
• Function: When a COMMIT statement is executed, all changes made within the transaction are
saved to the database, making them permanent and visible to other users.
• Use Case: It's typically used when you want to ensure that the changes you've made are finalized
and durable. It's the point of no return in a transaction.
2. ROLLBACK:
• Purpose: The ROLLBACK statement is used to undo changes made during the current
transaction and return the database to its state before the transaction began.
• Function: When a ROLLBACK statement is executed, all changes made within the transaction
are discarded, effectively cancelling the transaction.
• Use Case: It's used when you want to revert any changes made during a transaction due to
errors or other issues. It's a way to maintain the integrity of the database.
3. SAVEPOINT:
• Purpose: The SAVEPOINT statement is used to set a point within a transaction to which you
can later roll back.
• Function: SAVEPOINT allows you to create named points within a transaction. You can then
use the ROLLBACK TO statement to roll back to a specific save point within the transaction,
rather than rolling back the entire transaction.
• Use Case: Savepoints are handy when you want to isolate errors or changes within a large
transaction. You can roll back to a save point to correct specific issues without affecting the entire
transaction.

29
DBMS LAB ASSIGNMENT – 6
NAME: K. Santhana Gopala Krishnan PIN NO: HU21CSEN0101379
1. create a user with your 'roll no' and use password as Gitam
A.

2. grant all privileges to 'roll no' and connect to 'roll no' with appropriate
password
A.

3. retrieve all tables that exists in 'roll no'


A.

None of the rows was selected.


4. create a table login with attributes id, password with appropriate
datatypes and constraints
A.

5. insert 5 rows into login


A.

30
6. display login data
A.

7. connect back to admin user and revoke select privilege on login table
from roll no
A.

31
8. now retrieve the data from login table. what did you observe?
A.

After revoking the select privilege on the login table from the 'roll no' user, if we
try to retrieve the data from the login table using the 'roll no' user, we will get
an error message saying that the user does not have the required privilege to
access the table.

32
DBMS LAB ASSIGNMENT – 7
NAME: K. Santhana Gopala Krishnan PINNO: HU21CSEN0101379
Demonstrate the following joins using SQL queries
Table of Employees

Table for Departments

1. Equi join:

2. Natural join

33
3. non-equal join

4. Left outer join


34
5. Right outer join

6. Full outer join

Demonstrate the following set operators using SQL queries


35
Table 1

Table 2

1. Union

2. Union All

36
3. Intersect

4. Minus / Except

37
DBMS LAB ASSIGNMENT – 8
Name : K. Santhana Gopala Krishnan Pinno: HU21CSEN0101379
1. To print the employee details from employee table for a specific employee no given at
run time using local variables.

OUTPUT:

2. To print the employee details from employee table for a specific employee no given at
run time using record type variable.

OUTPUT:

38
3. To display the employee details from employee table for a specific employee no given
at run time using row type record variable.

OUTPUT:

39
4. To display the employee details from employee table for a specific employee no given
at run time using procedures.

40
5. To display the employee salary from employee table for a specific employee no given
at run time using functions.

41
DBMS LAB ASSIGNMENT – 9
NAME: K. Santhana Gopala Krishnan PIN NO: HU21CSEN0101379
1. To display all the employee details from employee table using implicit cursors

OUTPUT:

2. To display all the employee details from employee table using explicit cursors

OUTPUT:

42
3. To display all the student details from student table using loops (any loop)

OUTPUT:

4. Write an update trigger to display the salary change for an employee salary updating.

43
OUTPUT:

5. Create a log table and log every change of employee table, timing, operation, user
name using triggers.

OUTPUT: Here I performed 3 operations of insertion, updating and deleting.


44
45

You might also like