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

Complex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxComplex Queries using MYSQL00123211.pptx
Complex Queries using MYSQL00123211.pptxmetriohanzel
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handoutsjhe04
 
Sql task answers
Sql task answersSql task answers
Sql task answersNawaz Sk
 
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 2Charles Givre
 
Top 40 sql queries for testers
Top 40 sql queries for testersTop 40 sql queries for testers
Top 40 sql queries for testerstlvd
 
90 Informatics Practices.pdf
90 Informatics Practices.pdf90 Informatics Practices.pdf
90 Informatics Practices.pdfvikas500500
 
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.pdffazilfootsteps
 
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.pdffckindswear
 
SQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankSQL-RDBMS Queries and Question Bank
SQL-RDBMS Queries and Question BankMd Mudassir
 

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

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.pptxAndy Lambert
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMRavindra Nath Shukla
 
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyThe Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyEthan lee
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsMichael W. Hawkins
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsP&CO
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Serviceritikaroy0888
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMANIlamathiKannappan
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communicationskarancommunications
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesDipal Arora
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...Any kyc Account
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
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 Centuryrwgiffor
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
A305_A2_file_Batkhuu progress report.pdf
A305_A2_file_Batkhuu progress report.pdfA305_A2_file_Batkhuu progress report.pdf
A305_A2_file_Batkhuu progress report.pdftbatkhuu1
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
 

Recently uploaded (20)

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
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Monte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSMMonte Carlo simulation : Simulation using MCSM
Monte Carlo simulation : Simulation using MCSM
 
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case studyThe Coffee Bean & Tea Leaf(CBTL), Business strategy case study
The Coffee Bean & Tea Leaf(CBTL), Business strategy case study
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael Hawkins
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 
Call Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine ServiceCall Girls In Panjim North Goa 9971646499 Genuine Service
Call Girls In Panjim North Goa 9971646499 Genuine Service
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Pharma Works Profile of Karan Communications
Pharma Works Profile of Karan CommunicationsPharma Works Profile of Karan Communications
Pharma Works Profile of Karan Communications
 
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best ServicesMysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
Mysore Call Girls 8617370543 WhatsApp Number 24x7 Best Services
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
KYC-Verified Accounts: Helping Companies Handle Challenging Regulatory Enviro...
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
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
 
7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
A305_A2_file_Batkhuu progress report.pdf
A305_A2_file_Batkhuu progress report.pdfA305_A2_file_Batkhuu progress report.pdf
A305_A2_file_Batkhuu progress report.pdf
 
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
VVVIP Call Girls In Greater Kailash ➡️ Delhi ➡️ 9999965857 🚀 No Advance 24HRS...
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 

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