SlideShare a Scribd company logo
1 of 2
Download to read offline
Bahria University Islamabad
BSCS 4
DBMS Lab, Major Quiz 01 Solution
24th March 2011
Lab Instructor: Saad Hashmi


SECTION I

True/False(Negative marking applies)              (0.5 marks)

Write T/F at the end of following statements. Correct answer .1 point, no attempt 0, incorrect -.05

   1. A foreign key attribute can never contain a null value. F
   2. Only Database Administrators can grant and revoke privileges to other users. T
   3. DBMS Engine helps the user to create and maintain the database and define the structure of the files
      in a database. F
   4. DESCRIBE keyword is used to display the tuples of a table. F
   5. Every primary key is also a superkey, but not vice versa. T



SECTION II        (3 Marks)

Write SQL queries for the following. Refer to Figure 01 for attribute names.

   a)   Find the fName and dNo of employee whose ssn is 125.                                           (.2)

   Select fName, dNo from employee where ssn = 125;

   b) Grant the delete and update operation privileges on EMPLOYEE table to guest.                     (.2)

   Grant delete, update on employee to guest;

   c)   Find out the unique fName(s) of all the employees working in dNo 10.                           (.2)

    Select DISTINCT fName from employee where dNo = 10;

   d) Calculate the number of employees who earn salary of more than 5000.                             (.2)

   Select Count(*) from employee where salary > 5000;

   e) Add a new department with dName ‘Engineering’ and dNumber 25 in the Department table.                        (.3)

   Insert into department (dName, dNumber) values (‘Engineering’, 25);

   f) List the fName of employees who were hired after the date of 31st Dec ‘05 and before 01st Jan ‘07. (.3)

This was a trick question. Hire_date had to be between 1st Jan ’06 and 31st Dec’ 06 because after 31-DEC-05 and before
01-JAN-07 excludes these dates, and between keyword includes the end point dates.

                                                       Page 1
Select fName from employee where hire_date between ’01-JAN-06’ and ’31-DEC-06’;

Since hire_date attribute wasn’t mentioned in the employee table, any attribute name would be considered.

g)   Retrieve the dNumber and dName of all the departments whose name begin with letter ‘S’ and has
     letter ‘A’ as its third character.                                                        (.3)

Select dNumber, dName from department where dName like ‘S_A%’;

h)   In the Employee relation, change the tuple values of the employee(s) to dNo = 15 and
     salary = 14000 whose salary = 12000 and superssn = 67.                                                         (.3)

Update employee set dNo = 15, salary = 14000 where salary = 12000 and superssn = 67;

i)   Delete the records of employees who work in dNo 15, 20 and 25.                                                 (.2)

Delete from employee where dNo in (15,20,25);

j)   For each department in which more than two employees work, retrieve the dNo and the number of
     employees who work in that department.                                                   (.3)

Select dNo, count(*) from employee group by dNo having count(*) > 2;

k)   Create the EMPLOYEE table with the given constraints as shown in the figure.                                   (.5)

CREATE TABLE EMPLOYEE
( FNAME    varchar2(15)    NOT NULL,
MINIT      char,                                                Not Null constraint doesn’t necessarily has to be
LNAME      varchar2(15)    NOT NULL,                            applied on the mentioned attributes.
SSN        char(9)         NOT NULL,
BDATE      date,
ADDRESS    varchar2(30),
SEX        char,
SALARY     number (10, 2),
SUPERSSN char(9),
DNO        number (4)      NOT NULL,
PRIMARY KEY (SSN) ,
FOREIGN KEY (SUPERSSN) REFERENCES EMPLOYEE(SSN) ,
FOREIGN KEY (DNO) REFERENCES DEPARTMENT(DNUMBER) ) ;




                                                       Figure 01
                                                      Page 2

More Related Content

Similar to Dbms quiz 01 solution

SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
SAIFKHAN41507
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
jhe04
 
Here is the company database for the problem--commen.pdf
Here is the company database for the problem--commen.pdfHere is the company database for the problem--commen.pdf
Here is the company database for the problem--commen.pdf
fazilfootsteps
 
Here is the company database--comments can be addedD.pdf
Here is the company database--comments can be addedD.pdfHere is the company database--comments can be addedD.pdf
Here is the company database--comments can be addedD.pdf
fckindswear
 

Similar to Dbms quiz 01 solution (20)

Sql lab experiments
Sql lab experimentsSql lab experiments
Sql lab experiments
 
Dump Answers
Dump AnswersDump Answers
Dump Answers
 
Complex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxComplex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptx
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
Sql task answers
Sql task answersSql task answers
Sql task answers
 
SQL
SQLSQL
SQL
 
Oracle
OracleOracle
Oracle
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2Data Exploration with Apache Drill: Day 2
Data Exploration with Apache Drill: Day 2
 
Spufi
SpufiSpufi
Spufi
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testers
 
90 Informatics Practices.pdf
90 Informatics Practices.pdf90 Informatics Practices.pdf
90 Informatics Practices.pdf
 
Here is the company database for the problem--commen.pdf
Here is the company database for the problem--commen.pdfHere is the company database for the problem--commen.pdf
Here is the company database for the problem--commen.pdf
 
