You are on page 1of 30

SQL SERVER INTERVIEW QUESTIONS

1. What is RDMS ?
2. What is SQL ?
3. DML & DDL ?
4. TOP clause ?
5. DISTINCT e!"#$% ?
&. IN #'e$at#$ ?
(. )lias ?
*. W+,R, a-% +).IN/ clause ?
0. D,L,T, a-% TR1NC)T, ?
12. 3OIN ?
11. Di44e$e-ce 5et"ee- 1NION a-% 1NION )LL ?
12. )66$e6ate 7u-cti#-s ?
13. What is N#$8ali9ati#- ?
14. What is De:N#$8ali9ati#- ?
15. What is Cu$s#$ ?
1&. What is I-%e; ?
1(. What is T$i66e$ ?
1*. Di44e$e-ce 5et"ee- a P$i8a$! e! a-% a 1-i<ue e! ?
10. 7#$ei6- e! ?
22. De4i-e Ca-%i%ate =e!> )lte$-ate =e!> C#8'#site =e!> Su'e$ =e! ?
21. St#$e P$#ce%u$e ?
22. 1se$ De4i-e% 7u-cti#-s ?
23. Di44e$e-ce 5et"ee- St#$e P$#ce%u$e ?SP@ a-% 1se$ De4i-e% 7u-cti#- ?1D7@ ?
24. What is .ie" ?
25. )LT,R T)AL, C#88a-% ?
2&. What is C#llati#- ?
2(. What is the 'u$'#se #4 Re'licati#- ?
2*. What is I%e-tit! ?
20. )uthe-ticati#- 8#%es i- SQL ?
32. C#88a-% usi-6 Que$! )-al!9e$ "ill 6iBe !#u the Be$si#- #4 SQL Se$Be$ a-% OS ?
31. L#6 Shi''i-6 ?
32. Di44e$e-ce 5et"ee- L#cal a-% /l#5al te8'#$a$! ta5le ?
33. Di44e$e-ce 5et"ee- ST177 4u-cti#- a-% R,PL)C, 4u-cti#- ?
34. C+,C= C#-st$ai-ts ?
35. NOT N1LL C#-st$ai-ts ?
3&. AulC#'! ?ACP@ a-% A1L= INS,RT ?
3(. What is c#88a-% use% 4#$ $e-a8e a %5> a ta5le a-% a c#lu8- ?
3*. 1PD)T,CST)TISTICS C#88a-% ?
30. +#" ca- !#u $aise cust#8 e$$#$s 4$#8 st#$e% '$#ce%u$e ?
42. What a$e %i44e$e-t t$a-sacti#- leBels i- SQL S,R.,R ?
41. I4 l#ci-6 is -#t i8'le8e-te% "hat issues ca- #ccu$ ?
What are GRANT and REVOKE statements ?
How many Types of Relationship Exist in Database Designing ?
How we can check the database permission for any user ?
43. What is the use #4 )PPCNa8e?@ ?
44. What is the use #4 C+)R 4u-cti#- ?
45. What a$e Ba$i#us l#c t!'es ?
4&. What is the use #4 MOD 4u-cti#- ?
Which function is used to know the current active user within the host Operating System?
40. +#" t# -#" the ID #4 a %ata5ase ?
Which function is used to know the database name by giving the database ID ?
52. Wh! 7LOOR 4u-cti#- is use% ?
51. Which 4u-cti#- is use% t# c#-Be$t the i-te6e$ Balue i-t# s'aces ?
What is the use of CEILING function ?
55. How to get the Year part from the given Date ?
56. How to get the Day part from the given Date ?
57. How to get the month value/month part from the given Date ?
58. Adding Year or Minutes or Months or Hours to a date ?
59. What's the SQL query to restore a database from a backup file ?
60. How To know your SQL Server Version in SQL command prompt ?
61. Which system table contains information on constraints on all the tables created ?
62. What is the use of ROWCOUNT ?
63. What is a table variable in T-SQL ?
64. How do we List all table names ?
65. How do we list all Databases in a server using query ?
66. What is the Magic Tables in Sqlserver2000 ?
67. What is COMMIT and ROLLBACK statement in SQL ?
&*. What is the use #4 C#88a-%Auil%e$ ?
&0. What is a cu5e ?
70. What are the three levels of data abstraction ?
(1. What is DTS )-% ACP ?
72. How do we list all column names of a table ?
73. What is Query binding ?
74. Difference Between Implict Transaction And Explict Transaction ?
75. What's the maximum size of a row ?
(&. What a$e S'a$se C#lu8-s i- S<l Se$Be$222* ?
77. What is the Difference between SQL SERVER 2000 and 2005 ?
(*. What is a Dc#-st$ai-tD ?
79. Which TCPEIP '#$t %#es SQL Se$Be$ $u- #- ?
*2. What is 1se$:De4i-e% %atat!'es ?
*1. CON.,RT? @ 4u-cti#- ?
*2. C)S, e;'$essi#- a-% N1LLI7 ? @ ISN1LL ? @ ?
*3. What is R#uti-es ?
*4. Multi$elati#- Que$ies ?
*5. What is Qua-ti4ie$s ?
*&. )DO.N,T ?
What is RDMS ?

Relati#-al Data5ase Ma-a6e8e-t S!ste8 ?RDMS@ is a %ata 5ase 8a-a6e8e-t s!ste8 that st#$e
%ataFs i- ta5les. I- ta5le %ata st#$e% i- $#"s a-% c#lu8-s 4#$8at.
RDMS Properties
C#lu8- Balues a$e sa8e %ata t!'e.
,ach $#" is u-i<ue.
.alues a$e at#8ic.
,ach c#lu8- 8ust haBe a u-i<ue -a8e.
What is SQL ?
St$uctu$e% Que$! La-6ua6e ?SQL@ is la-6ua6e that e-a5les !#u t# "#$ "ith a %ata5ase. 1si-6
SQL !#u ca- i-se$t> u'%ate> a-% %elete $ec#$%s. G#u ca- als# c$eate %ata5ase a-% ta5les. )%Ba-ce%
4eatu$es a$e st#$e% '$#ce%u$es a-% Bie".
DML & DDL ?
SQL is %iBi%e% i-t# t"# 8ai- cate6#$iesH Data Ma-i'ulati#- La-6ua6e ?DML@> a-% Data De4i-iti#-
La-6ua6e ?DDL@. )- e;'la-ati#- 4#ll#"s.
Data Manipulation Language ?DML@ "#$s "ith %ata that 6#es i-t# the %ata5ase. DML is use%
t# I-se$t> Select> Delete a-% 1'%ate %ata. C#88a-%s use% i- DML a$eI
I-se$t
Select
Delete
1'%ate
Data Definition Language ?DDL@ is use% t# c$eate #$ %$#' ?%elete@ ta5les #$ #the$ %ata5ase
#5Jects. C#88a-%s use% i- DDL a$eI
CR,)T, D)T)A)S, : C$eates a -e" %ata5ase
)LT,R D)T)A)S, : M#%i4ies the %ata5ase
DROP D)T)A)S, : D$#'s ?%eletes@ a %ata5ase
CR,)T, T)AL, : C$eates a -e" ta5le
)LT,R T)AL, : M#%i4ies the ta5le
DROP T)AL, : D$#'s ?%eletes@ a ta5le
TR1NC)T, K Delete all $#"s 4$#8 ta5le
TOP Clause ?
The TOP clause all#"s us t# s'eci4! h#" 8a-! t#' $#"s t# $etu$-.
,;a8'le1I : S,L,CT TOP 3 L 7ROM ta5le1
Note: - Select top 3 rows from table1.
G#u haBe the #'ti#- #4 s'eci4!i-6 a 'e$ce-ta6e #4 the $esult set i-stea% #4 a- a5s#lute Balue. D#
"ith this P,RC,NT e!"#$%.
,;a8'le2I : S,L,CT TOP 40 PERCENT L 7ROM ta5le1
Note: - Select top 40 percentages of rows from table1.
,;a8'le3I : S,L,CT TOP 2 L 7ROM t5lSala$! ORD,R AG Sala$! D,SC
Note:- Select top 2 salaries from tblsalary
,;a8'le4I :S,L,CT TOP 1 L 7ROM t5lSala$! W+,R, Sala$! IN
?S,L,CT TOP 4 Sala$! 7ROM t5lSala$! ORD,R AG Sala$! D,SC@
ORD,R AG Sala$! )SC
Note: -Select minimm salary from !ig!est 4 salaries in tblsalary
DISTINCT keyword ?
DISTINCT e!"#$% is use% t# select u-i<ue Balues 4$#8 a ta5le
,;a8'leI : S,L,CT DISTINCT?7i$stNa8e@ 7ROM ta5le 1
IN operator ?
1si-6 IN #'e$at#$ "e ca- c#8'a$e #u$ Balue "ith a list #4 Balues i- W+,R, clause.

,;a8'leI : S,L,CT L 7ROM ta5le1 W+,R, C#l#u81 IN ?MBalue1F>FBalue2F>FBalue3F@

Alias ?
)lias is use% t# 6iBe #u$ #- -a8e 4#$ ta5les i- <ue$!.

