Sie sind auf Seite 1von 9

UNIT CYCLE No 1 Class XII (SET A)(Answer Key) Subject : In!

or"at#cs $ract#ces
%ENE&AL INST&UCTI'NS All (uest#ons are co")ulsory **+ ,1 (a) (b) Write MySql command to open an existing database. T#"e 1 .r+

Use abc/ 'r Use any0atabasena"e/


Ms. Mirana wants to remove the entire content of a table BA !"#$ alongwith its str%ct%re to release the storage space. What MySql statement sho%ld she %se&

1ro) table bac2u)/


(c) 'ive one difference between ()**BA ! and )MM+, commands %sed in MySql.

&'LL3ACK co""an0 #s use0 to 0#scar0 t4e c4an5es "a0e #n t4e 0atabase u) to last co""#t w4ereas co""#t co""an0 #s use0 to )er"anent sa6e t4e 0ata #n an &13*S+
(0) A table S,"-./,S has 0 rows and 1 col%mns and another table ,.A 2.( has 3 rows and 0 col%mns. 2ow many rows and col%mns will be there if we obtain the artesian prod%ct of these two tables&

&ows 17 Colu"ns 8
(e) Mr. Sanghi created two tables with +,4 as #rimary !ey in ,able5 and 6oreign !ey in ,able1. While inserting a row in ,able17 Mr. Sanghi is not able to enter a val%e in the col%mn +,4. What co%ld be the possible reason for it& 5

&e!erent#al #nte5r#ty en!orce"ent ensures t4at 6alue "ust e9#st #n re!erre0 table !or success!ul #nsert#on #n t4e 0e)art"ent table+ '& Any relat#ons4#) s4ow#n5 t4e )r#"ary !ore#5n 2ey relat#ons4#)+
(!) Mr. 8ana9 is %sing a table with following col%mns : /ame7 lass7 o%rse;+d7 o%rse;name 2e needs to display names of st%dents7 who have not been assigned any stream or have been assigned o%rse;name that ends with <economics < 2e wrote the following command7 which did not give hte desired res%lt. SELECT Name, Class FROM Students WHERE Course_name=NULL OR Course_name= %econom cs ! 2elp Mr. 8ana9 to r%n the q%ery by removing the error and write the correct q%ery. 5

Select na"e !ro" stu0ents w4ere course:na"e #s null or

course:na"e l#2e ; <econ"#cs ; /


(5) Why do yo% mean by partial rollbac9 of a database & Write MySql q%ery =s> to do partial rollbac9 in a -atabase named as S,"-./,. +t means the changes done by the transaction is rollbac9 %p to the latest save point. (ollbac9 to S5 Where S5 is the latest save point. /ame the two constraints %sed for storing only the specified val%es in the attrib%tes of a table. 1

(4)

Enu" an0 SET


