DBMS Part A 2023
DBMS Part A 2023
PROGRAM-1
1.COLLEGE DATABASE:
• STUDENT (USN,Sname,Address,Phone,Gender)
• SEMSEC(SSID,Sem,Sec)
• CLASS(USN,SSID)
• SUBJECT(Subcode,Title,Sem,Credits)
• IA MARKS(USN,Subcode,SSID,Test1,Test2,Test3,Final IA)
2.COMPANY DATABASE:
• EMPLOYEE(SSN,Name,Address,Sex,Salary,SuperSSN,Dno)
• DEPARTMENT(DNo,DNAME,MGRSSN,MgrStartDate)
• DLOCATION(DNo,DLoc)
• PROJECT(PNo,PName,PLocation,DNo)
• WORKS_ON(SSN,PNo,Hours)
PROGRAM-2
Q:Write queries for the following:
Creating user ,Creating a user , Viewing all Tables in a user, Creating Tables (With
and Without Constraints), Inserting/Updating/Deleting Records in a Table, Saving
(Commit) and Undoing (rollback)
Product(PID,Number,Name,Text,Price)
Purchase(PO,Number,PID,QTY,)
Steps :-
User Created.
Statement processed.
Step2:- Create table Product and Purchase with and without constriant
TABLE CREATED.
CREATE TABLE PURCHASE(PO NUMBER(10) PRIMARY KEY,PRODUCT_ID
NUMBER(10) REFERENCES PRODUCT(PID) ,QTY NUMBER(5));
TABLE CREATED.
DESC PRODUCT;
PRICE NUMBER(8,2)
DESC PURCHASE;
PRODUCT_ID NUMBER(10)
QTY NUMBER(5)
TABLE_NAME STATUS
PRODUCT VALID
PURCHASE VALID
1 ROW INSERTED
1 ROW INSERTED
Insert into Product(PID,NAME,PRICE)values(30,’MONITOR’,15000);
1 ROW INSERTED
1 ROW INSERTED
1 ROW INSERTED
1 ROW INSERTED
1 ROW INSERTED
1 ROW INSERTED
1 ROW INSERTED
1 ROW INSERTED
Step 5:- Display all the tuples in the Product and Purchase table
10 PRINTER 20000
20 KEYBOAR 20000
D
30 MONITOR 15000
40 TABLE 25000
50 SCANNER 14000
PO PRODUCT_ID QTY
101 10 25
102 40 20
107 30 40
104 40 50
105 40 10
1 ROW UPDATED.
10 PRINTER 20000
20 KEYBOAR 20000
D
30 MONITOR 15000
40 CAMERA 25000
50 SCANNER 14000
1 ROW DELETED
10 PRINTER 20000
20 KEYBOARD 20000
30 MONITOR 15000
40 CAMERA 25000
COMMIT;
Statement processed.
1 row inserted
1 row inserted
10 PRINTER 20000
20 KEYBOARD 20000
30 MONITOR 15000
40 CAMERA 25000
50 MOBILE 35000
60 LAPTOP 70000
ROLLBACK;
Statement processed.
Select * from product;
10 PRINTER 20000
20 KEYBOARD 20000
30 MONITOR 15000
40 CAMERA 25000
Solution: Consider the library database with the following data and execute the queries
Lib(BID:Number,Title:Text,Publication:Text;Year_Of_Publication:Text)
Steps :-
3.Add a new column Price with Not Null constraint to the existing table library
4.All the constraints and the views that references the coloumn are dropped
automatically along with the column.
6.Change the data type of the column Year_Of _Publication as Text with size 15.
9.Drop table
Table created.
DESC LIB;
AUTHOR VARCHAR2(20)
PUBLICATION VARCAHR2(20)
YEAR_OF_PUBLICATION NUMBER(4)
Table altered.
DESC LIBRARY;
AUTHOR VARCAHR2(20)
PUBLICATION VARCHAR2(20)
YEAR_OF_PUBLICATION NUMBER(4)
Step 3:- add a new column Price with Not Null constraint to the existing table library
DESC LIBRARY;
AUTHOR VARCHAR2(20)
PUBLICATION VARCHAR2(20)
YEAR_OF_PUBLICATION NUMBER(4)
Step 4:- All the constraints and views that references the column are dropped
automatically along with the column
Table altered.
DESC LIBRARY;
PUBLICATION VARCHAR2(20)
YEAR_OF_PUBLICATION NUMBER(4)
Table altered.
DESC LIBRARY;
PUBLICATION VARCHAR2(20)
YEAR_OF_PUBLICATION NUMBER(4)
STEP 6:-Change the data type of the column YEAR_OF_PUBLICATION as Text with size 15
Table altered.
DESC LIBRARY;
PUBLICATION VARCHAR2(20)
YEAR_OF_PUBLICATION VARCHAR2(15)
1 row inserted
FOR VERIFICATION
No data found
Table dropped
FOR VERIFICATION
DESC LIBRARY;
Program 4: for a given set of relation schemes, create tables and perform the
following simple queries ,Simple Queries with Aggregate functions, Queries with
Aggregate functions (group by and having clause)
Solution:
Consider the salary database and execute the following simple queries
SALARYDB(EID:String;NAME:Text ;DEPT:String,DOJ:Date;Salary:Number)
Steps:
7.Display Employee information in ascending and descending order of their date of joining .
10.Display the details of the employee whose name is Rushank and salary is greater than
50000.
Table created.
DESC SALARYDB;
DEPT VARCHAR2(10)
DOJ DATE
SALARY NUMBER(10,2)
1 row inserted
1 row created
1 row created
1 row inserted .
1 row inserted.
ENO SALARY
SC 1010 60000
SC1011 45000
SC1013 55000
SC1014 35000
SC1015 55000
SC1016 25000
6 row selected
TOTAL_SALARY
275000
Step5 :find the sum and average salaries of the employees of a particular department
HR 95000 47500
DEPT NUMBER_OF_EMPLOYEES
ADMIN 1
HR 2
FINANCE 2
MARKETING 1
Step 7: Display Employee information in ascending and descending order of their date of
joining
6 row selected
6 row selected
Step 8:Find the highest salary that an employee draws .
HIGHEST_SALARY
___________
60000
LEAST_SALARY
_____________
25000
STEP 10: Display the details of the employee whose name is rushank and salary is greater
than 50000