,;a8'leI : S,L,CT L 7ROM ta5le1 AS A
Tuple variables as aliases #4 $elati#-s. SQL 'e$8its )S 5et"ee- $elati#- a-% its tu'le.
WHERE and HAVING clause ?
The! s'eci4! a sea$ch c#-%iti#- 4#$ a 6$#u' #$ a- a66$e6ate. +).IN/ clause is use% "ith
/RO1P AG 4u-cti#-. Whe- /RO1P AG is -#t use%> +).IN/ 5ehaBes lie a W+,R, clause.
+).IN/ is use% #-l! "ith S,L,CT state8e-t.
,;a8'leI : S,L,CT C#u-t?Sala$!@ 7ROM t5lSala$! /RO1P AG Sala$! +).IN/ Sala$!N25222
Note: - We ca- use +).N/ a-% W+,R, clause t#6ethe$.
,;a8'leI : S,L,CT S1M?Sala$!1@7ROM t5lSala$!1 W+,R, Sala$!1O12222 /RO1P AG Sala$!1
+).IN/ Sala$!1P52222
DELETE and TRUNCATE ?
TR1NC)T, %elete all $#"s 4$#8 a ta5le. TR1NC)T, is a DDL la-6ua6e. C#8'a$e% t#
D,L,T, its e;ecuti#- s'ee% is 4ast. W+,R, clause is -#t use% i- TR1NC)T, c#88a-%. TR1NC)T,
ca--#t use #- a ta5le that $e4e$e-ce% 5! 4#$ei6- e!. TR1NC)T, ca--#t 5e $#lle% 5ac. It ca--#t actiBate
a t$i66e$. We ca--#t use TR1NC)T, c#88a-% #- a ta5le "ith 7#$ei6- =e! 5ecause #4 $e4e$e-tial
i-te6$it!.
D,L,T, c#88a-% is use% t# %elete 'a$ticula$ $#"s 4$#8 ta5le 5ase% #- c#-%iti#-s.
D,L,T, is a DML la-6ua6e. D,L,T, #'e$ati#- ca- 5e $#lle% 5ac> 5ut TR1NC)T, #'e$ati#- ca--#t
5e $#lle% 5ac.
TR1NC)T, ta5le is 4aste$ as c#8'a$e% t# %elete ta5le.
D,L,T, ta5le ca- 5e $#lle% 5ac "hile TR1NC)T, ca--#t 5e.
D,L,T, ta5le ca- haBe c$ite$ia "hile TR1NC)T, ca--#t.
TR1NC)T, ta5le ca--#t haBe t$i66e$s
TR1NC)T, $eset i%e-tit! #4 the ta5le.
TR1NC)T, is 4aste$ a-% uses 4e"e$ s!ste8 a-% t$a-sacti#- l#6 $es#u$ces tha- D,L,T,.
1OIN ?
3OIN e!"#$% is use$ t# select %ata 4$#8 t"# ta5les. We haBe t# use 8ulti'le 3#i-Fs the-
select %ata 4$#8 8ulti'le ta5les.
"ypes of #$%N
INN,R 3OINI This "ill #-l! $etu$- $#"s "he- the$e is at least #-e $#" i- 5#th ta5les that 8atch
the J#i- c#-%iti#-.
L,7T O1T,R 3OIN ?#$ L,7T 3OIN@I This "ill $etu$- $#"s that haBe %ata i- the le4t ta5le ?le4t #4
the 3OIN e!"#$%@> eBe- i4 the$eQs -# 8atchi-6 $#"s i- the $i6ht ta5le.
RI/+T O1T,R 3OIN ?#$ RI/+T 3OIN@I This "ill $etu$- $#"s that haBe %ata i- the $i6ht ta5le
?$i6ht #4 the 3OIN e!"#$%@> eBe- i4 the$eQs -# 8atchi-6 $#"s i- the le4t ta5le.
71LL O1T,R 3OIN ?#$ 71LL 3OIN@I This "ill $etu$- all $#"s> as l#-6 as the$eQs 8atchi-6 %ata
i- #-e #4 the ta5les.
Sel4:3#i-I I4 !#u "a-t t# J#i-> t"# i-sta-ces #4 the sa8e ta5le !#u ca- use sel4:J#i-.
Difference between UNION and UNION ALL ?
UNION select DISTINCT %ataFs 4$#8 t"# ta5les. UNION ALL selects all %ataFs 4$#8 t"#
ta5les. I- UNION and UNION ALL all selecte% c#lu8-s -ee% t# 5e sa8e %ata t!'e. /iBe- the sa8e
-u85e$ #4 c#lu8-s a-% c#8'ati5le %atat!'es.
,;a8'le1I : S,L,CT e8'I% 7ROM t5l,8'Na8e
1NION
S,L,CT e8'i% 7ROM t5lSala$!
,;a8'le2I : S,L,CT e8'i% 7ROM t5lSala$!
1NION )LL
S,L,CT e8'I% 7ROM t5l,8'Na8e
Aggregate Functions ?
)66$e6ate 4u-cti#-s 'e$4#$8 a calculati#- #- a set #4 Balues a-% $etu$- a si-6le Balue.
S#8e #4 )66$e6ate 4u-cti#-s a$eI : )./> S1M> MIN> M)R> CO1NT> a-% C+,C=S1M.
What is Normalization ?
N#$8ali9ati#- 8i-i8i9e $e%u-%a-c! #4 %ata i- %ata5ase. N#$8ali9ati#- %iBi%es a %ata5ase i-t#
t"# #$ 8#$e ta5le a-% %e4i-i-6 $elati#-shi's 5et"ee- the ta5les.
1
st
NFI : ,li8i-ate Re'eati-6 /$#u's
Mae a se'a$ate ta5le 4#$ each set #4 $elate% att$i5utes. )-% set '$i8a$! e! 4#$ each ta5le.
2
nd
NFI : ,li8i-ate Re%u-%a-t %ata
)tt$i5utes #-l! the 'a$t #4 8ulti:Balue% e!> $e8#Be it t# a se'a$ate e!
3
rd
NFI : ,li8i-ate c#lu8- that -#t %e'e-%e-t #- P$i8a$! e!
M#Be the att$i5utes t# se'a$ate ta5le that -#t %e'e-%e-t #- the '$i8a$! e!.
What is De-Normalization ?

De:N#$8ali9ati#- is the Bice:Be$sa #4 -#$8ali9ati#-. It i8'$#Bes the 'e$4#$8a-ce. It i-c$eases
the $e%u-%a-c! #4 %ata i- %ata5ase.
What is Cursor ?
Cu$s#$ is a %ata5ase #5Ject use% t# 8a-i'ulate %ata i- a set #- a $#":5!:$#" 5asis. I- t!'ical
SQL c#88a-% #'e$ate the e-ti$e $#" i- a %ata set at #-e ti8e. I4 "e haBe %u'licate $ec#$%s i- a ta5le "e
ca- $e8#Be it 5! %ecla$i-6 a cu$s#$ "hich "#ul% chec the $ec#$%s %u$i-6 $et$ieBal #-e 5! #-e a-%
$e8#Be $#"s "hich haBe %u'licate Balues.
&rsor performs in following steps: -
Decla$e cu$s#$
O'e- cu$s#$
7etch $#" 4$#8 cu$s#$
P$#cess 4etch $#"
Cl#se cu$s#$
Deall#cate cu$s#$

,;a8'leI : D,CL)R, ,8'l#!eeCCu$s#$ C1RSOR 7OR
S,L,CT LastNa8e> 7i$stNa8e 7ROM N#$th"i-%.%5#.,8'l#!ees
OP,N ,8'l#!eeCCu$s#$
7,TC+ N,RT 7ROM ,8'l#!eeCCu$s#$
W+IL, SS7,TC+CST)T1S N 2
A,/IN
7,TC+ N,RT 7ROM ,8'l#!eeCCu$s#$
,ND
CLOS, ,8'l#!eeCCu$s#$
D,)LLOC)T, ,8'l#!eeCCu$s#$
What is Index ?
I-%e; is a 'h!sical st$uctu$e that c#-tai-s '#i-te$s t# %ata. I-%ices a$e c$eate% i- e;isti-6 ta5le
t# l#cate $#"s 8#$e <uicl! a-% e44icie-tl!. It is '#ssi5le t# c$eate a- i-%e; #- #-e #$ 8#$e c#lu8-s #4 a
ta5le a-% each i-%e; is 6iBe- a -a8e. The use$ ca--#t see i-%e;. The! s'ee% u' S,L,CT <ue$ies. )t the
sa8e ti8e %ata 8#%i4icati#- #'e$ati#- ?INS,RT> 1PD)T,> a-% D,L,T,@ "ill 5ec#8e sl#". Nee% 8#$e
%is s'ace.
) %ata5ase i-%e; is #$6a-i9e% i- a A:t$ee st$uctu$e. ,ach 'a6e i- a- i-%e; is calle% a- i-%e; 'a6e #$ a-
i-%e; -#%e. The i-%e; st$uctu$e 5e6i-s "ith a $##t -#%e at the t#' leBel. The root no'e 8a$s the
5e6i--i-6 #4 the i-%e;H it is the 4i$st %ata accesse% "he- a %ata l##u' #ccu$s. The $##t -#%e c#-tai-s a
-u85e$ #4 i-%e; $#"s. These i-%e; $#"s c#-tai- a e! Balue a-% a '#i-te$ t# a- i-%e; 'a6e ?calle% a
5$a-ch -#%e@
&reate %n'e( Synta(

a@ CR,)T, IND,R i-%e;C-a8e
ON ta5leC-a8e ?c#lu8-C-a8e@
5@ CR,)T, T1NIQ1,U TCL1ST,R,D V NONCL1ST,R,DU IND,R in'e()name
ON table)name ?colmn)name T)SC V D,SCUT>...-U@
Example :
CR,)T, CL1ST,R,D IND,R -a8eCsala$!Ci-%;
ON e8'l#!ees ?last-a8e> sala$! D,SC@
I-%e;es a$e #4 t"# t!'es.
Cluste$e% i-%e;es.
N#-:cluste$e% i-%e;es.