7 =a> What is the p%rpose of )(-.( B4 cla%se in MySql& 2ow is it different from '()"# B4 cla%se & 'ive S%itable .xample=s> . 1

'r0er by clause #s use0 to arran5e t4e 0ata 6alue #n ascen0#n5 or #n 0escen0#n5 or0er w4ere as 5rou) by clause #s use0 to 5rou)s tu)les to5et4er base0 on t4e s)ec#!#e0 5rou) attr#butes .
=b> Select ename7sal from emp order by ename? Select s%m=sal>7ename7 dname from emp gro%p by dname? onsider the ,able S2)##. given below. Write command in MySql for =i> to =v> and o%tp%t for =vi> to =vii>. ,able S.'$$E: Co0e Ite" Co")any =ty C#ty $r#ce 5@1 Bisc%it 2ide A See9 5@@ -elhi 5@.@@ 5@3 8am !issan 55@ !ol9ata 1B.@@ 5@5 offee /estle 1@@ !ol9ata BB.@@ 5@C Sa%ce Maggi BC M%mbai BB.@@ 5@D a9e Britannia D1 -elhi 5@.@@ 5@0 Maggi /estle 5B@ M%mbai 5@.@@ 5@B hocolate adb%ry 5D@ -ehli 1B.@@ ,o display names of the items whose name starts with < E in ascending order of #rice. 5

=i>

Select #te" !ro" s4o))e w4ere #te" l#2e ;C<> or0er by )r#ce+
=ii> =iii> ,o display ode7 +tem name and ity of the prod%cts whose q%antity is less than 5@@. 5 5

Select co0e?#te"+c#ty !ro" s4o))e w4ere (ty @1--/


,o print vario%s company names whose items are recorded in the table shoppe.

Select 0#st#nct co")any !ro" s4o))e/ '& Select co")any !ro" s4o))e 5rou) by co")any/
=iv> =v> ,o print the ,otal F%antity of +tems s%pplied in .ach city. 5 5

Select c#ty ? su"((ty)!ro" s4o))e 5rou) by c#ty/


,o print the total amo%nt of money collected from each city in the table

Select c#ty? su"()r#ceA(ty) !ro" s4o))e 5rou) by c#ty/

=v+>

Select +tem from Shoppe where +tem +/ =8am$7 offee$>? ITEM ______ Jam Coffee Select M+/ =Fty>7 Avg=#riceGFty> from Shoppe where ityH$M%mbai$? 56, 2290 Select distinct city from Shoppe where price I 1B? Kolkata Mumbai Write MySql command to create the ,able S,) ! incl%ding its onstraints. ,able ST'CK: Ty)e S#Be Jarchar 1@ Jarchar 1@ -ecimal K +nteger 1

=vii> =viii>

5 5

3.

(a)

5 Na"e o! Colu"n /ame ompany #rice Stoc9 Constra#nt #rimary !ey /ot /%ll /ot /%ll

=b>

Create table Stoc2 ( na"e 6arc4ar(7-)? Co")any 6arc4ar(7-) ? $r#ce 0ec#"al(C?-) not null? Stoc2 #nt(7)not null? $r#"ary 2ey(na"e?co")any) )/ +n a -atabase there are two tables: ICo0e 5@5 1@1 3@3 0@0 ,able ITE*: Ina"e ,elevision omp%ter (efrigerator Washing Machine ,able 3&AN1: ICo0e 5@5 1@1 3@3 0@0 3ran0:Na"e Sony 2# *' +6B $r#ce DB@@@ 01@@@ L@@@@ 1D@@@

=i>

(##)

Write MySql q%ery to display + ode7 +/ame and corresponding Brand /ames of those +tems7 whose #rice is between 1@@@@ and 0B@@@ =both val%es incl%sive>. Select Ite"+#co0e? #te"+#na"e? bran0+bran0:na"e !ro" #te"?bran0 w4ere #te"+#co0eDbran0+#co0e an0 #te"+)r#ce between 7--- an0 EF--/ Write MySql q%ery to display + ode7 #rice and Brand;/ame7 of the item which has +/ame as ,elevision Select Ite"+#co0e? #te"+#na"e? bran0+bran0:na"e !ro" #te"?bran0 w4ere #te"+#co0eDbran0+#co0e an0 #te"+#na"eDGTele6#s#onG/ Write a q%ery to print the details of all +tems of *' and +6B brands only Select #te"+A ? bran0:na"e !ro" #te"? bran0 w4ere #te"+#co0eDbran0+#co0e HH bran0:na"e #n(;l5>?>#!b>)/

(###)

(###)

Write MySql q%ery to increase the price of all +tem by 5BM of existing price U)0ate #te" set )r#ceD)r#ceI(()r#ceA1F)J1--) / 'r select )r#ceI(()r#ceA1F)J1--) as K#ncrease0 $r#ceG !ro" #te"/ Write MySql q%ery to create a cross Noin of +,.M and B(A/- table. Select A !ro" #te"? bran0/ 'iven below is a ,able #atient and -octor ,AB*. : #A,+./, /ame #;/o Jimla 8ain #@@@5 +shita !ohli #@@51 JiNay Jerma #5@@1 JiNay Jerma #5BCD ,AB*. : -) ,)( /ame -r. (avi #ra9ash -r. Alo9 Mittal -r. Ar%n !%mar -r. Ar%na

(#6)

(c)

-ate;Admn 1@55O5@O55 1@55O5@O55 1@55O5@O5D 1@55O55O11

-oc;/o -1@5 -B@C -1@5 -133

-;/o -1@5 -B@C -1@5 -133

SpecialiPation ardiologist )rthopedic hild Specialist 'ynecologist

#;/o #@@@5 #@@51 #5@@1 #5BCD

(#)

write Mysql query (s) to delete D_No attribute in doctor table and then use Name and Specialization attributes to jointly act as Primary key or the Doctor !able

alter table doctor drop primary key" alter table doctor add primary key(name# specialization)" alter table doctor modi y primary key( specialization)"

(##)

$rite MySql query Doctor name

to Print the Patient Name and their correspondin%

Select doctor&name#patient&name patient&p_no'doctor&p_no" (###)

rom patient# doctor where

$rite the output produced by the ollowin% queries a) Select (en%th(Mid()*n ormatics Practices+#, #,,))" ,, b) Select pow(*nstr()Delhi Public School -haziabad+#)My School+)#,)" , c) Select .ound (/012&34/ # 53)" /166 d) Select Day(curdate())" 77 assume that query is e8ecuted today ,1 e) Select year()36,3,3,3+)" 36,3 ) Select ucase(mid()M9 S:;<<( *S DPS- +#5/))" DPS-

Q C H 3

UNIT CYCLE No 1 Class XII (SET 3)(Answer Key) Subject : In!or"at#cs $ract#ces
%ENE&AL INST&UCTI'NS All (uest#ons are co")ulsory **+ ,1 (a) (b) T#"e 1 .r+ Write MySql command to view names of all existing databases. select 0atabases/ Ms. Mirana wants to remove the entire content of a table BA !"#$ b%t not the str%ct%re of the table. What MySql statement sho%ld she %se& 1elete !ro" bac2u)/ 'ive one difference between ()**BA ! and ()**BA ! ,) commands %sed in MySql. &'LL3ACK UN1' ALL T.E C.AN%ES 1'NE L&'* T.E STA&TIN% 'L T.E T&ANSACTI'N M.ILE &'LL3ACK T' UN1' ALL T.E C.AN%ES 1'NE U$T' T.E LATEST SANE$'INT 1ELINE1 1U&IN% T.E T&ANSACTI'N+ SYNTAX: &'LL3ACK/ &'LL3ACK T' SANE$'INT S/ A table S,"-./,S has 1 rows and 0 col%mns and another table ,.A 2.( has 0 rows and

(c)

(0)

(e)

(!)

3 col%mns. What will be the cardinality and degree of the res%ltant table if we obtain the artesian prod%ct of these two tables& 1e5ree O Car0#nal#ty C Mr. Sanghi created two tables with +,4 as 6oreign !ey in ,able5 and #rimary !ey in ,able1. While inserting a row in ,able57 Mr. Sanghi is not able to enter a val%e in the col%mn +,4. What co%ld be the possible reason for it& &e!erent#al #nte5r#ty en!orce"ent ensures t4at 6alue "ust e9#st #n re!erre0 table !or success!ul #nsert#on #n t4e 0e)art"ent table+ Mr. 8ana9 is %sing a table with following col%mns : /ame7 lass7 o%rse;+d7 o%rse;name 2e needs to display names of st%dents7 who have not been assigned any stream or have been assigned o%rse;name that ends with <economics < 2e wrote the following command7 which did not give hte desired res%lt. SELECT Name, Class FROM Students WHERE Course_name= "NULL OR Course_name = %econom cs ! 2elp Mr. 8ana9 to r%n the q%ery by removing the error and write the correct q%ery. Select na"e?class !ro" stu0ents w4ere course:na"e #s null or course:na"e l#2e ; <econ"#cs ; / *ist the q%ery =s> to do partial rollbac9 in a -atabase . Also state the category of mySql to which these F%eries belong to. &'LL3ACK T' SANE$'INT NA*E /

(5)

(4)

What is <./"ME & Why is it %sed in MySql. IT INCLU1ES ALL T.E NALUES IN A S$ECILIE1 1'*AIN+ S' T.E NALUES IN T.IS C'LU*N MILL 3E L&'* S$ECILIE1 SET 'NLY+ Which cla%se do we %se in MySql to a> Arrange the -ata in ascending R descending )rder& '&1E& 3Y? '&1E& 3Y 1ESC EX: SELECT A L&'* TA3LENA*E M.E&E @NA*EPD@C'N1ITI'NP '&1E& 3Y @C'LU*N NA*EP 1ESC/ b> 'enerate the s%mmary information of similar rows in the table. %rou) 3y Clause 'ive S%itable .xample for each cla%se.

=a>

=b>

onsider the ,able S2)##. given below. Write command in MySql for =i> to =v> and o%tp%t for =vi> to =vii>. ,able S.'$$E: Co0e Ite" Co")any =ty C#ty $r#ce 5@1 Bisc%it 2ide A See9 5@@ -elhi 5@.@@ 5@3 8am !issan 55@ !ol9ata 1B.@@ 5@5 offee /estle 1@@ !ol9ata BB.@@ 5@C Sa%ce Maggi BC M%mbai BB.@@ 5@D a9e Britannia D1 -elhi 5@.@@ 5@0 Maggi /estle 5B@ M%mbai 5@.@@ 5@B hocolate adb%ry 5D@ -ehli 1B.@@ ,o display names of the items whose name does not start with < E in descending order of #rice. 5

=i>

Select #te" !ro" s4o))e w4ere #te" N'T l#2e ;C<> or0er by )r#ce+
=ii> =iii> =iv> ,o display ode7 +tem name and ity of the prod%cts whose q%antity is not less than 5@@. 5 5 5

Select co0e?#te"+c#ty?ITE* !ro" s4o))e w4ere (ty PD1--/


,o co%nt vario%s city names recorded in the table.

SELECT C'UNT(1ISTINCT CITY) L&'* S.'$$E/

,o print the ,otal F%antity s%pplied and name of city for all cities where q%antity s%pplied is more than 5@@..

SELECT SU*(=TY) AS KT'TAL =TYG?CITY L&'* S.'$$E %&'U$ 3Y CITY .ANIN% SU*(=TY)P1--/
=v> =v+> ,o print the total no of items s%pplied in each city SELECT SU*(=TY)?CITY L&'* S.'$$E %&'U$ 3Y CITY/ Select +tem from Shoppe where +tem +/ = a9e$7 Sa%ce$>? CAKE SAUCE Select MAQ =Fty>7 Avg=#riceGFty> from Shoppe where /), ityH$M%mbai$? 7--?CQEE Select distinct city from Shoppe where price S 1B? 1EL.I 5 5

=vii> =viii>

5 5

3.

(a)

Write MySql command to create the ,able S,) ! incl%ding its onstraints. 5 Na"e o! Colu"n /ame ompany #rice Stoc9 Create table Stoc2 ( na"e 6arc4ar(7-)? Co")any 6arc4ar(7-) ? $r#ce 0ec#"al(C?-) not null? Stoc2 #nt(7)not null? $r#"ary 2ey(na"e?co")any) )/ ,able ST'CK: Ty)e S#Be Jarchar 1@ Jarchar 1@ -ecimal K +nteger 1 Constra#nt #rimary !ey /ot /%ll /ot /%ll

=b>

+n a -atabase there are two tables: ICo0e 5@5 1@1 3@3 0@0 ,able ITE*: Ina"e ,elevision omp%ter (efrigerator Washing Machine ,able 3&AN1: ICo0e 5@5 1@1 3@3 0@0 3ran0:Na"e Sony 2# *' +6B $r#ce DB@@@ 01@@@ L@@@@ 1D@@@

=i>

(##)

(###)

Write MySql q%ery to display ++tem -etails and Brand /ames of those +tems7 whose #rice is between 1@@@@ and 0B@@@ =both val%es incl%sive>. Select ITE*+A? bran0:na"e !ro" #te"?bran0 w4ere #te"+#co0eDbran0+#co0e an0 )r#ce between 7---- an0 EF---/ Write MySql q%ery to display + ode7 #rice and Brand;/ame7 of the item which does not have +/ame as ,elevision Select Ite"+#co0e?)r#ce?bran0+bran0:na"e !ro" #te"?bran0 w4ere #te"+#co0eDbran0+#co0e an0 not #te"+#na"eDGTele6#s#onG/ Write a q%ery to print the name and price of all +tems of *' and +6B brands only Select #te"+)r#ce ?bran0:na"e !ro" #te"? bran0 w4ere #te"+#co0eDbran0+#co0e HH bran0:na"e #n(;l5>?>#!b>)/

(###) (#6) (c)

Write MySql q%ery to decrease the price of all +tem by 5B@@ of existing price U)0ate #te" set )r#ceD)r#ce 1F--/ Write MySql q%ery to create a cartisian prod%ct of +,.M and B(A/- table. Select A !ro" #te"? bran0/ 'iven below is a ,able #atient and -octor ,AB*. : #A,+./, /ame #;/o -ate;Admn -oc;/o Jimla 8ain #@@@5 1@55O5@O55 -1@5 +shita !ohli #@@51 1@55O5@O55 -B@C JiNay Jerma #5@@1 1@55O5@O5D -1@5 JiNay Jerma #5BCD 1@55O55O11 -133 ,AB*. : -) ,)( /ame -r. (avi #ra9ash -r. Alo9 Mittal -r. Ar%n !%mar -r. Ar%na

5 5

-;/o -1@5 -B@C -1@5 -133

SpecialiPation ardiologist )rthopedic hild Specialist 'ynecologist

#;/o #@@@5 #@@51 #5@@1 #5BCD

(#)

write Mysql query (s) to modi y primary key constraint which is currently applied on D_No attribute in doctor table &a ter modi ication Name and Specialization attributes shall jointly act as Primary key or the Doctor !able

(##)

alter table doctor drop primary key" alter table doctor add primary key(name# specialization)" $rite MySql query to Print the Patient Name and Name
attendin% these patients Select doctor&name#patient&name patient&p_no'doctor&p_no"

Doctors

rom patient# doctor where Q C H 3

(###)

$rite the output produced by the ollowin% queries %) Select (en%th(Mid()*n ormatics Practices+#,,))" ,, h) Select pow(*nstr()Delhi Public School -haziabad+#)My School+)#6)" , i) Select .ound (/012&34/ # 54)" 0666 j) Select Dayname(curdate())" 77 assume that query is e8ecuted today monday k) Select month()36,3,3,3+)" ,3 l) Select lcase(mid()my school id DPS- +#5/))" dps%

Das könnte Ihnen auch gefallen