SQL Practise Query
SQL Practise Query
Consider the following tables: Hotel(hotelno, name, city),Room(roomno, hotelno, type, price),
Booking(hotelno, guestno, datefrom, dateto, roomno), Guest(guestno, name, address)
Construct the SQL statements for the following:
i. List the names and addresses of all guest alphabetically ordered by name.
ii. List all family rooms with a price below Rs. 400 per night.
iii. List the details of booking for hotel “DasPrakash”.
iv. Retrieve all the details of the hotels in Mysuru city.
2. For the company relational schema given below construct the following queries using relational
algebra
Employee (FName, Mint, LName, SSN, BDate, Address, Gender, Salary, SuperSSN, DNo)
Department (DName, DNumber, MgrSSN, MgrStartDate)
Project (PName, PNumber, PLocation, DNum)
WorksOn (ESSN, PNo, Hours)
Dependent (ESSN, DependentName, Gender, BDate, Relationship)
i) Retrieve the names of all employees in department 5 who work more than 10 hours per week on
“Product X” project
ii) Retrieve the ssn of all employees who either work in department number 5 or directly supervise
an employee who works in department number 5
iii) Find the names of employees who work on all projects controlled by department number 5.
iv) List the name and address of all employees who work for research dept
3. Explain second and third normal form with an example. Consider the relation
EMP_PROJ= {Ssn, Pnumber, Hours, Ename, Pname, Plocation}.
Assume {Ssn, Pnumber} as primary key. The dependencies are
Ssn, Pnumber {Hours}
Ssn {Ename}
Pnumber {Pname, Plocation}.
Identify whether the given relation is in 2NF or not. If not, normalize the relation into 2NF.