Whe- "e c$eate Cluste$e% I-%e; #- a ta5le> all the $#"s st#$e% i- the ta5le a$e st#$e% i- the
#$%e$ #4 Cluste$e% i-%e; e!. We c$eate #-l! #-e Cluste$e% i-%e; i- a ta5le. ) cluste$e% i-%e; st#$es the
actual $#"s #4 %ata i- its lea4 -#%es> i- s#$te% #$%e$. Aecause the %ata i- a cluste$e% i-%e; is st#$e% i- the
lea4 -#%es> #-ce the lea4 -#%e is $eache%> the %ata is aBaila5le. P$i8a$! e! is a Cluste$e% i-%e;. Cluste$e%
i-%e;es a$e 6##% 4#$ $a-6e sea$ches. Aecause the actual %ata is st#$e% i- the cluste$e% i-%e;> !#u ca--#t
c$eate 8#$e tha- #-e cluste$e% i-%e; #- a ta5le.
N#-:Cluste$e% i-%e; the lea4 -#%e c#-tai-s the '#i-te$ ?ROW ID@ t# the actual %ata i- $#"s.
S# "e ca- c$eate 8#$e tha- #-e N#-:cluste$e% i-%e; i- a ta5le. 1-i<ue e! is N#-:Cluste$e% i-%e;. N#-:
cluste$e% i-%e;es a$e 6##% 4#$ $a-%#8 sea$ches.
I- SQL 2225 a-% ea$lie$ the$e "as a li8itati#- #4 252 i-%e;es 'e$ ta5le> #-e cluste$e% a-%
240 -#-:cluste$e%. I- SQL 222*> "ith the a%%iti#- #4 4ilte$e% i-%e;es> that li8itati#- "as i-c$ease% t#
1222> #-e cluste$e% a-% 000 -#-:cluste$e% i-%e;es.
How to use hints in order to specif which index to use!
Example:
S,L,CT L
7ROM Cust#8e$s WIT+ ?IND,R?Re6i#-@@
W+,R, $e6i#- N QORQ )ND cit! N QP#$tla-%Q
Note: - MIND,RF is e!"#$% a-% MRe6i#-F is i-%e;-a8e
What is Trigger ?
T$i66e$s a$e 5asicall! use% t# i8'le8e-t 5usi-ess $ules. T$i66e$ is a SQL '$#ce%u$e that
i-itiates a- acti#- "he- a- eBe-t ?INS,RT> D,L,T, #$ 1PD)T,@ #ccu$s. T$i66e$s a$e st#$e% a-%
8a-a6e% 5! DAMS. T$i66e$s ca--#t 5e calle% #$ e;ecute%. It e;ecute% aut#8aticall!. ) t$i66e$ ca--#t 5e
c$eate% #- a Bie". ) t$i66e$ is c$eate% #-l! i- the cu$$e-t %ata5ase. CR,)T, TRI//,R 8ust 5e the 4i$st
state8e-t i- the 5atch a-% ca- a''l! t# #-l! #-e ta5le. ) t$i66e$ is c$eate% #- #-e %ata5ase ta5le> 5ut it ca-
access #the$ ta5les a-% #5Jects i- #the$ %ata5ases. T$i66e$s ca--#t 5e c$eate% #- te8'#$a$! ta5les #$
s!ste8 ta5les> #-l! #- use$:%e4i-e% ta5les #$ Bie"s. The ta5le #- "hich a t$i66e$ is %e4i-e% is calle% a
trigger table* I4 !#u %elete a ta5le> all t$i66e$s #- that ta5le a$e aut#8aticall! %elete% as "ell.
Example:
1S, 8!)%%$ess5##
I7 ,RISTS ?S,L,CT L 7ROM s!s#5Jects
W+,R, -a8e N Qt$i61Q )ND t!'e N QTRQ@
DROP TRI//,R t$i61
/O
CR,)T, TRI//,R t$i61
#- t5lsala$!
7OR INS,RT> 1PD)T,> D,L,T,
)S
S,L,CT L 7ROM Cust#8e$
/O
"wo "ypes of "riggers are create' on a table: -
INST,)D O7 T$i66e$s
POST E )7T,R T$i66e$s

"#$%&T ' "(TE) Triggers
)7T,R T$i66e$s a$e the %e4ault t!'e #4 t$i66e$ i- SQL Se$Be$ 2222> s# !#u %#-Qt haBe t# use the "#$%
)7T,R i- the CR,)T, TRI//,R state8e-t. G#u ca- %e4i-e 8ulti'le )7T,R T$i66e$s #- a ta5le 4#$
each eBe-t. I- )7T,R t$i66e$ 4i$st e;ecute eBe-t the- e;ecute t$i66e$.
+(ample: -
I7 ,RISTS ?S,L,CT L 7ROM s!s#5Jects
W+,R, -a8e N Q%eleteCtestQ )ND t!'e N QTRQ@
DROP TRI//,R %eleteCtest
/O
CR,)T, TRI//,R %eleteCtest
ON testCt$i66e$ )7T,R D,L,T,
)S
I7 SSROWCO1NT N 2 R,T1RN
PRINT QG#u Just %elete% a $#"WQ
/O
D,L,T, 7ROM testCt$i66e$
*#+N&TE"D %( Triggers
G#u ca- c$eate a si-6le a4te$ t$i66e$ t# e;ecute 4#$ a-! #$ all the INS,RT> 1PD)T,> a-% D,L,T,
acti#-s that 8#%i4! %ata. Cu$$e-tl!> SQL Se$Be$ #44e$s -# t$i66e$ #- a S,L,CT state8e-t 5ecause
S,L,CT %#es -#t 8#%i4! %ata. I- a%%iti#-> a4te$ t$i66e$s ca- e;ist #-l! #- 5ase ta5les> -#t #- Bie"s. O4
c#u$se> %ata 8#%i4ie% th$#u6h a Bie" %#es cause a- a4te$ t$i66e$ #- the u-%e$l!i-6 5ase ta5le t# 4i$e. )s
!#uQll see> !#u ca- %e4i-e i-stea%:#4 t$i66e$s #- Bie"s. I- INST,)D O7 T$i66e$ eBe-t is -#t e;ecute%
#-l! e;ecute% t$i66e$. N# -ee% #4 8#%i4icati#- 4#$ e;ecute INST,)D O7 T$i66e$.
G#u ca- haBe #-l! #-e i-stea%:#4 t$i66e$ 4#$ each acti#- ?INS,RT> 1PD)T,> a-% D,L,T,@.
+(ample: -
CR,)T, .I,W J#i-CBie"
)S
S,L,CT Ta5le1.a as a1> 5> c>
Ta5le2.a as a2> 8essa6e
7ROM Ta5le1 J#i- Ta5le2
ON Ta5le1.a N Ta5le2.a
/O
CR,)T, TRI//,R D,LC3OIN
ON J#i-CBie"
INST,)D O7 D,L,T,
)S
D,L,T, Ta5le1
W+,R, a IN ?S,L,CT a1 7ROM %elete%@
D,L,T, Ta5le2
W+,R, a IN ?S,L,CT a2 7ROM %elete%@
/O
D,L,T, 7ROM J#i-CBie"
,sing "LTE) T)+--E)
T# cha-6e the %e4i-iti#- #4 a t$i66e$> !#u ca- eithe$ %$#' a-% $e:c$eate the t$i66e$ #$ use the )LT,R
TRI//,R state8e-t. This state8e-t uses the sa8e s!-ta; as the CR,)T, TRI//,R state8e-t. G#u
8ust $e%e4i-e the e-ti$e t$i66e$ i4 !#u 8#%i4! it.
USE MyDB
GO
ALTER TRIGGER Print_Update
ON Bicycle_Inventory
FOR UPDATE, INSERT
AS
PRINT "Bicycle_Inventory was updated or a row was inserted"
GO
Difference between a Primary key and a Unique key ?
P$i8a$! e! a-% 1-i<ue e! e-4#$ce u-i<ue-ess #4 the c#lu8- #- "hich the! a$e %e4i-e%.
De4ault '$i8a$! e! c$eate Cluste$e% i-%e; #- the c#lu8-> "he$e u-i<ue e! a$e c$eates N#-:cluste$e%
i-%e; 5! %e4ault. P$i8a$! e! %#es-Qt all#" N1LLs> 5ut 1-i<ue e! all#"s #-e N1LL #-l!. P$i8a$! e!
use% 4#$ u-i<ue i%e-ti4icati#- #4 a $#". ) ta5le ca- haBe #-l! #-e '$i8a$! e!. )-! -u85e$ #4 u-i<ue
c#-st$ai-ts ca- 5e a%%e% t# a ta5le. Multi'le c#lu8-s ca- 5e c#-s#li%ate% t# 4#$8 a si-6le '$i8a$! e!.
Foreign key ?
7#$ei6- e! 8aes $elati#-shi' 5et"ee- ta5les. 7#$ei6- e! #4 #-e ta5le is a P$i8a$! e!
#4 a-#the$ e!.
Here.s a simple wa to declare a primar /e'foreign /e relationship:
CR,)T, T)AL, cust#8e$
?
custCi% i-t NOT N1LL ID,NTITG PRIM)RG =,G>
custC-a8e Ba$cha$?52@ NOT N1LL
@
CR,)T, T)AL, #$%e$s
?
#$%e$Ci% i-t NOT N1LL ID,NTITG PRIM)RG =,G>
custCi% i-t NOT N1LL R,7,R,NC,S cust#8e$?custCi%@
@
Define Candidate Key, Alternate Key, Composite Key, Super Key ?
) ta5le 8a! haBe 8#$e tha- #-e c#85i-ati#- #4 c#lu8-s that c#ul% u-i<uel! i%e-ti4! the
$#"s i- a ta5leH each c#85i-ati#- is a ca-%i%ate e!. /e-e$all! a Ca-%i%ate e! 5ec#8es the P$i8a$! e!
#4 the ta5le. I4 the ta5le has 8#$e tha- #-e Ca-%i%ate e!> #-e #4 the8 "ill 5ec#8e the P$i8a$! e!> a-%
the $est a$e calle% )lte$-ate e!s.
) e! 4#$8e% 5! c#85i-i-6 at least t"# #$ 8#$e c#lu8-s is calle% C#8'#site e!.
Su'e$ =e! is a set #4 att$i5utes that c#llectiBel! i%e-ti4! e-tit! i- a- e-tit! set. 7#$
e;a8'le acc#u-t -u85e$ is a su'e$ e! i- 5a- acc#u-t ta5le.
Store Procedure ?

