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

DBMS Assignmnet

The document describes creating tables for a library management system with tables for members, publishers, employees and books. It then provides queries to insert data to the tables, retrieve data from the tables, update and delete records. It also includes two PL/SQL code examples to calculate the factorial of a number and swap two numbers.

Uploaded by

Riya Love
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

DBMS Assignmnet

The document describes creating tables for a library management system with tables for members, publishers, employees and books. It then provides queries to insert data to the tables, retrieve data from the tables, update and delete records. It also includes two PL/SQL code examples to calculate the factorial of a number and swap two numbers.

Uploaded by

Riya Love
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

1|Page

1st Lab Assignment


 Create a table STUDENT with the following attributes and answer
the given questions:

[STUDENT_ID, STUDENT_NAME, STUDENT_ROLL, STUDENT_STREAM,


STUDENT_ADDRESS, STUDENT_MARKS, STUDENT_REGISTRATION]

 QUESTIONS
1. Insert atleast 15 records in the STUDENT table.
 Commands:
CREATE TABLE Student(
student_idNUMBER(4),
student_name VARCHAR2(30),
student_rollNUMBER(6),
student_stream VARCHAR2(20),
student_address VARCHAR2(20),
student_marksNUMBER(4),
student_registration VARCHAR2(10)
);
 Output:

 Query:
