SlideShare a Scribd company logo
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

DOCX
Oracle SQL
PDF
201801 CSE240 Lecture 09
PPTX
Function presentation
PDF
Let us c chapter 4 solution
PDF
Tipos de funciones
PPTX
Edu 290 ppt 2
PPTX
Edu 290 ppt 1
Oracle SQL
201801 CSE240 Lecture 09
Function presentation
Let us c chapter 4 solution
Tipos de funciones
Edu 290 ppt 2
Edu 290 ppt 1

Similar to Dbms quiz 01 solution (20)

PDF
Simran kaur,BCA Final Year 2015
PDF
Vijay Kumar
DOC
Sql task answers
PDF
Vishwajeet Sikhwal ,BCA,Final Year 2015
PDF
Priyanka Bhatia.BCA Final year 2015
PDF
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
PPT
Chapter08
DOC
Dump Answers
PDF
Nikhil Khandelwal BCA 3rd Year
PDF
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
PDF
Oracle (SQL), Sulieman Khudruj
DOCX
Sql Queries
PDF
Oracle OCP 1Z0-007题库
PPT
Sql server lab_4
PDF
Pooja Jain
DOC
Activity sep11 solution
PDF
Pooja Bijawat,Bachelor Degree in Computer Application
PDF
Very simple queries of DBMS
PDF
Sql queries questions and answers
Simran kaur,BCA Final Year 2015
Vijay Kumar
Sql task answers
Vishwajeet Sikhwal ,BCA,Final Year 2015
Priyanka Bhatia.BCA Final year 2015
Apurv Gupta, BCA ,Final year , Dezyne E'cole College
Chapter08
Dump Answers
Nikhil Khandelwal BCA 3rd Year
Divyansh Mehta,BCA Final Year 2015 ,Dezyne E'cole College
Oracle (SQL), Sulieman Khudruj
Sql Queries
Oracle OCP 1Z0-007题库
Sql server lab_4
Pooja Jain
Activity sep11 solution
Pooja Bijawat,Bachelor Degree in Computer Application
Very simple queries of DBMS
Sql queries questions and answers
Ad

Recently uploaded (20)

DOCX
Business Management - unit 1 and 2
PPTX
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
PDF
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
PDF
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
PDF
Types of control:Qualitative vs Quantitative
PPTX
Probability Distribution, binomial distribution, poisson distribution
PDF
COST SHEET- Tender and Quotation unit 2.pdf
PPTX
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PDF
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
PDF
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
PPTX
Amazon (Business Studies) management studies
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PDF
Reconciliation AND MEMORANDUM RECONCILATION
PDF
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
DOCX
unit 1 COST ACCOUNTING AND COST SHEET
PDF
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
DOCX
Euro SEO Services 1st 3 General Updates.docx
PDF
Nidhal Samdaie CV - International Business Consultant
Business Management - unit 1 and 2
AI-assistance in Knowledge Collection and Curation supporting Safe and Sustai...
Elevate Cleaning Efficiency Using Tallfly Hair Remover Roller Factory Expertise
SIMNET Inc – 2023’s Most Trusted IT Services & Solution Provider
Types of control:Qualitative vs Quantitative
Probability Distribution, binomial distribution, poisson distribution
COST SHEET- Tender and Quotation unit 2.pdf
job Avenue by vinith.pptxvnbvnvnvbnvbnbmnbmbh
Power and position in leadershipDOC-20250808-WA0011..pdf
340036916-American-Literature-Literary-Period-Overview.ppt
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
Katrina Stoneking: Shaking Up the Alcohol Beverage Industry
Amazon (Business Studies) management studies
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
Reconciliation AND MEMORANDUM RECONCILATION
pdfcoffee.com-opt-b1plus-sb-answers.pdfvi
unit 1 COST ACCOUNTING AND COST SHEET
Solara Labs: Empowering Health through Innovative Nutraceutical Solutions
Euro SEO Services 1st 3 General Updates.docx
Nidhal Samdaie CV - International Business Consultant
Ad

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