St#$e '$#ce%u$e is '$e:l#a%e% SQL state8e-ts i- 8e8#$! 4#$ 4aste$ e;ecuti#-. ) st#$e
'$#ce%u$e is a 6$#u' #4 SQL state8e-t that haBe 5ee- '$eBi#usl! c$eate% a-% st#$e% i- the se$Be$ %ata5ase.
St#$e '$#ce%u$e acce'ts i-'ut 'a$a8ete$s s# that a si-6le st#$e '$#ce%u$e ca- use% 5! seBe$al clie-ts usi-6
%i44e$e-t i-'ut %ata. Whe- a st#$e '$#ce%u$e is 8#%i4ie% the- all clie-t aut#8aticall! 6et -e" Be$si#-.
St#$e '$#ce%u$e $e%uces -et"#$ t$a44ic a-% i8'$#Bes 'e$4#$8a-ce. St#$e '$#ce%u$e '$#Bi%es 5ette$
secu$it! t# !#u$ %ata. St#$e '$#ce%u$e su''#$t $ecu$si#-. That 8ea-s "e ca- call st#$e '$#ce%u$e
the8selBes. St#$e '$#ce%u$e hel' '$#8#te c#%e $euse. I- #$%e$ t# e;ecute the st#$e% '$#ce%u$e use
EXECUTE or EXEC e!"#$%. Ma;i8u8 -u85e$ #4 i-'ut a-% #ut'ut 'a$a8ete$s i- St#$e% '$#ce%u$e i- SQL
Se$Be$ 2222 is 1224.
Example 0:
CR,)T, PROC,D1R, 6ettitles
Sti% Ba$cha$?&@ N QXQ
:: the 'a$a8ete$ %e4ault 8ea-s that i4 -# 'a$a8ete$
:: is s'eci4ie%> the '$#ce%u$e "ill $etu$- all the
:: titles
)S
S,L,CT title
7ROM titles
W+,R, titleCi% LI=, Sti%
I7 SS$#"c#u-t N 2
PRINT QThe$e a$e -# titles 8atchi-6 !#u$ i-'utQ
R,T1RN
1all $rocedure :- ,R,C 6ettitles 5u1232
User Defined Functions ?
1se$ De4i-e% 7u-cti#-s a$e c#8'act 'ieces #4 T$a-sact SQL c#%e> "hich ca- acce't
'a$a8ete$s> a-% $etu$- eithe$ a Balue> #$ a ta5le. The! a$e saBe% as i-%iBi%ual "#$ u-its> a-% a$e c$eate%
usi-6 sta-%a$% SQL c#88a-%s. Data t$a-s4#$8ati#- a-% $e4e$e-ce Balue $et$ieBal a$e c#88#- uses 4#$
4u-cti#-s. 1D7 is s'ecial i-% #4 st#$e '$#ce%u$e. 1D7 is i-B#e% "ith SQL state8e-ts 5ut St#$e%
P$#ce%u$e ca- i-B#e 4$#8 4$#-t e-%.
O-e #4 the a%Ba-ta6es #4 1se$ De4i-e% 7u-cti#-s #Be$ St#$e% P$#ce%u$es> is the 4act
that a 1D7 ca- 5e use% i- a Select> Whe$e> #$ Case state8e-t. The! als# ca- 5e use% t# c$eate J#i-s.
1se$ De4i-e% 7u-cti#-s ca--#t 5e use% t# 8#%i4! 5ase ta5le i-4#$8ati#-. It ca--#t 5e
use% "ith INS,RT> 1PD)T, a-% D,L,T,.
"ypes of ,ser Define' -nctions: -
o Scala$ 1D7s
o I-li-e Ta5le 1D7s
o Multi State8e-t 1D7s
&calar ,ser Defined (unction:- It ca- tae u' t# 1224 i-'ut 'a$a8ete$s 5ut -# #ut'ut
'a$a8ete$s. The 4u-cti#- ca- $etu$- a Balue #4 a-! %atat!'e e;ce't row.ersion ?#$ timestamp/> crsor> #$
table. The SQL state8e-ts i-si%e !#u$ scala$:Balue% 4u-cti#-s ca--#t i-clu%e a-! -#-%ete$8i-istic s!ste8
4u-cti#-s. T# i-B#e a use$:%e4i-e% scala$ 4u-cti#-> !#u 8ust s'eci4! the #"-e$ -a8e ?%n +(ample 0'bo1
is owner name@.
,;a8'le 1I : CR,)T, 71NCTION %5#.DateO-l!?SI-DateTi8e %ateti8e@
R,T1RNS Ba$cha$?12@
)S
A,/IN
D,CL)R, SM!Out'ut Ba$cha$?12@
S,T SM!Out'ut N CON.,RT?Ba$cha$?12@>SI-DateTi8e>121@
R,T1RN SM!Out'ut
,ND
To call our function2 execute: S,L,CT %5#.DateO-l!?/,TD)T,?@@
,;a8'le 2I : CR,)T, 71NCTION )Be$a6eP$ice?S5##t!'e Ba$cha$?12@@
R,T1RNS 8#-e!
)S
A,/IN
D,CL)R, SaB6 8#-e!
S,L,CT SaB6 N aB6?'$ice@
7ROM titles
W+,R, t!'e N S5##t!'e

R,T1RN SaB6
,ND
+nvo/e (unction : -
S,L,CT titleCi%> '$ice
7ROM titles
W+,R, '$ice O %5#.)Be$a6eP$ice?Q5usi-essQ@
)ND t!'e N Q5usi-essQ
+nline Table ,ser Defined (unctions $etu$- a ta5le Ba$ia5le that "as c$eate% 5! a
si-6le select state8e-t. I-li-e 4u-cti#- 5#%! sh#ul% 5e a si-6le S,L,CT state8e-t.
,;a8'le 1I : CR,)T, 71NCTION %5#.L##A!7Na8e?S7i$stLette$ cha$?1@@
R,T1RNS T)AL,
)S
R,T1RN S,L,CT L
7ROM e8'l#!ee
W+,R, L,7T?4-a8e> 1@ N S7i$stLette$
,;a8'le 2I : CR,)T, 71NCTION SalesA!St#$e?Sst#$i% Ba$cha$?32@@
R,T1RNS T)AL,
)S
R,T1RN ?S,L,CT title> <t!
7ROM sales s> titles t
W+,R, s.st#$Ci% N Sst#$i% )ND t.titleCi% N s.titleCi%@
+nvo/e +nline function: - S,L,CT L 7ROM SalesA!St#$e ?Q*242Q@

Multi &tatement ,ser Defined (unctions a$e Be$! si8ila$ t# St#$e% P$#ce%u$es. It
all#"s c#8'le; l#6ic i-si%e the 4u-cti#-. It all#"s 8ulti'le state8e-ts. The Multi State8e-t 1D7 "ill
al"a!s $etu$- a ta5le Ba$ia5le::a-% #-l! #-e ta5le Ba$ia5le.
,;a8'le 1I : CR,)T, 71NCTION 4;CO$%e$sA!DateRa-6e)-%C#u-t
? SO$%e$DateSta$t s8all%ateti8e>
SO$%e$Date,-% s8all%ateti8e>
SO$%e$C#u-t s8alli-t @
R,T1RNS SO$%e$sA!DateRa-6e T)AL,
? Cust#8e$ID -cha$?5@>
C#8'a-!Na8e -Ba$cha$?42@>
O$%e$C#u-t s8alli-t>
Ra-i-6 cha$?1@ @

)S
A,/IN
::State8e-t 1
INS,RT SO$%e$sA!DateRa-6e
S,L,CT a.Cust#8e$ID>
a.C#8'a-!Na8e>
CO1NT?a.Cust#8e$ID@)S O$%e$C#u-t>
QAQ
7ROM Cust#8e$s a
3OIN O$%e$s 5 ON a.Cust#8e$ID N5.Cust#8e$ID
W+,R, O$%e$Date A,TW,,N SO$%e$DateSta$t )ND SO$%e$Date,-%
/RO1P AG a.Cust#8e$ID>a.C#8'a-!Na8e
+).IN/ CO1NT?a.Cust#8e$ID@OSO$%e$C#u-t
::State8e-t 2
1PD)T, SO$%e$sA!DateRa-6e
S,T Ra-i-6 NQ)Q
R,T1RN
,ND
+nvo/e Multi-&tatement: -
S,L,CT L
7ROM 4;CO$%e$sA!DateRa-6e)-%C#u-t ?Q1E1E0&Q>Q1E1E0(Q>2@
ORD,R A! Ra-i-6
Difference between Store Procedure (SP) and User Defined Function (UDF) ?
1D7 ca- 5e e;ecute% usi-6 S,L,CT clause "hile SPMs ca--#t 5e.
1D7 ca--#t 5e use RML 7OR clause 5ut SPFs ca- 5e.
1D7 %e#s-Ft $etu$- #ut'ut 'a$a8ete$s "hile SPFs $etu$- #ut'ut 'a$a8ete$s.
)-! e$$#$ is c#8i-6 1D7 st#' e;ecuti-6. Aut SPFs i6-#$es the e$$#$ a-% 8#Bes t# -e;t state8e-t.
1D7 ca--#t 8ae 'e$8a-e-t cha-6es t# se$Be$ e-Bi$#-8e-t. Aut SPFs ca- cha-6e s#8e #4 the
se$Be$ e-Bi$#-8e-t.
7u-cti#- 8ust i-clu%e the R,T1RN state8e-t. I- st#$e% '$#ce%u$es> the R,T1RN is #'ti#-al.
What is View ?
I- SQL Se$Be$> a .iew is a '$e:"$itte- <ue$! that is st#$e% #- the %ata5ase. ) Bie"
c#-sists #4 a S,L,CT state8e-t> a-% "he- !#u $u- the Bie"> !#u see the $esults #4 it lie !#u "#ul% "he-
#'e-i-6 a ta5le. S#8e 'e#'le lie t# thi- #4 a Bie" as a Bi$tual ta5le. ) Bie" ca- 5e use4ul "he- the$e
a$e 8ulti'le use$s "ith %i44e$e-t leBels #4 access> "h# all -ee% t# see '#$ti#-s #4 the %ata i- the %ata5ase
?5ut -#t -ecessa$il! all #4 the %ata@. G#u ca- 8#%i4! a- e;isti-6 Bie" 5! usi-6 )LT,R i-stea% #$
CR,)T,.
,;a8'leI : CR,)T, .I,W )l'ha5eticalClistC'$#%ucts )S
S,L,CT P$#%ucts.L> Cate6#$ies.Cate6#$!Na8e
7ROM Cate6#$ies INN,R 3OIN P$#%ucts ON Cate6#$ies.Cate6#$!ID N P$#%ucts.Cate6#$!ID
W+,R, ???P$#%ucts.Disc#-ti-ue%@N2@@
+nvo/e a 3iew: - S,L,CT L 7ROM )l'ha5eticalClistC'$#%ucts
ALTER TABLE Command ?

We "ill 8#%i4! the ta5le usi-6 the )LT,R T)AL, c#88a-%.
Synta( 23'' a colmn/
)LT,R T)AL, ta5leC-a8e
)DD c#lu8-C-a8e %atat!'e

