Assignment 1 DBMS Solution by Jaya

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Maulana Abul Kalam Azad University of Technology, West Bengal

Jaya Das
Roll No:30011218009
Assignment-1
Subject : Advanced Database Management System Lab
Subject Code : PGCSE291/PGSE291

1. Create table DEPARTMENT


Column Name Data Type Size Constraints
DeptCode Varchar2 4 Not null, Primary key
DeptName Varchar2 40 Not null
HOD Varchar2 4 Not null
.
Query:

CREATE TABLE DEPARTMENT( DeptCode VARCHAR(4) not


null, DeptName VARCHAR(40) not null, HOD VARCHAR(4) not
null, PRIMARYKEY(DeptCode));

Output:
Table created

2. Insert values into DEPARTMENT table, as follows:


DeptCode DeptName HOD
IT Information Technology F201
BIO Bio Technology F901
CSE Computer Science and F101
Engineering
NS Natural Science F506

Query:
INSERT INTO DEPARTMENT(DeptCode, DeptName, HOD) VALUES ('IT',
'Information Technology','F201');

Output:
1 row created.

Query:
INSERT INTO DEPARTMENT(DeptCode, DeptName, HOD) VALUES ('BIO',
'Bio Technology','F901');

Output:
1 row created

Query:
INSERT INTO DEPARTMENT(DeptCode, DeptName, HOD) VALUES ('NS',
'Natural Science','F506');
Maulana Abul Kalam Azad University of Technology, West Bengal

Output:
1 row created.

Query:
INSERT INTO DEPARTMENT(DeptCode, DeptName, HOD) VALUES ('CSE',
'Computer Science and Engineering','F101');

Output:
1row created

3. Add a foreign key constraint in STUDENT against DeptCode column


which references department
Query:
CREATE TABLE STUDENT(StdId varchar2(4) not null,StdName varchar2(30)
not null,DeptCode varchar2(4) references DEPARTMENT(DeptCode));

Output:
Table created

4.Create table: FACULTY


Column Name Data Type Size Constraints
FacultyCode Varchar2 4 Primary key
FacultyName Varchar2 15 Not null
DateOfJoin Date Not null
DeptCode Varchar2 4 Not null

Query:

CREATE TABLE FACULTY(


FacultyCode VARCHAR(4) not null PRIMARY KEY,
FacultyName VARCHAR(15) not null,
DateOfJoin DATE not null,
DeptCode varchar(4) not null);

Output:
Table created

5. Insert appropriate values in the above table.

FacultyCode FacultyName DateOfJoin DeptCode


F101 M. Sinha 01-01-2005 CSE
F105 P. Sarkar 01-02-2019 CSE
Maulana Abul Kalam Azad University of Technology, West Bengal

F201 S. Mazumder 15-09-2005 IT


F301 S. Mondal 01-08-2018 CSE
F401 D. Majumdar 01-12-2003 IT
F506 N. Biswas 31-12-2013 NS
F607 R. Paul 10-04-2007 BIO
F704 S. Sarkar 01-01-2012 IT
F808 K. Das 15-06-2010 IT
F901 R. Roy 15-06-2017 BIO
F902 R. Biswas 15-06-2018 BIO

Query:
INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)
VALUES ('F101', 'M. Sinha','2005-01-01','CSE');
Output:
1 row created.
Query:

INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)


VALUES ('F105', 'P. sarkar','2019-02-01','CSE');
Output:
1 row created

Query:
INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)
VALUES ('F201', 'S. Mazumder','2005-09-15','IT');
Output:
1 row created.
Query:

INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)


VALUES ('F301', 'S. Mondal','2018-08-01','CSE');
Output:
1 row created.
Query:
INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)
VALUES ('F401', 'D. Majumdar','2003-01-12','IT');
Output:
1 row created.
Query:

INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)


VALUES ('F506', 'N. Biswas','2013-12-31','NS');
Output:
1 row created

Query:
Maulana Abul Kalam Azad University of Technology, West Bengal

INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)


VALUES ('F607', 'R. Paul','2007-04-10','BIO');
Output:
1 row created.
Query:

INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)


VALUES ('F704', 'S. sarkar','2012-01-01','IT');
Output:
1 row created.

