0% found this document useful (0 votes)
66 views6 pages

SQL Sample Questions and Answers

This document contains sample SQL questions and their answer queries. It also has the tables required for these questions. Enjoy

Uploaded by

Balley Mojin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views6 pages

SQL Sample Questions and Answers

This document contains sample SQL questions and their answer queries. It also has the tables required for these questions. Enjoy

Uploaded by

Balley Mojin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Sample Tables for the Test

AntiqueOwners OwnerID OwnerLastName 01 Jones 02 Smith 15 Lawson 21 Akins 50 Fowler Orders OwnerID 02 02 21 15

OwnerFirstName Bill Bob Patricia Jane Sam

ItemDesired Table Desk Chair Mirror

Antiques SellerID 01 02 15 21 50 01 02 15 01 02 21 50

BuyerID 50 15 02 50 01 21 21 50 15 21 02 01

Item Be Table Chair Mirror Desk Cabinet Co!!ee Table Chair Jewelr" Bo# Potter" Bookcase Plant Stan

SSN 512$%&'5% &5%'20012 10225'%.$ %&$5125$(

FirstName Joe Mar" Sam Sarah

LastName Smith Scott Jones Ackerman

EmployeeAddressTable Address %( First Street %'2 +ine A,e(( /lm St''0 2-S- 110

ity )owar Losanti,ille Paris 23ton

State *hio *hio 0ew 1ork Michi4an

EmployeeIDNo

Salary

EmployeeStatisti!sTable Benefits

"osition