Synta( 2&!ange t!e 'atatype/
)LT,R T)AL, ta5leC-a8e
)LT,R COL1MN c#lu8-C-a8e %atat!'e
Synta( 2Drop a colmn/
)LT,R T)AL, ta5leC-a8e
DROP COL1MN c#lu8-C-a8e
What is Collation ?
C#llati#- is a set #4 $ules that %ete$8i-e h#" %ata s#$te% a-% c#8'a$e%.

Different "ypes of &ollation Sensiti.ity
Case Se-sitiBit!
)cce-t Se-sitiBit!
=a-a Se-sitiBit!
Wi%th Se-sitiBit!
What is the purpose of Replication ?
Re'licati#- is "a! #4 ee'i-6 %ata s!-ch$#-i9e% i- 8ulti'le %ata5ases. SQL se$Be$
$e'licati#- has t"# i8'#$ta-t as'ects 'u5lishe$ a-% su5sc$i5e$.
Th$ee T!'es #4 Re'licati#-
S-a'sh#t Re'licati#-
T$a-sacti#-al Re'licati#-
Me$6e Re'licati#-
I- &napshot )eplication tae the s-a'sh#t #4 #-e %ata5ase a-% 8#Bes it t# #the$ %ata5ase. I-
Transactional )eplication %ata is c#'ie% 4i$st ti8e as lie s-a'sh#t $e'licati#-> late$ c#'! #-l! the
t$a-sacti#-. I- Merge )eplication c#85i-es %ata 4$#8 8ulti'le s#u$ces i-t# a si-6le ce-t$al %ata5ase.
What is Identity ?
I%e-tit! ?#$ )ut#Nu85e$@ is a c#lu8- that aut#8aticall! 6e-e$ates -u8e$ic Balues. )
sta$t a-% i-c$e8e-t Balue ca- 5e set> 5ut c#88#-l! set as #-e. ,ach ta5le ca- haBe #-l! #-e c#lu8- "ith
the ID,NTITG '$#'e$t!. The ta5leQs c$eat#$ ca- s'eci4! the sta$ti-6 -u85e$ ?see%@ a-% the a8#u-t that
this Balue i-c$e8e-ts.
Authentication modes in SQL ?

Wi-%#"s 8#%e a-% Mi;e% 8#%e K SQL & Wi-%#"s.
Command using Query Analyzer will give you the version of SQL Server and OS ?
S,L,CT S,R.,RPROP,RTG?Q'$#%uctBe$si#-Q@> S,R.,RPROP,RTG?Q'$#%uctleBeQ@>
S,R.,RPROP,RTG?Qe%iti#-Q@
Log Shipping ?
,-te$'$ise ,%iti#-s #-l! su''#$t L#6 Shi''i-6. L#6 Shi''i-6 aut#8aticall! 5acu'
t$a-sacti#-al l#6 4ile a-% aut#8aticall! $est#$e the8 #- the sta-% 5! se$Be$.
Difference between Local and Global temporary table ?
L#cal te8'#$a$! ta5le e;ists #-l! 4#$ the %u$ati#- #4 a c#--ecti#-. Aut /l#5al
te8'#$a$! ta5le $e8ai-s i- the %ata5ase 'e$8a-e-tl!> 5ut $#"s e;ist #-l! 4#$ the %u$ati#- #4 a c#--ecti#-.
Difference between STUFF function and REPLACE function ?
ST177 4u-cti#- is use% t# #Be$"$ite e;isti-6 cha$acte$s. R,PL)C, 4u-cti#- is use% t#
$e'lace e;isti-6 cha$acte$s.
CHECK Constraints ?
C+,C= c#-st$ai-t is use% t# li8its the Balues that ca- 5e 'lace% i- a c#lu8-. It
e-4#$ce %#8ai- i-te6$it!. I4 !#u %e4i-e a C+,C= c#-st$ai-t #- a si-6le c#lu8- it all#"s #-l! ce$tai-
Balues 4#$ this c#lu8-.
NOT NULL Constraints ?
NOT N1LL c#-st$ai-t "ill -#t acce't N1LL Balue i- the c#lu8-. It e-4#$ce %#8ai-
i-te6$it!.
BulkCopy (BCP) and BULK INSERT ?
1si-6 ACP> !#u ca- c#'! %ata 4$#8 a %ata 4ile i-t# SQL Se$Be$ #$ !#u ca- c#'! %ata 4$#8
SQL Se$Be$ i-t# a %ata 4ile.
A1L= INS,RT state8e-t is si8ila$ t# ACP i- that 5#th ca- 5e use% t# 5ul c#'! %ata i-t#
the SQL Se$Be$ %ata5ase 4$#8 a %ata 4ile. 1-lie ACP> h#"eBe$> A1L= INS,RT ca--#t 5e use% t#
e;t$act %ata 4$#8 SQL Se$Be$ %ata5ases.
What is command used for rename a db, a table and a column ?
To rename db
S!-ta;I : s'C$e-a8e%5 M#l%-a8eF > M-e"-a8eF
To rename Table
S!-ta;I : s'C$e-a8e M#l%Ta5leNa8eF M-e"Ta5leNa8eF
To rename 1olumn
S!-ta;I : s'C$e-a8e MTa5leNa8e.TOl%c#lu8-Na8eUF> MNe"C#lu8-Na8eF> MC#lu8-F
UPDATE_STATISTICS Command ?
This c#88a-% is use% "he- a la$6e '$#cessi-6 #4 %ata has #ccu$$e%. Whe- la$6e a8#u-t
#4 %eleti#-> 1'%ati-6> C#'!i-6 i-t# a ta5le at the sa8e ti8e i-%e; #4 that ta5le u'%ate.
1PD)T,CST)TISTICS C#88a-% u'%ate i-%e; #4 these ta5les.
How can you raise custom errors from stored procedure ?
The R)IS,RROR state8e-t is use% t# '$#%uce a- a% h#c e$$#$ 8essa6e #$ t# $et$ieBe a cust#8 8essa6e
that is st#$e% i- the sysmessages ta5le.
Example: - )LT,R PROC,D1R, 'sCN#-7atalCINS,RT
SC#lu8-2 i-t NN1LL
)S
D,CL)R, S,$$#$Ms6ID i-t
INS,RT N#-7atal .)L1,S ?SC#lu8-2@
S,T S,$$#$Ms6ID NSS,RROR
I7 S,$$#$Ms6ID PO2
A,/IN
R)IS,RROR ?Q)- e$$#$ #ccu$e% u'%ati-6 the N#-7atal ta5leQ>12>1@
,ND
What are different transaction levels in SQL SERVER?
T$a-sacti#- Is#lati#- leBel %eci%es h#" is #-e '$#cess is#late% 4$#8 #the$ '$#cess. 1si-6 t$a-sacti#-
leBels !#u ca- i8'le8e-t l#ci-6 i- SQL S,R.,R.

The$e a$e 4#u$ t$a-sacti#- leBels i- SQL S,R.,RI:
R,)D COMMITT,D
R,)D 1NCOMMITT,D
R,P,)T)AL, R,)D
S,RI)LIY)AL,
7#ll#"i-6 is the s!-ta; 4#$ setti-6 t$a-sacti#- leBel i- SQL S,R.,R.
S+" "R3NS3&"%$N %S$43"%$N 4+5+4 S+R%34%6374+
If locking is not implemented what issues can occur ?
7#ll#"i-6 a$e the '$#5le8s that #ccu$ i4 !#u %# -#t i8'le8e-t l#ci-6 '$#'e$l! i- SQL S,R.,R.
L#st 1'%ates
N#-:Re'eata5le Rea%
Di$t! Rea%s
Pha-t#8 Rea%s
The #-l! is#lati#- leBel that %#es-Qt all#" 'ha-t#8s is S,RI)LIY)AL,>
What a$e Z/R)NT[ a-% ZR,.O=,F state8e-ts?
/R)NT state8e-t 6$a-ts $i6hts t# the #5Jects ?ta5le@. While $eB#e %#es the Bice:Be$sa #4 it> it
$e8#Bes $i6hts 4$#8 the #5Ject.
+#" 8a-! T!'es #4 Relati#-shi' ,;ist i- Data5ase Desi6-i-6 ?
The$e a$e th$ee 8aJ#$ $elati#-shi' 8#%elsI
O-e:t#:#-e
O-e:t#:8a-!
Ma-!:t#:8a-!
How we can check the database permission for any user ?
SELECT * FROM fn_my_permissions (null, 'DATABASE')
What is the use of APP_Name() ?
)PPCN)M,?@ $etu$-s the -a8e #4 the a''licati#- 4#$ the cu$$e-t secti#-.
S,L,CT )PPCN)M,?@
What is the use of CHAR function ?
C+)R 4u-cti#- is use% t# c#-Be$t the -u8e$ic )SCII c#%e t# a cha$acte$.
S,L,CT C+)R?02@
:::9
What are various lock types ?
S+)R,D
1PD)T,
,RCL1SI.,
We chec the l#cs %e4i-e% i- a DA usin! in"uil# s#ore$ pro%e$u%e sp_lock
What is the use of MOD function ?
MOD fun%#ion is use$ #o !e# #&e rem'in$er of ' $i(ision)
MOD?%iBi%e-%> %iBi%e$@
,;a8'leI:
S,L,CT MOD?12>5@
it "ill #ut'ut 2.
It "ill $etu$- the %iBi%e-% i4 the %iBi%e$ "ill 2.
Which 4u-cti#- is use% t# -#" the cu$$e-t actiBe use$ "ithi- the h#st O'e$ati-6 S!ste8?
SGST,MC1S,R 4u-cti#- is use% t# -#" the cu$$e-t actiBe use$ "ithi- the h#st O'e$ati-6 S!ste8.
S,L,CT SGST,MC1S,R
)5hise
How to know the ID of a database ?
T# -#" the ID #4 a %ata5ase DACID 4u-cti#- is use%. It taes the %ata5ase -a8e as a- a$6u8e-t.
DACID?%5Na8e@
,;a8'leI: S,L,CT DACID?Stu%e-t@ ::O5
Which function is used to know the database name by giving the database ID ?
The DACN)M, 4u-cti#- is use% t# -#" the %ata5ase -a8e. It taes the %ata5ase i% as the a$6u8e-t.
DACN)M,?%5ID@
,;a8'leI: S,L,CT DACN)M,?5@ ::OStu%e-t
Why FLOOR function is used ?
7LOOR 4u-cti#- is use% t# $#u-%u' a -#- i-te6e$ -u85e$ t# the -e;t least i-te6e$.
&ntax:-
7LOOR?e;'$essi#-@
,;a8'leI:
S,L,CT 7LOOR?355.34@ 7ROM %ualH
It "ill #ut'ut 355. I4 "e "ill 'ass a '#sitiBe -#. it "ill $etu$- #-l! the i-te6e$ 'a$t.
S,L,CT 7LOOR?:355.34@ 7ROM %ualH
It "ill #ut'ut :35&. Whe- "e 'ass a -e6atiBe Balue the- it $etu$-s a- i-te6e$ less tha- the Balue 'asse%.
Which function is used to convert the integer value into spaces ?
The SP)C, 4u-cti#- c#-Be$t the s'eci4ie% i-te6e$ Balue i-t# s'aces.
S,L,CT SP)C,?4@
It "ill #ut'ut a st$i-6 #4 4#u$ s'aces D D.
What is the use of CEILING function ?
The C,ILIN/ 4u-cti#- %#es the #''#site #4 7LOOR 4u-cti#-. It $etu$-s the s8allest i-te6e$ 6$eate$ tha-
the Balue !#u s'eci4!.
S!-ta;I:
C,ILIN/?e;'$essi#-@TECOD,
Example:-
S,L,CT C,ILIN/?422.45@ 7ROM %ual