INSERT INTO Student VALUES('001','Liza Sinha',1,'CST','Howrah',889,'D202106554');
INSERT INTO Student VALUES('002','Trisa Das',2,'CST','Howrah',782,'D202106555');
INSERT INTO Student VALUES('003','Sayantika Mayur',3,'CST','Kolkata',625,'D202106556');
INSERT INTO Student VALUES('004','Shilpa Betal',4,'Civil','Sodepur',554,'D202106557');
INSERT INTO Student VALUES('005','Rajeswari
Basu',5,'Electrical','Barrackpore',625,'D202106558');
INSERT INTO Student VALUES('006','Arijit Mitra',6,'Electrical','Barrackpore',753,'D202106559');
INSERT INTO Student VALUES('007','Biswarup Das',7,'Civil','Baranagar',690,'D202106560');
INSERT INTO Student VALUES('008','Sneha Ghosh',8,'CST','Sodepur',662,'D202106561');
INSERT INTO Student VALUES('009','Shobnom Dasgupta',9,'Civil','Ghola',735,'D202106562');
INSERT INTO Student VALUES('010','Abhraneel
Bose',10,'Mechanical','Kolkata',841,'D202106563');
INSERT INTO Student VALUES('011','Projjal Sarkar',11,'Civil','Agarpara',583,'D202106564');
INSERT INTO Student VALUES('012','Rohan
Banerjee',12,'Electrical','Belghoria',650,'D202106565');
INSERT INTO Student VALUES('013','Jayashree
Das',13,'Automobile','Howrah',772,'D202106566');
INSERT INTO Student VALUES('014','Sumon Sanati',14,'Electrical','Kona',635,'D202106567');
2|Page

INSERT INTO Student VALUES('015','Promita


Palui',15,'Mechanical','Kolkata',851,'D202106568');
 Output:

2. Show the structure of the table(without data).

 Query:
DESC Student;

 Output:

3. Show the table with its content(all data).


 Query:
SELECT * FROMStudent;

 Output:

4. Arranged the table in a sorting manner.


 Query:
3|Page

SELECT* FROM student ORDER BYstudent_id;


 Output:

5. Create a view table to show the students name and id.


 Query:
CREATE view SHOW as SELECTstudent_id,student_nameFROM Student
WHEREstudent_marks<1000;
 Output:

 Query:
SELECT * FROM Show;
 Output:
4|Page

6. Delete the record for the student ‘Rohan Banerjee’.


 Query:
DELETEFROM Student WHEREstudent_name='Rohan Banerjee';
 Output:

 Query:
SELECT * FROMStudent ORDER BYstudent_id;
 Output:

7. Insert a new record whose name is ‘Ankush Banerjee’ from the


Department ‘Mechanical’.
 Query:
insert into
Student(student_id,student_name,student_roll,student_stream,student_address,student_marks,st
udent_registration) VALUES('016','Ankush
Banerjee',16,'Mechanical','Shyambazar',932,'D202106588');
 Output:

 Query:
SELECT * FROMStudent ORDER BY student_id;
 Output:
5|Page

8. Show the detail of the students who got above 800.


 Query:
SELECT * FROMStudent WHEREstudent_marks>800;
 Output:

9. Show the Registration Number and Students Name who are from
Barrackpore.
 Query:
SELECTstudent_name,student_registrationFROMStudent WHERE
student_address='Barrackpore';
 Output:

10. Show the table without containing the records where the students
are from ‘Baranagar’.
 Query:
SELECT * FROMStudent WHEREstudent_address='Baranagar';
 Output:
6|Page

2nd Lab Assignment


 Create a small LIBRARY MNAGEMENT SYSTEM with the
following 4 tables and answer the given questions:
 TABLES
 MEMBER_MASTER (will contain details of the members of Library)
 PUBLISHER_MASTER (will contain the details of publishers )
 EMPLOYEE_MASTER(will contain the details of employees of the Library)
 BOOK_MASTER (will contain the details of available books of the Library)
[assume any of the attribute names of the tables as per the given question : e.g.: for the
table BOOK_MASTER --- the attributes: B_ID, B_TYPE, B_NAME, B_AUTHOR, B_PRICE,… etc.]
 QUESTIONS :
 Commands:
CREATE TABLE MEMBER_MASTER(
M_NUMBER VARCHAR(10),
M_NAME VARCHAR2(30),
M_ADDRESS VARCHAR2(20)
);
 Output:

 Query:
INSERT INTO MEMBER_MASTER VALUES('M001','Liza Sinha','Howrah-711106');
INSERT INTO MEMBER_MASTER VALUES ('M002','Trisa Das','Howrah-711106');
INSERT INTO MEMBER_MASTER VALUES ('M003','Sayantika Mayur','Kolkata-700078');
INSERT INTO MEMBER_MASTER VALUES ('M004','Shilpa Betal','Sodepur-711067');
INSERT INTO MEMBER_MASTER VALUES ('M005','Rajeswari Basu','Barrackpore-700045');
 Output:

 Commands:
CREATE TABLE PUBLISHER_MASTER(
P_ID NUMBER(10),
P_NAME VARCHAR2(30)
);
 Output:
7|Page

 Query:
INSERT INTO PUBLISHER_MASTER VALUES('01','Ray and Martine');
INSERT INTO PUBLISHER_MASTER VALUES('02','Chaya Prakashani');
INSERT INTO PUBLISHER_MASTER VALUES('03','Parul Prakashani');
INSERT INTO PUBLISHER_MASTER VALUES('04','Dey and Ray');
INSERT INTO PUBLISHER_MASTER VALUES('05','Martine and sons');
 Output:

 Commands:
CREATE TABLE EMPLOYEE_MASTER(
E_ID NUMBER(10),
E_NAME VARCHAR2(30),
E_SALARY VARCHAR(10)
);
 Output:

 Query:
INSERT INTO EMPLOYEE_MASTER VALUES('01','Liza Sinha','30000');
INSERT INTO EMPLOYEE_MASTER VALUES('02','Trisa Das','35000');
INSERT INTO EMPLOYEE_MASTER VALUES('03','Sayantika Mayur','15000');
INSERT INTO EMPLOYEE_MASTER VALUES('04','Shilpa Betal','20000');
INSERT INTO EMPLOYEE_MASTER VALUES('05','Rajeswari Basu','27000');
 Output:

 Commands:
CREATE TABLE BOOK_MASTER(
B_ID NUMBER(10),
B_NAME VARCHAR2(30),
B_TYPE VARCHAR2(20),
B_AUTHOR VARCHAR2(20),
B_PRICE NUMBER(10)
);
 Output:
8|Page

 Query:
INSERT INTO BOOK_MASTER VALUES('001','Python','Text book','Ray and Dey',500);
INSERT INTO BOOK_MASTER VALUES('002','Hamlet','Story book','William
Shakespeare',1000);
INSERT INTO BOOK_MASTER VALUES('003','DBMS','Text book','Dey and Kanan',670);
INSERT INTO BOOK_MASTER VALUES('004','LetsC','Textbook','Biswas and Maity',350);
INSERT INTO BOOK_MASTER VALUES('005','Paradise Lost','Storybook','John
Milton',280);
 Output:

1. Find the name of all the members , employees, publishers.


 Query:
SELECT M_NAME FROM MEMBER_MASTER;
 Output:

 Query:
SELECT E_NAME FROM EMPLOYEE_MASTER;
 Output:

 Query:
SELECT P_NAME FROM PUBLISHER_MASTER;
 Output:
9|Page

2. Retrieve the entire contents of the table BOOK_MASTER.


 Query:
SELECT * FROM BOOK_MASTER ORDER BY B_ID;
 Output:

3. List the various type of books available.


 Query:
SELECT B_NAME,B_TYPE FROM BOOK_MASTER;
 Output:

4. Find the employee who have salary greater than Rs. 25000.
 Query:
SELECT E_NAME FROM EMPLOYEE_MASTER WHEREE_SALARY>25000;
 Output:

5. Change the address of the member number ‘M005’ to ‘kol-56’.


 Query:
UPDATE MEMBER_MASTER SET M_ADDRESS='kol-56' WHERE M_NUMBER=‘M005’;
 Output:

 Query:
SELECT * FROM MEMBER_MASTER ORDER BY M_NUMBER;
 Output:
10 | P a g e

6. Delete all the books name which have a price greater than Rs.500.
 Query:
DELETEFROM BOOK_MASTER WHERE B_PRICE>500;
 Output:

 Query:
SELECT * FROM BOOK_MASTER ORDER BY B_ID;
 Output:

7. Add a field named Mem_ph of data type ‘varchar 2’ and size ‘13’ to
the MEMBER _MASTER table.
 Query:
ALTERTABLE MEMBER_MASTER ADDMem_ph varchar2(13);
 Output:

 Query:
SELECT * FROM MEMBER_MASTER ORDER BY M_NUMBER;
 Output:

8. List the number of all members having ‘s’ or ‘S’ as the first latter in
their name.
 Query:
SELECT M_NUMBER,M_NAME FROM MEMBER_MASTER WHERE M_NAME LIKE 'S%';
11 | P a g e

 Output:

9. Find the name of all employee of library that having ‘a’ or ‘A’ as the
2nd letter in their name.
 Query:
SELECT E_NAME FROM EMPLOYEE_MASTER WHERE E_NAME LIKE '_a%';
 Output:

10. Arrange the books in their maximum price.


 Query:
SELECT B_NAME,B_PRICE FROM BOOK_MASTER GROUP BY B_NAME,B_PRICE ORDER BY
MAX(B_PRICE);
 Output:

 PL/SQL (any two)

11. Write the PL/SQL codes to calculate the FACTORIAL of a number.

 Source Code:
declare
numint:=7;
res int;
function fact(num IN int)
return int
AS
f int;
begin
f:=1;
for i in 1..num loop
f:=f*i;
end loop;
12 | P a g e

return f;
end fact;
begin
dbms_output.put_line('FINDING FACTORIAL OF:'||num);
res:=fact(num);
dbms_output.put_line('FACTORIAL IS:'||res);
end;

 Output:

12. Write the PL/SQL codes to calculate the SWAPPING of two


numbers.

 Source Code:
declare
num1 number;
num2 number;
temp number;
begin
num1:=544;
num2:=455;
dbms_output.put_line('before');
dbms_output.put_line('num1 = '|| num1 ||' num2 = '|| num2);
temp := num1;
num1 := num2;
num2 := temp;
dbms_output.put_line('after');
dbms_output.put_line('num1 = '|| num1 ||' num2 = '|| num2);
end;
 Output:
13 | P a g e

You might also like