Você está na página 1de 11

What is normalization? Explain different levels of normalization?

Check out the article Q100139 from Microsoft knoled!e "ase and of course# there$s much
more information availa"le in the net% &t$ll "e a !ood idea to !et a hold of an' ()*M+
fundamentals text "ook#especiall' the one "' C% ,% )ate% Most of the times# it ill "e oka'
if 'ou can explain till third normal form%
What is denormalization and hen ould 'ou !o for it?
-s the name indicates# denormalization is the reverse process of normalization% &t$s the
controlled introduction of redundanc' in to the data"ase desi!n% &t helps improve the .uer'
performance as the num"er of /oins could "e reduced%
0o do 'ou implement one1to1one# one1to1man' and man'1to1man' relationships hile
desi!nin! ta"les?
2ne1to12ne relationship can "e implemented as a sin!le ta"le and rarel' as to ta"les ith
primar' and forei!n ke' relationships%2ne1to1Man' relationships are implemented "'
splittin! the data into to ta"les ith primar' ke' and forei!n ke' relationships%
Man'1to1Man' relationships are implemented usin! a /unction ta"le ith the ke's from "oth
the ta"les formin! the composite primar' ke' of the /unction ta"le% &t ill "e a !ood idea to
read up a data"ase desi!nin! fundamentals text "ook%
What$s the difference "eteen a primar' ke' and a uni.ue ke'?
*oth primar' ke' and uni.ue enforce uni.ueness of the column on hich the' are defined%
*ut "' default primar' ke' creates a clustered index on the column# here are uni.ue
creates a nonclustered index "' default% -nother ma/or difference is that# primar' ke'
doesn$t allo 3455s# "ut uni.ue ke' allos one 3455 onl'%
What are user defined datat'pes and hen 'ou should !o for them?
4ser defined datat'pes let 'ou extend the "ase +Q5 +erver datat'pes "' providin! a
descriptive name# and format to the data"ase% 6ake for example# in 'our data"ase# there is
a column called 7li!ht83um hich appears in man' ta"les% &n all these ta"les it should "e
varchar9:;% &n this case 'ou could create a user defined datat'pe called 7li!ht8num8t'pe of
varchar9:; and use it across all 'our ta"les%
What is "it datat'pe and hat$s the information that can "e stored inside a "it column?
*it datat'pe is used to store "oolean information like 1 or 0 9true or false;% 4ntill +Q5
+erver <%= "it datat'pe could hold either a 1 or 0 and there as no support for 3455% *ut
from +Q5 +erver >%0 onards# "it datat'pe can represent a third state# hich is 3455%
)efine candidate ke'# alternate ke'# composite ke'%
- candidate ke' is one that can identif' each ro of a ta"le uni.uel'%
?enerall' a candidate ke' "ecomes the primar' ke' of the ta"le% &f the
ta"le has more than one candidate ke'# one of them ill "ecome the
primar' ke'# and the rest are called alternate ke's% - ke' formed "' com"inin! at least to
or more columns is called composite ke'%
What are defaults? &s there a column to hich a default can$t "e "ound?
- default is a value that ill "e used "' a column# if no value is supplied to that column
hile insertin! data% &)E36&6@ columns and timestamp columns can$t have defaults "ound
to them% +ee C(E-6E )E74-56 in "ooks online%
What is a transaction and hat are -C&) properties?
- transaction is a lo!ical unit of ork in hich# all the steps must "e performed or none%
-C&) stands for -tomicit'# Consistenc'# &solation# )ura"ilit'% 6hese are the properties of a
transaction% 7or more information and explanation of these properties# see +Q5 +erver
"ooks online or an' ()*M+ fundamentals text "ook%
Explain different isolation levels
An isolation level determines the degree of isolation of data between concurrent transactions. The default
SQL Server isolation level is Read Committed. Here are the other isolation levels (in the ascending
order of isolation) Read !ncommitted" Read Committed" Re#eatable Read" Seriali$able. See SQL Server
boo%s online for an e&#lanation of the isolation levels. 'e sure to read about S(T TRA)SACT*+)
*S+LAT*+) L(,(L" which lets -ou customi$e the isolation level at the connection level.
C(E-6E &3)EA m'&ndex 23 m'6a"le9m'Column;
What t'pe of &ndex ill !et created after executin! the a"ove statement?
3on1clustered index% &mportant thin! to noteB *' default a clustered index !ets created on
the primar' ke'# unless specified otherise%
What$s the maximum size of a ro?
:0<0 "'tes% )on$t "e surprised ith .uestions like $hat is the maximum num"er of
columns per ta"le$% Check out +Q5 +erver "ooks online for the pa!e titledB CMaximum
Capacit' +pecificationsC% Explain -ctiveD-ctive and -ctiveDEassive cluster confi!urations
0opefull' 'ou have experience settin! up cluster servers% *ut if 'ou don$t# at least "e
familiar ith the a' clusterin! orks and the to clusternin! confi!urations -ctiveD-ctive
and -ctiveDEassive% +Q5 +erver "ooks online has enou!h information on this topic and there
is a !ood hite paper availa"le on Microsoft site%
Explain the architecture of +Q5 +erver
6his is a ver' important .uestion and 'ou "etter "e a"le to anser it if consider 'ourself a
)*-% +Q5 +erver "ooks online is the "est place to read a"out +Q5 +erver architecture% (ead
up the chapter dedicated to +Q5 +erver -rchitecture%
What is lock escalation?
5ock escalation is the process of convertin! a lot of lo level locks 9like ro locks# pa!e
locks; into hi!her level locks 9like ta"le locks;% Ever' lock is a memor' structure too man'
locks ould mean# more memor' "ein! occupied "' locks% 6o prevent this from happenin!#
+Q5 +erver escalates the man' fine1!rain locks to feer coarse1!rain locks% 5ock escalation
threshold as defina"le in +Q5 +erver <%=# "ut from +Q5 +erver >%0 onards it$s
d'namicall' mana!ed "' +Q5 +erver%
What$s the difference "eteen )E5E6E 6-*5E and 6(43C-6E 6-*5E commands?
)E5E6E 6-*5E is a lo!!ed operation# so the deletion of each ro !ets lo!!ed in the
transaction lo!# hich makes it slo% 6(43C-6E 6-*5E also deletes all the ros in a ta"le#
"ut it on$t lo! the deletion of each ro# instead it lo!s the deallocation of the data pa!es
of the ta"le# hich makes it faster% 2f course# 6(43C-6E 6-*5E can "e rolled
"ack%
Explain the stora!e models of 25-E
Check out M25-E# (25-E and 025-E in +Q5 +erver "ooks online for more infomation%
What are the ne features introduced in +Q5 +erver F000 9or the latest release of +Q5
+erver at the time of 'our intervie;? What chan!ed
"eteen the previous version of +Q5 +erver and the current version?
6his .uestion is !enerall' asked to see ho current is 'our knoled!e% ?enerall' there is a
section in the "e!innin! of the "ooks online titled CWhat$s 3eC# hich has all such
information% 2f course# readin! /ust that is not enou!h# 'ou should have tried those thin!s
to "etter anser the .uestions% -lso check out the section titled
C*ackard Compati"ilit'C in "ooks online hich talks a"out the chan!es
that have taken place in the ne version%
What are constraints? Explain different t'pes of constraints%
Constraints ena"le the ()*M+ enforce the inte!rit' of the data"ase automaticall'# ithout
needin! 'ou to create tri!!ers# rule or defaults%
6'pes of constraintsB 326 3455# C0ECG# 43&Q4E# E(&M-(@ GE@# 72(E&?3 GE@
7or an explanation of these constraints see "ooks online for the pa!es
titledB CConstraintsC and CC(E-6E 6-*5EC# C-56E( 6-*5EC
Whar is an index? What are the t'pes of indexes? 0o man' clustered indexes can "e
created on a ta"le? & create a separate index on each column of a ta"le% hat are the
advanta!es and disadvanta!es of this approach?
&ndexes in +Q5 +erver are similar to the indexes in "ooks% 6he' help +Q5 +erver retrieve
the data .uicker%
*nde&es are of two t-#es. Clustered inde&es and non.clustered inde&es. /hen -ou craete a clustered inde&
on a table" all the rows in the table are stored in the order of the clustered inde& %e-. So" there
can be onl- one clustered inde& #er table. )on.clustered inde&es have their own storage se#arate from the
table data storage. )on.clustered inde&es are stored as '.tree structures (so do clustered inde&es)"
with the leaf level nodes having the inde& %e- and it0s row locater. The row located could be the R*1 or
the Clustered inde& %e-" de#ending
up on the a"sence or presence of clustered index on the ta"le%
&f 'ou create an index on each column of a ta"le# it improves the .uer' performance# as the
.uer' optimizer can choose from all the existin! indexes to come up ith an efficient
execution plan% -t the same t ime# data modification operations 9such as &3+E(6# 4E)-6E#
)E5E6E; ill "ecome slo# as ever' time data chan!es in the ta"le# all the indexes need to
"e updated% -nother disadvanta!e is that# indexes need disk space# the more indexes 'ou
have# more disk space is used%
What is (-&) and hat are different t'pes of (-&) confi!urations?
(-&) stands for (edundant -rra' of &nexpensive )isks# used to provide fault tolerance to
data"ase servers% 6here are six (-&) levels 0 throu!h = offerin! different levels of
performance# fault tolerance% M+)3 has some information a"out (-&) levels and for
detailed information# check out the (-&) advisor' "oard$s homepa!e
What are the steps 'ou ill take to improve performance of a poor
performin! .uer'?
6his is a ver' open ended .uestion and there could "e a lot of reasons "ehind the poor
performance of a .uer'% *ut some !eneral issues that 'ou could talk a"out ould "eB 3o
indexes# ta"le scans# missin! or out of date statistics# "lockin!# excess recompilations of
stored procedures# procedures and tri!!ers ithout +E6 32C2436 23# poorl'
ritten .uer' ith unnecessaril' complicated /oins# too much normalization# excess usa!e
of cursors and temporar' ta"les%
+ome of the toolsDa's that help 'ou trou"leshootin! performance
pro"lems areB +E6 +02WE5-38-55 23# +E6 +02WE5-386EA6 23# +E6
+6-6&+6&C+ &2 23# +Q5 +erver Erofiler# Windos 36 DF000 Eerformance
monitor# ?raphical execution plan in Quer' -nal'zer%
What are the steps 'ou ill take# if 'ou are tasked ith securin! an
+Q5 +erver?
-!ain this is another open ended .uestion% 0ere are some thin!s 'ou could talk a"outB
Ereferrin! 36 authentication# usin! server# data"se and application roles to control access to
the data# securin! the ph'sical data"ase files usin! 367+ permissions# usin! an
un!uessa"le +- passord# restrictin! ph'sical access to the +Q5 +erver# renamin!
the -dministrator account on the +Q5 +erver computer# disa"lin! the ?uest account#
ena"lin! auditin!# usin! multiprotocol encr'ption# settin! up ++5# settin! up firealls#
isolatin! +Q5 +erver from the e" server etc%
What is a deadlock and hat is a live lock? 0o ill 'ou !o a"out resolvin! deadlocks?
)eadlock is a situation hen to processes# each havin! a lock on one piece of data#
attempt to ac.uire a lock on the other$s piece% Each process ould ait indefinitel' for the
other to release the lock# unless one of the user processes is terminated% +Q5 +erver
detects deadlocks and terminates one user$s process%
- livelock is one# here a re.uest for an exclusive lock is repeatedl' denied "ecause a
series of overlappin! shared locks keeps interferin!% +Q5 +erver detects the situation after
four denials and refuses further shared locks% - livelock also occurs hen read transactions
monopolize a ta"le or pa!e# forcin! a rite transaction to ait indefinitel'%
Check out +E6 )E-)52CG8E(&2(&6@ and CMinimizin! )eadlocksC in +Q5 +erver "ooks
online% -lso check out the article Q1<99<0 from Microsoft knoled!e "ase%
What is "lockin! and ho ould 'ou trou"leshoot it?
*lockin! happens hen one connection from an application holds a lock
and a second connection re.uires a conflictin! lock t'pe% 6his forces
the second connection to ait# "locked on the first%
(ead up the folloin! topics in +Q5 +erver "ooks onlineB 4nderstandin!
and avoidin! "lockin!# Codin! efficient transactions%
Explain C(E-6E )-6-*-+E s'ntax
Man' of us are used to craetin! data"ases from the Enterprise Mana!er
or "' /ust issuin! the commandB C(E-6E )-6-*-E M')*% *ut hat if 'ou
have to create a data"ase ith to file!roups# one on drive C and the
other on drive ) ith lo! on drive E ith an initial size of <00 M*
and ith a !roth factor of 1=H? 6hat$s h' "ein! a )*- 'ou should "e
familiar ith the C(E-6E )-6-*-+E s'ntax% Check out +Q5 +erver "ooks
online for more information%
0o to restart +Q5 +erver in sin!le user mode? 0o to start +Q5 +erver
in minimal confi!uration mode?
+Q5 +erver can "e started from command line# usin! the +Q5+E(I(%EAE%
6his EAE has some ver' important parameters ith hich a )*- should "e
familiar ith% 1m is used for startin! +Q5 +erver in sin!le user mode
and 1f is used to start the +Q5 +erver in minimal confu!uration mode%
Check out +Q5 +erver "ooks online for more parameters and their
explanations%
-s a part of 'our /o"# hat are the )*CC commands that 'ou commonl'
use for data"ase maintenance?
)*CC C0ECG)*# )*CC C0ECG6-*5E# )*CC C0ECGC-6-52?# )*CC C0ECG-552C#
)*CC +02WC236&?# )*CC +0(&3G)-6-*-+E# )*CC +0(&3G7&5E etc% *ut there
are a hole load of )*CC commands hich are ver' useful for )*-s%
Check out +Q5 +erver "ooks online for more information%
What are statistics# under hat circumstances the' !o out of date# ho
do 'ou update them?
+tatistics determine the selectivit' of the indexes% &f an indexed
column has uni.ue values then the selectivit' of that index is more#
as opposed to an index ith non1uni.ue values% Quer' optimizer uses
these indexes in determinin! hether to choose an index or not hile
executin! a .uer'%
+ome situations under hich 'ou should update statisticsB
1; &f there is si!nificant chan!e in the ke' values in the index
F; &f a lar!e amount of data in an indexed column has "een added#
chan!ed# or removed 9that is# if the distri"ution of ke' values has
chan!ed;# or the ta"le has "een truncated usin! the 6(43C-6E 6-*5E
statement and then repopulated
3; )ata"ase is up!raded from a previous version
5ook up +Q5 +erver "ooks online for the folloin! commandsB 4E)-6E
+6-6&+6&C+# +6-6+8)-6E# )*CC +02W8+6-6&+6&C+# C(E-6E +6-6&+6&C+# )(2E
+6-6&+6&C+# sp8autostats# sp8createstats# sp8updatestats
What are the different a's of movin! dataDdata"ases "eteen servers
and data"ases in +Q5 +erver?
6here are lots of options availa"le# 'ou have to choose 'our option
dependin! upon 'our re.uirements% +ome of the options 'ou have areB
*-CG4ED(E+62(E# dettachin! and attachin! data"ases# replication# )6+#
*CE# lo!shippin!# &3+E(6%%%+E5EC6# +E5EC6%%%&362# creatin! &3+E(6
scripts to !enerate data%
Explian different t'pes of *-CG4Es avaiala"e in +Q5 +erver? ?iven a
particular scenario# ho ould 'ou !o a"out choosin! a "ackup plan?
6'pes of "ackups 'ou can create in +Q5 +ever >%0J are 7ull data"ase
"ackup# differential data"ase "ackup# transaction lo! "ackup#
file!roup "ackup% Check out the *-CG4E and (E+62(E commands in +Q5
+erver "ooks online% *e prepared to rite the commands in 'our
intervie% *ooks online also has information on detailed
"ackupDrestore architecture and hen one should !o for a particular
kind of "ackup%
What is data"ase replicaion? What are the different t'pes of
replication 'ou can set up in +Q5 +erver?
(eplication is the process of cop'in!Dmovin! data "eteen data"ases on
the same or different servers% +Q5 +erver supports the folloin! t'pes
of replication scenariosB
K +napshot replication
K 6ransactional replication 9ith immediate updatin! su"scri"ers#
ith .ueued updatin! su"scri"ers;
K Mer!e replication
+ee +Q5 +erver "ooks online for indepth covera!e on replication% *e
prepared to explain ho different replication a!ents function# hat
are the main s'stem ta"les used in replication etc%
0o to determine the service pack currentl' installed on +Q5 +erver?
6he !lo"al varia"le LLIersion stores the "uild num"er of the
s.lservr%exe# hich is used to determine the service pack installed%
6o kno more a"out this process visit +Q5 +erver service packs and
versions%
*ack to top
)ata"ase pro!rammin! 9top;
What are cursors? Explain different t'pes of cursors% What are the
disadvanta!es of cursors? 0o can 'ou avoid cursors?
Cursors allo ro1"'1ro prcessin! of the resultsets%
6'pes of cursorsB +tatic# )'namic# 7orard1onl'# Ge'set1driven% +ee
"ooks online for more information%
)isadvanta!es of cursorsB Each time 'ou fetch a ro from the cursor#
it results in a netork roundtrip# here as a normal +E5EC6 .uer'
makes onl' one roundtrip# hoever lar!e the resultset is% Cursors are
also costl' "ecause the' re.uire more resources and temporar' stora!e
9results in more &2 operations;% 7urthere# there are restrictions on
the +E5EC6 statements that can "e used ith some t'pes of cursors%
Most of the times# set "ased operations can "e used instead of
cursors% 0ere is an exampleB
&f 'ou have to !ive a flat hike to 'our emplo'ees usin! the folloin!
criteriaB
+alar' "eteen 30000 and M0000 11 =000 hike
+alar' "eteen M0000 and ==000 11 >000 hike
+alar' "eteen ==000 and <=000 11 9000 hike
&n this situation man' developers tend to use a cursor# determine each
emplo'ee$s salar' and update his salar' accordin! to the a"ove
formula% *ut the same can "e achieved "' multiple update statements or
can "e com"ined in a sin!le 4E)-6E statement as shon "eloB
4E)-6E t"l8emp +E6 salar' N
C-+E W0E3 salar' *E6WEE3 30000 -3) M0000 60E3 salar' J =000
W0E3 salar' *E6WEE3 M0000 -3) ==000 60E3 salar' J >000
W0E3 salar' *E6WEE3 ==000 -3) <=000 60E3 salar' J 10000
E3)
-nother situation in hich developers tend to use cursorsB @ou need to
call a stored procedure hen a column in a particular ro meets
certain condition% @ou don$t have to use cursors for this% 6his can "e
achieved usin! W0&5E loop# as lon! as there is a uni.ue ke' to
identif' each ro% 7or examples of usin! W0&5E loop for ro "' ro
processin!# check out the $M' code li"rar'$ section of m' site or
search for W0&5E%
Write don the !eneral s'ntax for a +E5EC6 statements coverin! all the
options%
0ere$s the "asic s'ntaxB 9-lso checkout +E5EC6 in "ooks online for
advanced s'ntax;%
+E5EC6 select8list
O&362 ne8ta"le8P
7(2M ta"le8source
OW0E(E search8conditionP
O?(24E *@ !roup8"'88expressionP
O0-I&3? search8conditionP
O2()E( *@ order88expression O-+C Q )E+CP P
What is a /oin and explain different t'pes of /oins%
,oins are used in .ueries to explain ho different ta"les are related%
,oins also let 'ou select data from a ta"le dependin! upon data from
another ta"le%
6'pes of /oinsB &33E( ,2&3s# 246E( ,2&3s# C(2++ ,2&3s% 246E( ,2&3s are
further classified as 5E76 246E( ,2&3+# (&?06 246E( ,2&3+ and 7455
246E( ,2&3+%
7or more information see pa!es from "ooks online titledB C,oin
7undamentalsC and C4sin! ,oinsC%
Can 'ou have a nested transaction?
@es# ver' much% Check out *E?&3 6(-3# C2MM&6# (255*-CG# +-IE 6(-3 and
LL6(-3C2436
What is an extended stored procedure? Can 'ou instantiate a C2M o"/ect
"' usin! 61+Q5?
-n extended stored procedure is a function ithin a )55 9ritten in a
pro!rammin! lan!ua!e like C# CJJ usin! 2pen )ata +ervices 92)+; -E&;
that can "e called from 61+Q5# /ust the a' e call normal stored
procedures usin! the EAEC statement% +ee "ooks online to learn ho to
create extended stored procedures and ho to add them to +Q5 +erver%
@es# 'ou can instantiate a C2M 9ritten in lan!ua!es like I*# ICJJ;
o"/ect from 61+Q5 "' usin! sp82-Create stored procedure% -lso see
"ooks online for sp82-Method# sp82-?etEropert'# sp82-+etEropert'#
sp82-)estro'% 7or an example of creatin! a C2M o"/ect in I* and
callin! it from 61+Q5# see $M' code li"rar'$ section of this site%
What is the s'stem function to !et the current user$s user id?
!S(R2*1(). Also chec% out other s-stem functions li%e !S(R2)A3(()"
S4ST(32!S(R" S(SS*+)2!S(R" C!RR()T2!S(R" !S(R" S!S(R2S*1()"
02+683-ME9;%
What are tri!!ers? 0o man' tri!!ers 'ou can have on a ta"le? 0o to
invoke a tri!!er on demand?
6ri!!ers are special kind of stored procedures that !et executed
automaticall' hen an &3+E(6# 4E)-6E or )E5E6E operation takes place
on a ta"le%
&n +Q5 +erver <%= 'ou could define onl' 3 tri!!ers per ta"le# one for
&3+E(6# one for 4E)-6E and one for )E5E6E% 7rom +Q5 +erver >%0
onards# this restriction is !one# and 'ou could create multiple
tri!!ers per each action% *ut in >%0 there$s no a' to control the
order in hich the tri!!ers fire% &n +Q5 +erver F000 'ou could specif'
hich tri!!er fires first or fires last usin! sp8settri!!erorder
6ri!!ers can$t "e invoked on demand% 6he' !et tri!!ered onl' hen an
associated action 9&3+E(6# 4E)-6E# )E5E6E; happens on the ta"le on
hich the' are defined%
6ri!!ers are !enerall' used to implement "usiness rules# auditin!%
6ri!!ers can also "e used to extend the referential inte!rit' checks#
"ut herever possi"le# use constraints for this purpose# instead of
tri!!ers# as constraints are much faster%
6ill +Q5 +erver >%0# tri!!ers fire onl' after the data modification
operation happens% +o in a a'# the' are called post tri!!ers% *ut in
+Q5 +erver F000 'ou could create pre tri!!ers also% +earch +Q5 +erver
F000 "ooks online for &3+6E-) 27 tri!!ers%
-lso check out "ooks online for $inserted ta"le$# $deleted ta"le$ and
C254M3+84E)-6E)9;
6here is a tri!!er defined for &3+E(6 operations on a ta"le# in an
256E s'stem% 6he tri!!er is ritten to instantiate a C2M o"/ect and
pass the nel' insterted ros to it for some custom processin!% What
do 'ou think of this implementation? Can this "e implemented "etter?
&nstantiatin! C2M o"/ects is a time consumin! process and since 'ou
are doin! it from ithin a tri!!er# it slos don the data insertion
process% +ame is the case ith sendin! emails from tri!!ers% 6his
scenario can "e "etter implemented "' lo!!in! all the necessar' data
into a separate ta"le# and have a /o" hich periodicall' checks this
ta"le and does the needful%
What is a self /oin? Explain it ith an example%
+elf /oin is /ust like an' other /oin# except that to instances of
the same ta"le ill "e /oined in the .uer'% 0ere is an exampleB
Emplo'ees ta"le hich contains ros for normal emplo'ees as ell as
mana!ers% +o# to find out the mana!ers of all the emplo'ees# 'ou need
a self /oin%
C(E-6E 6-*5E emp
9empid int#m!rid int#empname char910;;
&3+E(6 emp +E5EC6 1#F#$I'as$
&3+E(6 emp +E5EC6 F#3#$Mohan$
&3+E(6 emp +E5EC6 3#3455#$+ho"ha$
&3+E(6 emp +E5EC6 M#F#$+hridhar$
&3+E(6 emp +E5EC6 =#F#$+oura"h$
+E5EC6 t1%empname OEmplo'eeP# tF%empname OMana!erP
7(2M emp t1# emp tF
W0E(E t1%m!rid N tF%empid
0ere$s an advanced .uer' usin! a 5E76 246E( ,2&3 that even returns the
emplo'ees ithout mana!ers 9super "osses;
S(L(CT t5.em#name 6(m#lo-ee7" C+AL(SC((t8.em#name" 0)o manager0) 63anager7
9R+3 em# t5
L(9T +!T(R :+*)
em# t8
+)
t5.mgrid ; t8.em#id

Você também pode gostar