It "ill #ut'ut 421.
S,L,CT C,ILIN/?:422.45@ 7ROM %ual

It "ill #ut'ut 422.
+#" t# 6et the Gea$ 'a$t 4$#8 the 6iBe- Date ?
(*) +e'r(,ETDATE()) Ou#pu#- ./*/
(.) D'#e0'r#(yy,,ETDATE()) Ou#pu#- ./*/
+#" t# 6et the Da! 'a$t 4$#8 the 6iBe- Date ?
(*) DA+(,ETDATE()) Ou#pu#- ..
(.) D'#e0'r#($,,ETDATE()) Ou#pu#- ..
+#" t# 6et the 8#-th BalueE8#-th 'a$t 4$#8 the 6iBe- Date ?
(*) MO1T2(,ETDATE()) Ou#0u#- .
(.) S3BSTR41,(CO15ERT(('r%&'r(6/),,ETDATE(),*/7),*,6) Ou#pu#- Fe"
(6) D'#e0'r#(M,,ETDATE()) ou#pu#- .
)%%i-6 Gea$ #$ Mi-utes #$ M#-ths #$ +#u$s t# a %ate ?
)%% Gea$I : Select D)T,)DD?!ea$>1>6et%ate?@@
)%% Mi-utesI :Select D)T,)DD?8i-ute>1>6et%ate?@@
)%% M#-thsI :Select D)T,)DD?88>1>6et%ate?@@
)%% +#u$sI :D)T,)DD?hh>11.5>6et%ate?@@
What's the SQL query to restore a database from a backup file ?
RESTORE DATABASE $"_n'me FROM D4S8 9 'E-:$"_n'me)"';'
S84 statement 2a sample/ to bac9p a 'atabase :
"'%;up $'#'"'se $"_n'me #o $is; 9 'e-:$"_n'me)"';'
+#" T# -#" !#u$ SQL Se$Be$ .e$si#- i- SQL c#88a-% '$#8't ?
SELECT <<5ERS4O1
Which s!ste8 ta5le c#-tai-s i-4#$8ati#- #- c#-st$ai-ts #- all the ta5les c$eate%?
3SER_CO1STRA41TS
What is the use of ROWCOUNT?
Retu$-s the -u85e$ #4 $#"s a44ecte% 5! the last state8e-t. It $etu$-s 2 5illi#- $#"s.
What is a ta5le Ba$ia5le i- T:SQL?
T'"le 5'ri'"les 're #&e spe%i'l $'#' #ype #o s#ore #&e ('lues 's in ' #'"le) T&is is s#ore$ insi$e of &e'p)
+#" %# "e List all ta5le -a8es ?
select L 4$#8 s!s#5Jects "he$e ;t!'eNQ1Q #$%e$ 5! -a8e
+#" %# "e list all Data5ases i- a se$Be$ usi-6 <ue$! ?
sele%# * from sys$'#'"'ses
What is the Ma6ic Ta5les i- S<lse$Be$2222 ?
In Database for any table or view When a trigger is fired for any DML command.
Then 2 tables automatically create on backend.
One table is for Insert and other one is for Delete.
These tables are called Magic Tables.
Number of records in both tables should be same.
The two tables have the same structure (the same columns and types of data) as the table on which
the trigger is defined. The deleted table holds copies of rows affected by the execution of a DELETE
or an UPDATE statement. The rows that are deleted from the trigger table are transferred to the
deleted table. The data in the deleted table can then be accessed within the trigger. The inserted table
holds copies of the rows added to the trigger table by the execution of an INSERT or UPDATE
statement. The rows are added simultaneously to the trigger table and the inserted table. Because an
UPDATE statement is treated as a DELETE followed by an INSERT, when an UPDATE statement
is used, the old row values are copied into the deleted table and the new row values are copied into
the trigger table and the inserted table.
The values in the inserted and deleted tables are accessible only within the trigger. Once the trigger
is completed, these tables are no longer accessible.
What is COMMIT a-% ROLLA)C= state8e-t i- SQL ?
COMMIT statement helps in termination of the current transaction and do all the changes that
occur in transaction persistent and this also commits all the changes to the database.
ROLLBACK do the same thing just terminate the current transaction but one another thing is that
the changes made to database are ROLLBACK to the database. ROLLBACK cancel a transaction.
What is the use of CommandBuilder ?
C#88a-%Auil%e$ 5uil%s ZPa$a8ete$[ #5Jects aut#8aticall!. Ael#" is a si8'le c#%e "hich uses
c#88a-%5uil%e$ t# l#a% its 'a$a8ete$ #5Jects.
Di8 '#5JC#88a-%Auil%e$ )s Ne" OleD5C#88a-%Auil%e$?'#5JData)%a'te$@
'#5JC#88a-%Auil%e$.De$iBePa$a8ete$s?'#5JC#88a-%@
What is a cube ?
) cu5e is a c#llecti#- #4 8easu$es a-% %i8e-si#-s 4#$ a-al!9i-6 the %ata i- %etail.
What are the three levels of data abstraction ?
Physical level: The l#"est leBel #4 a5st$acti#- %esc$i5es h#" %ata a$e st#$e%.
Logical level: The -e;t hi6he$ leBel #4 a5st$acti#-> %esc$i5es "hat %ata a$e st#$e% i- %ata5ase a-% "hat
$elati#-shi' a8#-6 th#se %ata.
View level: The hi6hest leBel #4 a5st$acti#- %esc$i5es #-l! 'a$t #4 e-ti$e %ata5ase.
What is DTS And BCP ?
Data T$a-s4#$8ati#- Se$Bices ?DTS@ i- SQL Se$Be$ 2222 '$#Bi%es a set #4 6$a'hical t##ls a-%
'$#6$a88a5le #5Jects t# e;'#$t a-% i8'#$t %ata.
The Aul C#'! P$#6$a8 ?ACP@ is a c#88a-%:li-e utilit! that shi's "ith SQL Se$Be$. It is use% t#
t$a-s4#$8 %ata 4$#8 #-e %ata5ase t# a-#the$.
ACP is 4aste$ tha- DTS
How do we list all column names of a table ?
S,L,CT COL1MNCN)M, 7ROM IN7ORM)TIONCSC+,M) .C#lu8-s
W+,R, T)AL,CN)M, N Qt5l,8'l#!eeQ ORD,R AG COL1MNCN)M,
What is Que$! 5i-%i-6 ?
T&e "in$in! of 'n o"=e%# #o ' >uery)
Di44e$e-ce Aet"ee- I8'lict T$a-sacti#- )-% ,;'lict T$a-sacti#- ?
Implicit Transaction is the auto commit. There is no beginning or ending of the transaction.
Explicit Transaction has the beginning, ending and rollback of transactions with the command
Begin Transaction
Commit Transaction and
Rollback Transaction
In the explicit transaction, if an error occurs in between we can rollback to the begining of the
transaction which cannot be done in implicit transaction.
WhatQs the 8a;i8u8 si9e #4 a $#" ?
?/@/ "y#es
What are Sparse Columns in Sql Server2008 ?
SP)RS, c#lu8- is a t##l that hel's t# $e%uce a8#u-t #4 'h!sical st#$a6e use% i- a %ata5ase. These a$e
#$%i-a$! c#lu8-s that haBe a- #'ti8i9e% st#$a6e 4#$ all -ull Balues. SP)RS, c#lu8- a$e 5ette$ at
8a-a6i-6 N1LL a-% Y,RO Balues i- SQL Se$Be$. It %#es -#t tae a-! s'ace i- %ata5ase at all.
What is the Difference between SQL SERVER 2000 and 2005 ?
SQL S,R.,R 2225 has i-t$#%uce% t"# -e" %ata t!'es Ba$5i-a$! ?8a;@ a-% RML.
SQL S,R.,R 2225 has $e'#$ti-6 se$Bices 4#$ $e'#$ts "hich is a -e"l! a%%e% 4eatu$e a-% %#es -#t
e;ist 4#$ SQL S,R.,R 2222. It "as a se'a$ate i-stallati#- 4#$ SQL Se$Be$ 2222.
I- SQL S,R.,R 2222 the$e "e$e 8a;i8u8 1& i-sta-ces> 5ut i- 2225 !#u ca- haBe u' t# 52
i-sta-ces.
Aul %ata u'l#a%i-6 i- SQL S,R.,R 2222 "as %#-e usi-6 ACP ?Aul c#'! '$#6$a8Fs@ 4#$8at
4iles. N#" i- SQL S,R.,R 2225 5ul> %ata u'l#a%i-6 uses RML 4ile 4#$8at.
SQL S,R.,R 2225 Que$! a-al!9e$ is -#" $e'lace% 5! <ue$! e%it#$.
SQL S,R.,R ,-te$'$ise 8a-a6e$ is -#" $e'lace% 5! SQL S,R.,R Ma-a6e8e-t stu%i#.
Re'licati#- is -#" 8a-a6e% 5! RMO ?Re'licati#- Ma-a6e8e-t O5Jects@.
What is a "constraint" ?
) c#-st$ai-t all#"s !#u t# a''l! si8'le $e4e$e-tial i-te6$it! checs t# a ta5le. The$e a$e 4#u$ '$i8a$!
t!'es #4 c#-st$ai-ts that a$e cu$$e-tl! su''#$te% 5! SQL Se$Be$I
PRIM)RGE1NIQ1,
D,7)1LT
7OR,I/N =,G
C+,C=
NOT N1LL
Which TCP/IP port does SQL Server run on ?
SQL Se$Be$ $u-s #- '#$t 1433 5ut "e ca- als# cha-6e it 4#$ 5ette$ secu$it!.
What is User-Defined datatypes ?
) use$:%e4i-e% %atat!'e ?1DDT@ '$#Bi%es a c#-Be-ie-t "a! 4#$ !#u t# 6ua$a-tee c#-siste-t use #4
u-%e$l!i-6 -atiBe %atat!'es 4#$ c#lu8-s -#"- t# haBe the sa8e %#8ai- #4 '#ssi5le Balues. O-ce
%ecla$e%> a 1DDT is static a-% i88uta5le ?a5s#lute@. The use #4 1DDTs ca- 8ae !#u$ %ata5ase 8#$e
c#-siste-t a-% clea$.
,;a8'le 4#$ c$eate 1se$:%e4i-e% Datat!'eI : ,R,C s'Ca%%t!'e 'h#-eC-u85e$> QBa$cha$?22@Q> Q-#t -ullQ
,se ,ser-Defined datatpe when create a table:-
CR,)T, T)AL, t5lcust#8e$
?
custCi% s8alli-t NOT N1LL>
custC-a8e Ba$cha$?52@ NOT N1LL>
custC9i' Ba$cha$?12@ NOT N1LL>
custC'h#-e 'h#-eC-u85e$>
custC4a; Ba$cha$?22@ NOT N1LL>
@
CONVERT( ) function ?
CON.,RT 4u-cti#- is use% t# c#-Be$t a c#lu8- t!'e t# a-#the$ t!'e. CON.,RT 4u-cti#- t# aB#i% a-
#Be$4l#" e$$#$.
Example: -
S,L,CT c#l1> S1M?CON.,RT?5i6i-t> c#l2@@
7ROM 8!ta5le
/RO1P AG c#l1
CASE expression and NULLIF ( ) and ISNULL ( ) ?
1"&E expression
Synta(: -
C)S,
W+,N e;'$essi#-1Ne;'$essi#-2 T+,N N1LL
,LS, e;'$essi#-1
,ND
+(ample: -
1PD)T, t5lSala$! S,T sala$! N
C)S,
W+,N sala$! A,TW,,N 32222 )ND 42222 T+,N sala$! \ 5222
W+,N sala$! A,TW,,N 42222 )ND 55222 T+,N sala$! \ (222
W+,N sala$! A,TW,,N 55222 )ND &5222 T+,N sala$! \ 12222
,LS, sala$! \ 2222
,ND
N,LL+( 4 #
N1LLI72emp)salary; 0/ '$#%uces N1LL 4#$ $#"s i- "hich the sala$! e<uals 2. A! c#-Be$ti-6 the 2
Balues t# N1LL> "e ca- use the a66$e6ate 4u-cti#-s Just as "eQ% use the8 "ith N1LL s# that S1M a-%
MIN a-% )./ i6-#$e the N1LL e-t$ies.
+(ample: -
S,L,CT
QNu8 ,8'l#!eesQNCO1NT?L@>
Q)B6 Sala$!QN)./?N1LLI7?e8'Csala$!> 2@@>
QL#" Sala$!QNMIN?N1LLI7?e8'Csala$!> 2@@>
Q)B6 )6eQN)./?N1LLI7?e8'Ca6e> 2@@>
QG#u-6estQNMIN?N1LLI7?e8'Ca6e> 2@@
7ROM e8'l#!ee
+&N,LL 4 #
+(ample 1: -
CR,)T, .I,W aut#Ccu5e ?u-its> 8#%el> !ea$> c#l#$@ )S
S,L,CT S1M?u-itsCs#l%@>
ISN1LL?8#%el> Q)LLQ@> ISN1LL?CON.,RT?cha$?4@> !ea$@> Q)LLQ@>
ISN1LL?c#l#$> Q)LLQ@
7ROM 4ullcu5e
/RO1P AG 8#%el> !ea$> c#l#$
Note: - I- the a5#Be e;a8'le Null is c#-Be$ti-6 t# )LL
+(ample 2: -
S,L,CT -a8e> )./?ISN1LL?!ea$s>2@@ 7ROM t5lGea$s
/RO1P AG -a8e
What is Routines ?
I- SQL Se$Be$ 2222> st#$e% '$#ce%u$es a-% use$:%e4i-e% 4u-cti#-s a$e c#-si%e$e% $#uti-es. The )NSI
SC+,M) .I,W calle% RO1TIN,S c#-tai-s i-4#$8ati#- a5#ut all !#u$ '$#ce%u$es a-% use$:%e4i-e%
4u-cti#-s> i-clu%i-6 the te;t that 8aes u' the $#uti-eQs %e4i-iti#-.
S,L,CT $#uti-eCt!'e> $#uti-eC-a8e 7ROM IN7ORM)TIONCSC+,M).RO1TIN,S
Multirelation Queries ?
List #4 $elati#-s i- 7ROM clause.
Relati#-:%#t:att$i5ute i%e-ti4! att$i5utes 4$#8 seBe$al $elati#-s "ith#ut %#u5t.
,;a8'leI :
S,L,CT 5ee$ 7ROM 7$e<ue-ts> Lies
W+,R, 5a$NFJ#eF )ND
7$e<ue-ts.%$i-e$ NLies.%$i-e$
What is Quantifiers ?
)NG a-% )LL 5ehaBe as e;iste-tial a-% u-iBe$sal <ua-ti4ie$s $es'ectiBel!.
+(ample 1: -
S,L,CT 5ee$ 7ROM Sells )>P$ice A
W+,R, A.a8#u-tON)NG?S,L,CT a8#u-t 7ROM P$ice@ )ND ).5ee$i%NA.5ee$i%
Note: - Dis'la! all 5ee$ that has a8#u-t i- MP$iceF ta5le.
+(ample 2: -
S,L,CT 5ee$ 7ROM Sells )>P$ice A
W+,R, A.a8#u-tON)LL?S,L,CT a8#u-t 7ROM P$ice@ )ND ).5ee$i%NA.5ee$i%
Note: - Dis'la! 5ee$ that has hi6hest a8#u-t i- MP$iceF ta5le.
ADO.NET ?
)DO.N,T is a %ata5ase access 8#%el i- .Net. )DO.N,T access %ata Be$! 4ast.
7#ll#"i-6 a$e the -a8es'aces '$#Bi%e% 5! .N,T 4#$ %ata 8a-a6e8e-t I:
S!ste8.Data
S!ste8.Data.OleDA
S!ste8.Data.S<lClie-t
S!ste8.RML