010 105 152 215 2'' (00 ((5 '00 ''1

&5000 $5000 $0000 $0000 50000 '5000 '0000 (2000 2%000

15000 15000 15000 12500 12000 10000 10000 &500 &500

Mana4er Mana4er Mana4er Mana4er Sta!! Sta!! Sta!! /ntr"5Le,el /ntr"5Le,el

/#3lain the !ollowin4 S6L statements7


12SELECT OWNERLASTNAME, OWNERFIRSTNAME FROM ANTIQUEOWNERS, ANTIQUES WHERE BUYERID = OWNERID AND ITEM = 'Chair'; SELECT OWN.OWNERLASTNAME, OWN.OWNERFIRSTNAME FROM ANTIQUEOWNERS OWN, ANTIQUES A0T WHERE ANT.BUYERID = OWN.OWNERID AND ANT.ITEM = 'Chair'; SELECT DISTINCT SELLERID, OWNERLASTNAME, OWNERFIRSTNAME FROM ANTIQUES, ANTIQUEOWNERS WHERE SELLERID = OWNERID ORDER BY OWNERLASTNAME, OWNERFIRSTNAME; SELECT SUM(SALARY), A !(SALARY) FROM EM"LOYEESTATISTICSTABLE; SELECT EM"LOYEEIDNO FROM EM"LOYEESTATISTICSTABLE WHERE "OSITION = 'Ma#a$%r' AND (SALARY & '(((( OR BENEFITS & )((((); SELECT MIN(BENEFITS) FROM EM"LOYEESTATISTICSTABLE WHERE "OSITION = Ma#a$%r'; SELECT EM"LOYEEIDNO FROM EM"LOYEESTATISTICSTABLE WHERE SALARY NOT BETWEEN *(((( AND '((((; SELECT EM"LOYEEIDNO FROM EM"LOYEEADDRESSTABLE WHERE LASTNAME LI+E 'S,'; SELECT BUYERID, MA-("RICE) FROM ANTIQUES !ROU" BY BUYERID HA IN! "RICE & )(((; IEW ANT IEW AS SELECT ITEMDESIRED FROM ORDERS;

(-

'5$&%.-

10- CREATE

11- CREATE TABLE ORDERS (OWNERID INTE!ER NOT NULL, ITEMDESIRED CHAR(.() NOT NULL); 12- U"DATE ANTIQUEOWNERS SET OWNERFIRSTNAME = '/0h#' WHERE OWNERID = (SELECT BUYERID FROM ANTIQUES WHERE ITEM = 'B0012a3%'); 1(- SELECT OWNERFIRSTNAME, OWNERLASTNAME FROM ANTIQUEOWNERS WHERE E-ISTS (SELECT 4 FROM ANTIQUES WHERE ITEM = 'Chair'); 1'- SELECT OWNERID, 'i3 i# 506h Or7%r3 8 A#6i9:%3' FROM ORDERS, ANTIQUES WHERE OWNERID = BUYERID UNION SELECT BUYERID, 'i3 i# A#6i9:%3 0#;<' FROM ANTIQUES WHERE BUYERID NOT IN (SELECT OWNERID FROM ORDERS); 15- SELECT 4 FROM ANTIQUEOWNERS, ORDERS;

2sin4 the Sam3le tables8 write a S6L statement to7 1- Show each Anti9:es or er an the last an !irst names o! the 3erson who or ere the itemSELECT A#6i9:%O=#%r3.O=#%rLa36Na>%, A#6i9:%O=#%r3.O=#%rFir36Na>%, Or7%r3.I6%>D%3ir%7 FROM A#6i9:%O=#%r3, Or7%r3 WHERE A#6i9:%O=#%r3.O=#%rID = Or7%r3.O=#%rID; 0r SELECT A#6i9:%O=#%r3.O=#%rLa36Na>%, A#6i9:%O=#%r3.O=#%rFir36Na>%, Or7%r3.I6%>D%3ir%7 FROM A#6i9:%O=#%r3 RI!HT /OIN Or7%r3 ON A#6i9:%O=#%r3.O=#%rID = Or7%r3.O=#%rID;

2- Show each col:mn in the /m3lo"eeStatisticsTable in al3habetical or er b" Position8 then b" /m3lo"ee;D0oSELECT 4 FROM E>?;0<%%S6a6i36i23Ta5;% ORDER BY "03i6i0#, E>?;0<%%IDN0;

(- Show the ann:al b: 4et !or Bene!its !rom the /m3lo"eeStatisticsTableSELECT S:>(B%#%@i63) FROM E>?;0<%%S6a6i36i23Ta5;%;

'- 2sin4 the ;0 *3erator8 show the names o! the owners o! ChairsSELECT O=#%rLa36Na>%, O=#%rFir36Na>% FROM A#6i9:%O=#%r3, A#6i9:%3 WHERE I6%> I# ('Chair') AND A#6i9:%O=#%r3.O=#%rID = A#6i9:%3.B:<%rID;

5- Show the names o! all Anti9:es *wners who ha,e o not ha,e an or er 3lace SELECT O=#%rLa36Na>%, O=#%rFir36Na>% FROM A#6i9:%O=#%r3 WHERE O=#%rID NOT IN (SELECT O=#%rID FROM Or7%r3);

$- Show the names o! those who ha,e 3lace Anti9:e or ers8 with no :3licatesSELECT DISTINCT O=#%rLa36Na>%, O=#%rFir36Na>% FROM Or7%r3, A#6i9:%O=#%r3 WHERE A#6i9:%O=#%r3.O=#%rID = Or7%r3.O=#%rID; 0r 60 :3% /OIN #06a6i0#A SELECT DISTINCT A#6i9:%O=#%r3.O=#%rLa36Na>%, A#6i9:%O=#%r3.O=#%rFir36Na>% FROM A#6i9:%O=#%r3 RI!HT /OIN Or7%r3 ON A#6i9:%O=#%r3.O=#%rID = Or7%r3.O=#%rID;

&- Delete all o! Bob Smith<s Anti9:e or ersDELETE FROM ORDERS WHERE OWNERID = (B;

%- Create an Anti9:e or er !or a =ockin4 Chair !or Jane AkinsINSERT INTO ORDERS ALUES (B), 'R021i#$ Chair');

.- Create a table calle /m3lo"ees8 with col:mns /m3lo"ee;D0o8 First0ame8 an Last0ameCREATE TABLE EM"LOYEES (E>?;0<%%IDN0 INTE!ER NOT NULL, Fir36Na>% CHAR(.() NOT NULL, La36Na>% CHAR(.() NOT NULL);

10- Show the ann:al b: 4et !or Salar" b" each 3osition !rom the /m3lo"eeStatisticsTable
SELECT "03i6i0#, S:>(Sa;ar<) FROM E>?;0<%%S6a6i36i23Ta5;% !ROU" BY "03i6i0#;

11- >hat is the relationshi3 between the Anti9:e*wners table an the *wners table? *ne to one 12- ;! "o: o not ha,e a 3rimar" ke" in a table8 the a ition o! what t"3e o! col:mn is 3re!erre to 4i,e the table a 3rimar" ke"? An inte4er i enti!ication n:mber@ an a:to5increment ;D is 3re!erre 1(- >hich !:nction will allow "o: to s:bstit:te a 4i,en ,al:e !or an" 0:ll ,al:es arisin4 !rom a Select statement? 0+L 1'- ;! all o! the col:mns in all o! the tables in "o:r schema are e3en ent solel" on the ,al:e o! the 3rimar" ke" in each table8 in which 0ormal Form is "o:r esi4n? Thir 0ormal Form 15- >hat term is :se to escribe the e,ent o! a atabase s"stem a:tomaticall" :3 atin4 the ,al:es o! !orei4n ke"s in other tables8 when the ,al:e o! a 3rimar" ke" is :3 ate ? Casca in4 :3 ate 1$- >hat atabase obAect 3ro,i es !ast access to the ata in the rows o! a table? ;0D/B 1&- >hat t"3e o! S6L statement is :se to chan4e the attrib:tes o! a col:mn?
ALTER TABLE.

1%- ;n a Create Table statement8 when a col:mn is esi4nate as 0*T 02LL8 what oes this mean? A ,al:e is re9:ire in this col:mn !or e,er" row in the table

20- ;! "o: wish to write a 9:er" that is base on other 9:eries8 rather than tables8 what o these other 9:eries nee to be create as?

You might also like