Query:
INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)
VALUES ('F808', 'K. Das','2010-06-15','IT');
Output:
1 row created.
Query:

INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)


VALUES ('F901', 'R. Roy','2017-06-15','BIO');
Output:
1 row created.
Query:

INSERT INTO FACULTY(FacultyCode, FacultyName, DateOfJoin, DeptCode)


VALUES ('F902', 'R. Biswas','2018-06-15','BIO');

Output:
1 row created.

6. Alter the table Faculty and add check constraint such that FacultyCode
starts with ‘F’
Query:
ALTER TABLE FACULTY
ADD CONSTRAINT My_Constraint CHECK(FacultyCode like 'F%');

Output:
Table altered.

7. Alter the table Faculty and add check constraint such DeptCode is
either CSE,IT, BIO,NS
Query:
ALTER TABLE FACULTY ADD CHECK(DeptCode IN (‘CSE’,’IT’,’BIO’,’NS’));
Maulana Abul Kalam Azad University of Technology, West Bengal

Output:
Table altered

8. Add constraint : DeptCode of Faculty is foreign key and references


DeptCode in Department.

Query:

ALTER TABLE FACULTY


ADD FOREIGN KEY (DeptCode) REFERENCES DEPARTMENT(DeptCode);
Output:
Table altered

9. Add Constraint: HOD of Department table is foreign key and references


FacultyCode of Faculty.

Query:

ALTER TABLE DEPARTMENT ADD FOREIGN KEY (HOD) REFERENCES


FACULTY(FacultyCode);
Output:
Table altered

10. Find the names of faculties of CSE Department.


Query:
SELECT FacultyName from Faculty where DeptCode='CSE';

Output:

11. Find the number of faculties in the IT department


Query:
SELECT COUNT( * ) as "Number of IT Faculty"
FROM faculty
WHERE DeptCode='IT';

Output:
Maulana Abul Kalam Azad University of Technology, West Bengal

12. Show the names of the heads of departments with department name.

Query:
SELECT HOD, DeptName, FacultyName FROM DEPARTMENT
FULL JOIN FACULTY ON FacultyCode=HOD;
Output:

13. Find the number of faculties who joined in August.


Query:
select count( * )as "no of faculty" from faculty WHERE
to_char(DateOfJoin, 'mon')='aug';
Output:

14. Add an extra attribute to the faculty table - Salary Number(8,2)


Query:
alter table faculty add salary number(8,2);
Output:

15.Insert values into the corresponding field Salary Number(8,2) (Enter


distinct values).
Maulana Abul Kalam Azad University of Technology, West Bengal

Query:
update faculty set salary=45823.00 where FacultyCode='F101';
update faculty set salary=458856.00 where FacultyCode='F201';
update faculty set salary=528856.00 where FacultyCode='F301';
update faculty set salary=522456.00 where FacultyCode='F401';
update faculty set salary=350426.00 where FacultyCode='F506';
update faculty set salary=452106.00 where FacultyCode='F607';
update faculty set salary=252106.00 where FacultyCode='F704';
update faculty set salary=201406.00 where FacultyCode='F808';
update faculty set salary=651406.00 where FacultyCode='F901';
update faculty set salary=658796.00 where FacultyCode='F902';

Output:

Find the Department having more than one faculty.


16.
Query:
select d.DeptName from Department d where (select count(*) from Faculty f
where d.DeptCode=f.DeptCode)>2;
Output:

17. Find the name, department of the faculties who earn between 8000 and
12000.

Query:
select FacultyName,DeptCode from faculty where salary >8000.00 AND salary<12000.00;

Output:
Maulana Abul Kalam Azad University of Technology, West Bengal

18. Find the name of the department with maximum faculties.


Query:
select deptname from department where DeptCode In(select DeptCode from(select
DeptCode, count(*) as num_faculty from faculty group by DeptCode order by 2
desc)where rownum=1);

Output:

19. Find the senior most faculty.


Query:
select facultyname from faculty where dateofjoin in (select min(dateofjoin) from faculty);
Output:

20. Find the name of the faculty who has completed 5 years.
Query:
select facultyname from faculty where To_Char(sysdate,'yyyy')
to_char(dateofjoin,'yyyy')>=5;
Output:

You might also like