&stem! Data c#-tai-s the 5asic #5Jects use% 4#$ accessi-6 a-% st#$i-6 $elati#-al %ata> such as
DataSet> DataTa5le> a-% DataRelati#-.
&stem!Data!%leD* c#-tai-s the #5Jects that "e use t# c#--ect t# a %ata s#u$ce Bia a- OL,:
DA '$#Bi%e$> such as OleD5C#--ecti#-> OleD5C#88a-%> etc.
&stem!Data!&5l1lient c#-tai-s the #5Jects that "e use t# c#--ect t# a %ata s#u$ce Bia the
Ta5ula$ Data St$ea8 ?TDS@ i-te$4ace #4 Mic$#s#4t SQL Se$Be$ ?#-l!@.
&stem!6ML C#-tai-s the 5asic #5Jects $e<ui$e% t# c$eate> $ea%> st#$e> "$ite> a-% 8a-i'ulate
RML %#cu8e-ts acc#$%i-6 t# W3C $ec#88e-%ati#-s.
The 8#st i8'#$ta-t secti#- i- )DO.N,T a$chitectu$e is ZData P$#Bi%e$[. Data P$#Bi%e$ '$#Bi%es access
t# %atas#u$ce ?SQL S,R.,R> )CC,SS> OR)CL,@.O5Ject #4 )DO.N,T a$eI :
C#--ecti#-
C#88a-%
DataRea%e$
DataSet
Data )%a'te$
Datareader a-% Dataset a$e the t"# 4u-%a8e-tal #5Jects i- )DO.N,T.
1onnection ob7ects are used to connect a data to a 1ommand ob7ect!
] )- OleD5C#--ecti#- #5Ject is use% "ith a- OL,:DA '$#Bi%e$
] ) S<lC#--ecti#- #5Ject uses Ta5ula$ Data Se$Bices ?TDS@ "ith MS SQL Se$Be$
1ommand %b7ects are used to connect connection ob7ect to Datareader or Dataset!
7#ll#"i-6 a$e the 8eth#%s '$#Bi%e% 5! c#88a-% #5Ject I:
] ,;ecuteN#-Que$!I : C#88a-% #5Ject e;ecute "ith 1PD)T,> D,L,T, #$ INS,RT <ue$ies.
] ,;ecuteRea%e$I : Its use% t# $et$ieBe% %ata 4$#8 %ata5ase.
] ,;ecuteScala$I : Its use% t# $etu$-s #-l! si-6le Balue. ?e44ectiBel! the 4i$st c#lu8- #4 the 4i$st
$#" #4 the $esulti-6 $#"set@. It is 4ast a-% e44icie-t "he- #-l! a Dsi-6let#-D Balue is $e<ui$e%.
Data"dapter are ob7ects that connect one or more 1ommand ob7ects to a Dataset ob7ect!
SQLData)%a'te$ class is use% t# $et$ieBe a-% u'%ate the %ata5ase $ec#$%s i- a DataSet. It is a 5$i%6e
5et"ee- SQL Se$Be$ a-% DataSet.
] )- OleD5Data)%a'te$ #5Ject is use% "ith a- OL,:DA '$#Bi%e$
] ) S<lData)%a'te$ #5Ject uses Ta5ula$ Data Se$Bices "ith MS SQL Se$Be$.
The$e a$e th$ee 8#st c#88#-l! use% 8eth#%s #4 Dataa%a'te$ I:
7ill
7illSche8a
1'%ate
8hat is difference between dataset and datareader 9
7#ll#"i-6 a$e s#8e 8aJ#$ %i44e$e-ces 5et"ee- %ataset a-% %ata$ea%e$ I:
] DataRea%e$ '$#Bi%es 4#$"a$%:#-l! a-% $ea%:#-l! access t# %ata> "hile the DataSet #5Ject ca-
h#l% 8#$e tha- #-e ta5le ?i- #the$ "#$%s 8#$e tha- #-e $#"set@ 4$#8 the sa8e %ata s#u$ce as "ell
as the $elati#-shi's 5et"ee- the8. 1si-6 Dataset %ata $ea% a-% u'%ate 4$#8 %ata s#u$ce.
] Dataset is a %isc#--ecte% a$chitectu$e "hile %ata$ea%e$ is c#--ecte% a$chitectu$e.
] Dataset ca- 'e$sist?Lc#-ti-ue@ c#-te-ts "hile %ata$ea%e$ ca- -#t 'e$sist c#-te-ts> the! a$e
4#$"a$% #-l!.
] DataSet slower t!an DataRea'er
] The$eQs -# c#-ce't #4 cu$s#$ t!'es i- a DataSet.
] ) DataSet ca- $e'$ese-t a- e-ti$e $elati#-al %ata5ase i- 8e8#$!> c#8'lete "ith ta5les> $elati#-s>
a-% Bie"s.
] DataSets haBe -# cu$$e-t $ec#$% '#i-te$ G#u ca- use 7#$ ,ach l##'s t# 8#Be th$#u6h the %ata.
] Data i- a DataSet is 5ul:l#a%e%
] ) DataSet ca- 5e c#-Be$te% t# RML.
) Dataset ca- $e'$ese-t a- e-ti$e $elati#-al %ata5ase i- 8e8#$!> c#8'lete "ith ta5les> $elati#-s> a-%
Bie"s.
Different methods and $roperties of Data)eader which ou have used in our pro7ect9
Rea%
/etSt$i-6
/etI-t32
How can we force the connection ob7ect to close after m datareader is closed 9
C#88a-% 8eth#% ,;ecute$ea%e$ taes a 'a$a8ete$ calle% as C#88a-%AehaBi#$ "he$e i- "e ca- s'eci4!
sa!i-6 cl#se c#--ecti#- aut#8aticall! a4te$ the Data$ea%e$ is cl#se.
pob<DataRea'er = pob<&omman'*+(ecteRea'er2&omman'7e!a.ior*&lose&onnection/
+ want to force the datareader to return onl schema of the datastore rather than data 9
pob<DataRea'er = pob<&omman'*+(ecteRea'er2&omman'7e!a.ior*Sc!ema$nly/
Note: - C#-4i6 4iles a$e the 5est 'laces t# st#$e c#--ecti#-st$i-6s. I4 it is a "e5:5ase% a''licati#-
ZWe5.c#-4i6[ 4ile "ill 5e use% a-% i4 it is a "i-%#"s a''licati#- Z)''.c#-4i6[ 4iles "ill 5e use%.
8hat are the various methods provided b the dataset ob7ect to generate 6ML9
] Rea%RML
Rea%Fs a RML %#cu8e-t i- t# Dataset.
] /etRML
This is a 4u-cti#- "hich $etu$-s the st$i-6 c#-tai-i-6 RML %#cu8e-t.
] W$iteRML
This "$ites a RML %ata t# %is.
How can we save all data from dataset 9
Dataset has Z)cce'tCha-6es[ 8eth#% "hich c#88its all the cha-6es si-ce last ti8e
How can we add'remove row:s in ;DataTable< ob7ect of ;Data&et< 9
Add
)%%s a -e" $#" i- DataTa5le
Remove
It $e8#Bes a ZDataR#"[ #5Ject 4$#8 ZDataTa5le[
RemoveAt
It $e8#Bes a ZDataR#"[ #5Ject 4$#8 ZDataTa5le[ %e'e-%i-6 #- i-%e; '#siti#- #4 the ZDataTa5le[
8hat is basic use of ;Data3iew< 9
>Data5iew? use% 4#$ s#$ti-6 a-% 4i-%i-6 %ata "ith i- Z%atata5le[.
DataBie" has the 4#ll#"i-6 8eth#%Fs I:
Find
It taes a a$$a! #4 Balues a-% $etu$-s the i-%e; #4 the $#".
FindRow
This als# taes a$$a! #4 Balues 5ut $etu$-s a c#llecti#- #4 ZDataR#"[.
I4 "e "a-t t# 8a-i'ulate %ata #4 ZDataTa5le[ #5Ject c$eate ZData.ie"[ ?1si-6 the ZDe4ault.ie"[ "e ca-
c$eate ZData.ie"[ #5Ject@ #4 the ZDataTa5le[ #5Ject a-% use the 4#ll#"i-6 4u-cti#-alities I:
AddNew
)%%s a -e" $#" t# the ZData.ie"[ #5Ject.
Delete
Deletes the s'eci4ie% $#" 4$#8 ZData.ie"[ #5Ject.
How can we add relation:s between table in a Data&et 9
Relati#-s ca- 5e a%%e% 5et"ee- ZDataTa5le[ #5Jects usi-6 the ZDataRelati#-[ #5Ject.
#5JDataSet.Relati#-s.)%%?DCust#8e$)%%$essesD>#5JDataSet.Ta5les?DCust#8e$D@.C#lu8-s?DCusti%D@
>#5JDataSet.Ta5les?D)%%$essesD@.C#lu8-s?DCusti%C4D@@
8hat is difference between Dataset! clone and Dataset! cop 9
Cl#-eI : It #-l! c#'ies st$uctu$e> %#es -#t c#'! %ata.
C#'!I : C#'ies 5#th st$uctu$e a-% %ata.
Explain the difference between an "D%!NET Dataset and an "D% )ecordset 9
With dataset you an retrieve data from two databases like oracle and sql server and merge
them in one dataset , with recordset this is not possible.
)ll $e'$ese-tati#- #4 Dataset is usi-6 RML "hile $ec#$%set uses COM.
Rec#$%set ca- -#t 5e t$a-s8itte% #- +TTP "hile Dataset ca- 5e.
8hat is the purpose of connection pooling in "D%!NET 9
O-ce a c#--ecti#- has 5ee- c$eate% a-% 'lace% i- a connection pool> a- a''licati#- ca- $euse that
c#--ecti#- "ith#ut 'e$4#$8i-6 the c#8'lete c#--ecti#- c$eati#- '$#cess.
A! %e4ault> the connection pool is c$eate% "he- the 4i$st c#--ecti#- "ith a u-i<ue c#--ecti#- st$i-6
c#--ects t# the %ata5ase. The '##l is '#'ulate% "ith c#--ecti#-s u' t# the 8i-i8u8 '##l si9e. )%%iti#-al
c#--ecti#-s ca- 5e a%%e% u-til the '##l $eaches the maximum pool size.
Whe- a use$ $e<uest a c#--ecti#-> it is $etu$-e% 4$#8 the '##l $athe$ tha- esta5lishi-6 -e" c#--ecti#-
a-%> "he- a use$ $eleases a c#--ecti#-> it is $etu$-e% t# the '##l $athe$ tha- 5ei-6 $elease%. Aut 5e su$e
tha- !#u$ c#--ecti#-s use the sa8e connection string each ti8e.
+e$e is the S!-ta;
conn*&onnectionString = @integrate' Secrity=SSP%A S+R5+R=1B2*1CD*0*123A D3"373S+=ME)D7A
Min Pool SiFe=4AMa( Pool SiFe=40A&onnect "imeot=14A@A
P^^..T# DataRea%e$^^^^..O
CON.O'e-? @
6CMD.Pa$a8ete$s.Clea$?@
6CMD.Pa$a8ete$s.)%%?DSO$%e$N#D> t;tTAOO$%e$N#.Te;t@
6st$Que$! N DS,L,CT L 7ROM t5lT$a-Ai-%O$%e$ D & C
D W+,R, TAi-%O$%e$I%POD & li-tTAOI% & D )ND O$%e$N#NSO$%e$N#D
6CMD.C#--ecti#- N CON
6CMD.C#88a-%Te;t N 6st$Que$!
6DR N 6CMD.,;ecuteRea%e$
P^^..T# D$#'%#"- list^^^^..O
CN.O'e-?@H
D) N -e" S<lData)%a'te$?DS,L,CT T.,8'I%>,.,8'Na8e 7ROM t5lC+RC,8'P$#4ile , INN,R 3OIN
t5lCSe$CTech-icia-Maste$ T ON ,.,8'IDNT.,8'ID ORD,R AG ,.,8'Na8eD> CN@H
D).7ill?DS> DTech-icia-sD@H
checTech-icia-s.DataS#u$ce N DS.Ta5lesTDTech-icia-sDUH
checTech-icia-s.DataTe;t7iel% N D,8'Na8eDH
checTech-icia-s.Data.alue7iel% N D,8'I%DH
checTech-icia-s.DataAi-%?@H
P^^..T# Data/$i%.ie"^^^^..O
CN.O'e-?@H
D) N -e" S<lData)%a'te$?DS,L,CT T.,8'I%>,.,8'Na8e 7ROM t5lC+RC,8'P$#4ile , INN,R 3OIN
t5lCSe$CTech-icia-Maste$ T ON ,.,8'IDNT.,8'ID ORD,R AG ,.,8'Na8eD> CN@H
D).7ill?DS> DTech-icia-sD@H
%6BDeatails.DataS#u$ce N DS.Ta5lesTDTech-icia-sDUH
%6BDeatails.DataAi-%?@H
8hat happens when we issue Dataset!)ead6ml command9
Rea%s RML sche8a a-% %ata i-t# the DataSet.