SQL Nov 2006 Solved
SQL Nov 2006 Solved
SQL Nov 2006 Solved
NOV- 2006
SQL
CUSTOMER
Attribute Data Type Constraints
Custid Varchar(2) Primary key
Lname Varchar(15)
Fname Varchar(15)
Area Varchar(2)
Phone Number(8)
MOVIE
Attribute Datatype Constraints
Mvno Number(2) Primary key
Title Varchar(25)
Type Varchar(10)
Star Varchar(25)
Price Number(8,2)
INVOICE
Attribute Datatype Constraints
Invno Varchar(3) Primary key
Mvno Number(2) Foreign key movie(mvno)
Custid Varchar(3) Foreign Key customer(custid)
Issue date Date
Return date Date
Q.1 A)State the features of Sql which have made it successful in the market.
Ans in page 8 of James R. Groff.
B) Explain the relational database model.
Ans in page 57 of James R. Groff.
c) If a view is updated, is the original table updated? Under what conditions can a view
not be updated?
Ans in page 423-424 of James R. Groff.
D) Explain the concept of Null values.
Ans in page 91 of James R. Groff.
E) Create the table RIVERS according to the description shown below.
Hiddencomputertricks.blogspot.com
Visit hiddencomputertricks.blogspot.com for more...
1. Add a new column called Maxdepth to the rivers table Make sure that the values of this
column range from 100 to 250 feet.
Ans: Alter table rivers add(Maxdepth number(3)
Check (maxdepth between 100 and 250))
iii. List the temperatures for July from table Data, Lowest temperatures first, picking up city
name and latitude by joining with the table city.
Ans : Select Temp_f, name, Latitude from Data d, City c where
d.Id=c.Id and month=7 order by Temp_f asc
Hiddencomputertricks.blogspot.com
Visit hiddencomputertricks.blogspot.com for more...
iv. List (using Subquery) the cities with year round average temperature above 50 degrees.
Ans : Select name from City where Id in(
Select id from Data where 50 < All(
Select avg(temp_f) from data group by ID))
Q3. A) Explain the column check constraint in sql-2. How can it be applied to many different
columns in the database?
Ans in page 295 of James R. Groff.
B) Explain the problems created by referential cycles on referential integrity.
Ans in page 308 of James R. Groff.
C) What is a deadlock? How can it be avoided? Explain various techniques used to
overcome deadlocks.
Ans in page 348 of James R. Groff.
Q.4. A) Explain the syntax of the select statement with various clauses that can be attached to
it.
Ans in page 96 of James R. Groff.
B) Enumerate the problems that can corrupt referential integrity of the parent/child
Relationships in a database.
Ans in page 299 James R. Groff.
C) Write SQL statements for the following based on the tables CUSTOMER, MOVIE AND
INVOICE
I. Find out the movies that cost more than 159 and also find the new cost as original cost*15
Ans: select mvno, price*15 “NEW COST” from movie where price>159
II. Print the names and types of all the movie except horror movies
Ans: select title, type from movie
where type not in(‘horror’)
III. List the various movie types available
Ans: select distinct type from movie
IV. List the mvno, title of movies whose stars begins with letter’m’
Ans: select mvno, title, type from movie
where star like ‘m%’
V. Determine the maximum and minimum of price. Rename the title as max-price and
min_price respectively.
Ans: select max(price) “max_price”, Min(price) “min_price”
From movie
VI. Find out number of movies in each type
Ans: select count (type) from movie group by type
VII. Find out Lname, Fname and mvno of customers who have been issued a movie.
Ans: select mvno, Lname , Fname From customers, invoice
Where customer.custid = invoice.custid
Q.5 A) What is a trigger? How are triggers used to implement referential integrity?
Hiddencomputertricks.blogspot.com
Visit hiddencomputertricks.blogspot.com for more...
I. Print the information of invoice table in the following format for all records.
The invoice no of customer id.{ custid} is { invno} and movie no is { movno}
Ans: Select ‘the invoice no of customer id : ’|| custid||’ is ‘||invno||’ and movie No. is ‘||
movno from invoice
II. Select the title, custid, mvno for all the movies that are issued.
III. Find out which customers have been issued movie number (Mvno)9.
Ans: Select fname from Customer,invoice
Where customer.custid=invoice.custid and mvno=9
IV. Display the month(in alphabets) in which customers are supposed to return the
movies
Ans: Select to_char(Returndate,’mon’) From invoice
Or Select Month(returnDate) from Invoice
I. Delete all the records having return date before 10th July ‘05
Ans: Delete from invoice
Where returndate<’10-JUL-05’
II. Find out if the movie starring ‘TOM Cruise’ is issued to any customer and list the custid to
whom it is issued
Ans: Select custid from invoice, movie Where invoice.mvno=movie.mvno and movie.star like
‘Tom Cruise’
III. Find the names of customers who have been issued movie of type’drama’
Ans: Select Fname||’ ‘||lname “Name” From customer c, movie M, invoice i Where
c.custid=i.custid AND m.mvno=i.mvno
And m.type like ‘drama’
Hiddencomputertricks.blogspot.com
Visit hiddencomputertricks.blogspot.com for more...
IV. Find out the title of the movies that have been issued to the customer whose Fname is’
Mary’
Ans: Select title from customer, movie, invoice
Where customer.custid=invoice.custid AND
Movie.mvno=invoice.mvno AND Customer.Fname like ‘Mary’
i. Add a column Remark of type varchar and size 25 to the invoice table
Ans: Alter table invoice add(Remark varchar(25));
ii. Find the names of all customers having ‘a’ in the second letter in their fname
Ans: Select Fname||’ ‘|| lname “Name” From customer
Where fname like ’_a%’
iii. Find out the movie number which has been issued to customer whose first name is
‘IVAN’
Ans: select i.mvno from customer c, invoice i
Where c.custid=i.custid and fname like ‘IVAN’
iv. Display the title, Lname,Fname for customers having movie number greater than or
equal to three in the following format. The movie taken by { Fname} { Lname} is { Title}
Ans: Select ‘The movie taken by ‘|| Fname||’ ‘|| Lname||’ is ‘||Title from customer c, movie m,
invoice i
where c.custid=i.custid AND m.mvno=i.mvno and m.mvno>=3
-----------------------
Hiddencomputertricks.blogspot.com