sql language
sql languagesql language
sql language
 
Here is the company database--comments can be addedD.pdf
Here is the company database--comments can be addedD.pdfHere is the company database--comments can be addedD.pdf
Here is the company database--comments can be addedD.pdf
 
DATABASE MANAGEMENT SYSTEM LAB.pdf
DATABASE MANAGEMENT SYSTEM LAB.pdfDATABASE MANAGEMENT SYSTEM LAB.pdf
DATABASE MANAGEMENT SYSTEM LAB.pdf
 
newsql
newsqlnewsql
newsql
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question Bank
 
Dbms record
Dbms recordDbms record
Dbms record
 

Recently uploaded

Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
lizamodels9
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Anamikakaur10
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 

Recently uploaded (20)

RSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors DataRSA Conference Exhibitor List 2024 - Exhibitors Data
RSA Conference Exhibitor List 2024 - Exhibitors Data
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
Business Model Canvas (BMC)- A new venture concept
Business Model Canvas (BMC)-  A new venture conceptBusiness Model Canvas (BMC)-  A new venture concept
Business Model Canvas (BMC)- A new venture concept
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Monthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptxMonthly Social Media Update April 2024 pptx.pptx
Monthly Social Media Update April 2024 pptx.pptx
 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
 
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon ➥99902@11544 ( Best price)100% Genuine Escort In 24...
 
Famous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st CenturyFamous Olympic Siblings from the 21st Century
Famous Olympic Siblings from the 21st Century
 
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
Call Girls Service In Old Town Dubai ((0551707352)) Old Town Dubai Call Girl ...
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptxB.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
B.COM Unit – 4 ( CORPORATE SOCIAL RESPONSIBILITY ( CSR ).pptx
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 

Dbms quiz 01 solution

  • 1. Bahria University Islamabad BSCS 4 DBMS Lab, Major Quiz 01 Solution 24th March 2011 Lab Instructor: Saad Hashmi SECTION I True/False(Negative marking applies) (0.5 marks) Write T/F at the end of following statements. Correct answer .1 point, no attempt 0, incorrect -.05 1. A foreign key attribute can never contain a null value. F 2. Only Database Administrators can grant and revoke privileges to other users. T 3. DBMS Engine helps the user to create and maintain the database and define the structure of the files in a database. F 4. DESCRIBE keyword is used to display the tuples of a table. F 5. Every primary key is also a superkey, but not vice versa. T SECTION II (3 Marks) Write SQL queries for the following. Refer to Figure 01 for attribute names. a) Find the fName and dNo of employee whose ssn is 125. (.2) Select fName, dNo from employee where ssn = 125; b) Grant the delete and update operation privileges on EMPLOYEE table to guest. (.2) Grant delete, update on employee to guest; c) Find out the unique fName(s) of all the employees working in dNo 10. (.2) Select DISTINCT fName from employee where dNo = 10; d) Calculate the number of employees who earn salary of more than 5000. (.2) Select Count(*) from employee where salary > 5000; e) Add a new department with dName ‘Engineering’ and dNumber 25 in the Department table. (.3) Insert into department (dName, dNumber) values (‘Engineering’, 25); f) List the fName of employees who were hired after the date of 31st Dec ‘05 and before 01st Jan ‘07. (.3) This was a trick question. Hire_date had to be between 1st Jan ’06 and 31st Dec’ 06 because after 31-DEC-05 and before 01-JAN-07 excludes these dates, and between keyword includes the end point dates. Page 1
  • 2. Select fName from employee where hire_date between ’01-JAN-06’ and ’31-DEC-06’; Since hire_date attribute wasn’t mentioned in the employee table, any attribute name would be considered. g) Retrieve the dNumber and dName of all the departments whose name begin with letter ‘S’ and has letter ‘A’ as its third character. (.3) Select dNumber, dName from department where dName like ‘S_A%’; h) In the Employee relation, change the tuple values of the employee(s) to dNo = 15 and salary = 14000 whose salary = 12000 and superssn = 67. (.3) Update employee set dNo = 15, salary = 14000 where salary = 12000 and superssn = 67; i) Delete the records of employees who work in dNo 15, 20 and 25. (.2) Delete from employee where dNo in (15,20,25); j) For each department in which more than two employees work, retrieve the dNo and the number of employees who work in that department. (.3) Select dNo, count(*) from employee group by dNo having count(*) > 2; k) Create the EMPLOYEE table with the given constraints as shown in the figure. (.5) CREATE TABLE EMPLOYEE ( FNAME varchar2(15) NOT NULL, MINIT char, Not Null constraint doesn’t necessarily has to be LNAME varchar2(15) NOT NULL, applied on the mentioned attributes. SSN char(9) NOT NULL, BDATE date, ADDRESS varchar2(30), SEX char, SALARY number (10, 2), SUPERSSN char(9), DNO number (4) NOT NULL, PRIMARY KEY (SSN) , FOREIGN KEY (SUPERSSN) REFERENCES EMPLOYEE(SSN) , FOREIGN KEY (DNO) REFERENCES DEPARTMENT(DNUMBER) ) ; Figure 01 Page 2