SlideShare a Scribd company logo
hirist 
.com 
www.hirist.com 
SQL 
TOP 100 
INTERVIEW QUESTIONS & ANSWERS
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisDBMS? 
2 
QUESTION 
ADatabaseManagementSystem(DBMS)isaprogramthatcontrolscreation,maintenanceanduseofadatabase. DBMScanbetermedasFileManagerthatmanagesdatainadatabaseratherthansavingitinfilesystems. 
ANSWER 
QUESTION 1
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisRDBMS? 
3 
QUESTION 
RDBMSstandsforRelationalDatabaseManagementSystem.RDBMSstorethedataintothecollectionoftables, whichisrelatedbycommonfieldsbetweenthecolumnsofthetable.Italsoprovidesrelationaloperatorstomanipulatethedatastoredintothetables. 
Example:SQLServer. 
ANSWER 
QUESTION 2
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisSQL? 
4 
QUESTION 
SQLstandsforStructuredQueryLanguage,anditisusedtocommunicatewiththeDatabase.Thisisastandardlanguageusedtoperformtaskssuchasretrieval,updation,insertionanddeletionofdatafromadatabase. 
StandardSQLCommandsareSelect. 
ANSWER 
QUESTION 3
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisaDatabase? 
5 
QUESTION 
Databaseisnothingbutanorganizedformofdataforeasyaccess,storing,retrievalandmanagingofdata.Thisisalsoknownasstructuredformofdatawhichcanbeaccessedinmanyways. 
Example:SchoolManagementDatabase,BankManagementDatabase. 
ANSWER 
QUESTION 4
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhataretablesandFields? 
6 
QUESTION 
AtableisasetofdatathatareorganizedinamodelwithColumnsandRows.Columnscanbecategorizedasvertical,andRowsarehorizontal.Atablehasspecifiednumberofcolumncalledfieldsbutcanhaveanynumberofrowswhichiscalledrecord. 
Example:. 
Table:Employee. 
Field:EmpID,EmpName,DateofBirth. 
Data:201456,David,11/15/1960. 
ANSWER 
QUESTION 5
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisaprimarykey? 
7 
QUESTION 
Aprimarykeyisacombinationoffieldswhichuniquelyspecifyarow.Thisisaspecialkindofuniquekey,andithasimplicitNOTNULLconstraint.Itmeans,PrimarykeyvaluescannotbeNULL. 
ANSWER 
QUESTION 6
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisauniquekey? 
8 
QUESTION 
AUniquekeyconstraintuniquelyidentifiedeachrecordinthedatabase.Thisprovidesuniquenessforthecolumnorsetofcolumns. 
APrimarykeyconstrainthasautomaticuniqueconstraintdefinedonit.Butnot,inthecaseofUniqueKey. 
Therecanbemanyuniqueconstraintdefinedpertable,butonlyonePrimarykeyconstraintdefinedpertable. 
ANSWER 
QUESTION 7
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisaforeignkey? 
9 
QUESTION 
Aforeignkeyisonetablewhichcanberelatedtotheprimarykeyofanothertable.Relationshipneedstobecreatedbetweentwotablesbyreferencingforeignkeywiththeprimarykeyofanothertable. 
ANSWER 
QUESTION 8
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatarethetypesofjoinandexplaineach? 
10 
QUESTION 
Therearevarioustypesofjoinwhichcanbeusedtoretrievedataanditdependsontherelationshipbetweentables. 
InnerJoin:Innerjoinreturnrowswhenthereisatleastonematchofrowsbetweenthetables. 
RightJoin:RightjoinreturnrowswhicharecommonbetweenthetablesandallrowsofRighthandsidetable. Simply,itreturnsalltherowsfromtherighthandsidetableeventhoughtherearenomatchesinthelefthandsidetable. 
LeftJoin:LeftjoinreturnrowswhicharecommonbetweenthetablesandallrowsofLefthandsidetable.Simply,itreturnsalltherowsfromLefthandsidetableeventhoughtherearenomatchesintheRighthandsidetable. 
FullJoin:Fulljoinreturnrowswhentherearematchingrowsinanyoneofthetables.Thismeans,itreturnsalltherowsfromthelefthandsidetableandalltherowsfromtherighthandsidetable. 
ANSWER 
QUESTION 9
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Explainanouterjoin? 
11 
QUESTION 
Anouterjoinincludesrowsfromtableswhentherearenomatchingvaluesinthetables. 
ANSWER 
QUESTION 10
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisnormalization? 
12 
QUESTION 
Normalizationistheprocessofminimizingredundancyanddependencybyorganizingfieldsandtableofadatabase.ThemainaimofNormalizationistoadd,deleteormodifyfieldthatcanbemadeinasingletable. 
ANSWER 
QUESTION 11
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisDenormalization? 
13 
QUESTION 
DeNormalizationisatechniqueusedtoaccessthedatafromhighertolowernormalformsofdatabase.Itisalsoprocessofintroducingredundancyintoatablebyincorporatingdatafromtherelatedtables. 
ANSWER 
QUESTION 12
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatareallthedifferentnormalizations? 
14 
QUESTION 
Thenormalformscanbedividedinto4forms,andtheyareexplainedbelow-. 
FirstNormalForm(1NF):Thisshouldremovealltheduplicatecolumnsfromthetable.Creationoftablesfortherelateddataandidentificationofuniquecolumns. 
SecondNormalForm(2NF):Meetingallrequirementsofthefirstnormalform.PlacingthesubsetsofdatainseparatetablesandCreationofrelationshipsbetweenthetablesusingprimarykeys. 
ThirdNormalForm(3NF):Thisshouldmeetallrequirementsof2NF.Removingthecolumnswhicharenotdependentonprimarykeyconstraints. 
FourthNormalForm(4NF):Meetingalltherequirementsofthirdnormalformanditshouldnothavemulti- valueddependencies. 
ANSWER 
QUESTION 13
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisanIndex?Whatareallthedifferenttypesofindexes? 
15 
QUESTION 
Anindexisperformancetuningmethodofallowingfasterretrievalofrecordsfromthetable.Anindexcreatesanentryforeachvalueanditwillbefastertoretrievedata. 
Thisindexingdoesnotallowthefieldtohaveduplicatevaluesifthecolumnisuniqueindexed.Uniqueindexcanbeappliedautomaticallywhenprimarykeyisdefined. 
ClusteredIndex:Thistypeofindexreordersthephysicalorderofthetableandsearchbasedonthekeyvalues. Eachtablecanhaveonlyoneclusteredindex. 
NonClusteredIndex:NonClusteredIndexdoesnotalterthephysicalorderofthetableandmaintainslogicalorderofdata.Eachtablecanhave999nonclusteredindexes. 
ANSWER 
QUESTION 14
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisarelationshipandwhatarethey? 
16 
QUESTION 
DatabaseRelationshipisdefinedastheconnectionbetweenthetablesinadatabase.Therearevariousdatabasingrelationships,andtheyareasfollows:. OnetoOneRelationship. OnetoManyRelationship. ManytoOneRelationship. Self-ReferencingRelationship. 
ANSWER 
QUESTION 15
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisaquery? 
17 
QUESTION 
ADBqueryisacodewritteninordertogettheinformationbackfromthedatabase.Querycanbedesignedinsuchawaythatitmatchedwithourexpectationoftheresultset.Simply,aquestiontotheDatabase. 
ANSWER 
QUESTION 16
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatissubquery?Whatarethetypesofsubquery? 
18 
QUESTION 
Asubqueryisaquerywithinanotherquery.Theouterqueryiscalledasmainquery,andinnerqueryiscalledsubquery.SubQueryisalwaysexecutedfirst,andtheresultofsubqueryispassedontothemainquery. 
Therearetwotypesofsubquery–CorrelatedandNon-Correlated. 
Acorrelatedsubquerycannotbeconsideredasindependentquery,butitcanreferthecolumninatablelistedintheFROMthelistofthemainquery. 
ANon-Correlatedsubquerycanbeconsideredasindependentqueryandtheoutputofsubqueryaresubstitutedinthemainquery. 
ANSWER 
QUESTION 17
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisatrigger? 
19 
QUESTION 
ADBtriggerisacodeorprogramsthatautomaticallyexecutewithresponsetosomeeventonatableorviewinadatabase.Mainly,triggerhelpstomaintaintheintegrityofthedatabase. 
Example:Whenanewstudentisaddedtothestudentdatabase,newrecordsshouldbecreatedintherelatedtableslikeExam,ScoreandAttendancetables. 
ANSWER 
QUESTION 18
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatarethetypesofTriggers? 
20 
QUESTION 
Therearefourtypesoftriggersandtheyare: 
•Insert 
•Delete 
•Update 
•Insteadof 
ANSWER 
QUESTION 19
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisthedifferencebetweenDELETETRUNCATEandDROPcommands? 
21 
QUESTION 
DELETEcommandisusedtoremoverowsfromthetable,andWHEREclausecanbeusedforconditionalsetofparameters.CommitandRollbackcanbeperformedafterdeletestatement. 
TRUNCATEremovesallrowsfromthetable.Truncateoperationcannotberolledback. 
Dropcommandisusedtodropthetableorkeyslikeprimary,foreignfromatable. 
ANSWER 
QUESTION 20
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisdataIntegrity? 
22 
QUESTION 
DataIntegritydefinestheaccuracyandconsistencyofdatastoredinadatabase.Itcanalsodefineintegrityconstraintstoenforcebusinessrulesonthedatawhenitisenteredintotheapplicationordatabase. 
ANSWER 
QUESTION 21
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatiscollation? 
23 
QUESTION 
Collationisdefinedassetofrulesthatdeterminehowcharacterdatacanbesortedandcompared.ThiscanbeusedtocompareAand,otherlanguagecharactersandalsodependsonthewidthofthecharacters. 
ASCIIvaluecanbeusedtocomparethesecharacterdata. 
ANSWER 
QUESTION 22
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
AdvantagesandDisadvantagesofStoredProcedure? 
24 
QUESTION 
Storedprocedurecanbeusedasamodularprogramming–meanscreateonce,storeandcallforseveraltimeswheneverrequired.Thissupportsfasterexecutioninsteadofexecutingmultiplequeries.Thisreducesnetworktrafficandprovidesbettersecuritytothedata. 
DisadvantageisthatitcanbeexecutedonlyintheDatabaseandutilizesmorememoryinthedatabaseserver. 
ANSWER 
QUESTION 23
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisSQLInjection? 
25 
QUESTION 
SQLInjectionisoneofthetechniquesusesbyhackerstohackawebsitebyinjectingSQLcommandsindatafields. 
ANSWER 
QUESTION 24
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisthedifferencebetweenaHAVINGCLAUSEandaWHERECLAUSE? 
26 
QUESTION 
Theyspecifyasearchconditionforagrouporanaggregate.ButthedifferenceisthatHAVINGcanbeusedonlywiththeSELECTstatement.HAVINGistypicallyusedinaGROUPBYclause.WhenGROUPBYisnotused, HAVINGbehaveslikeaWHEREclause.HavingClauseisbasicallyusedonlywiththeGROUPBYfunctioninaquerywhereasWHEREClauseisappliedtoeachrowbeforetheyarepartoftheGROUPBYfunctioninaquery. 
ANSWER 
QUESTION 25
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Howwouldapplydaterangefilter? 
27 
QUESTION 
a.Youcanusesimplecondition>=and<=orsimilarorusebetween/andbutthetrickistoknowyourexactdatatype. 
b.Sometimesdatefieldscontaintimeandthatiswherethequerycangowrongsoitisrecommendedtousesomedaterelatedfunctionstoremovethetimeissue.InSQLServercommonfunctiontodothatisdatedifffunction. 
c.Youalsohavetobeawareofdifferenttimezonesandservertimezone. 
d.Toincreasequeryperformanceyoumaystillwanttousebetweenhoweveryoushouldbeawareofproperformatyoushoulduseifnotitmightmisbehaveduringfiltering. 
ANSWER 
QUESTION 26
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisthedifferencebetweenJOINandUNION? 
28 
QUESTION 
SQLJOINallowsusto―lookup‖recordsonothertablebasedonthegivenconditionsbetweentwotables.Forexample,ifwehavethedepartmentIDofeachemployee,thenwecanusethisdepartmentIDoftheemployeetabletojoinwiththedepartmentIDofdepartmenttabletolookupdepartmentnames. 
UNIONoperationallowsustoadd2similardatasetstocreateresultingdatasetthatcontainsallthedatafromthesourcedatasets.Uniondoesnotrequireanyconditionforjoining.Forexample,ifyouhave2employeetableswithsamestructure,youcanUNIONthemtocreateoneresultsetthatwillcontainalltheemployeesfrombothofthetables. 
SELECT*FROMEMP1 
UNION 
SELECT*FROMEMP2; 
ANSWER 
QUESTION 27
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisthedifferenceamongUNION,MINUSandINTERSECT? 
29 
QUESTION 
UNIONcombinestheresultsfrom2tablesandeliminatesduplicaterecordsfromtheresultset. 
MINUSoperatorwhenusedbetween2tables,givesusalltherowsfromthefirsttableexcepttherowswhicharepresentinthesecondtable. 
INTERSECToperatorreturnsusonlythematchingorcommonrowsbetween2resultsets. 
ANSWER 
QUESTION 28
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisSelfJoinandwhyisitrequired? 
30 
QUESTION 
SelfJoinistheactofjoiningonetablewithitself.SelfJoinisoftenveryusefultoconvertahierarchicalstructureintoaflatstructure 
ANSWER 
QUESTION 29
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
HowcanwetransposeatableusingSQL(changingrowstocolumnorvice-versa)? 
31 
QUESTION 
TheusualwaytodoitinSQListouseCASEstatementorDECODEstatement. 
ANSWER 
QUESTION 30
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatarethedifferencesamongROWNUM,RANKandDENSE_RANK? 
32 
QUESTION 
ROW_NUMBERassignscontiguous,uniquenumbersfrom1..Ntoaresultset. 
RANKdoesnotassignuniquenumbers—nordoesitassigncontiguousnumbers.Iftworecordstieforsecondplace,norecordwillbeassignedthe3rdrankasnoonecameinthird,accordingtoRANK. 
DENSE_RANK,likeRANK,doesnotassignuniquenumbers,butitdoesassigncontiguousnumbers.Eventhoughtworecordstiedforsecondplace,thereisathird-placerecord. 
ANSWER 
QUESTION 31
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisadatabasetransaction? 
33 
QUESTION 
Databasetransactiontakedatabasefromoneconsistentstatetoanother.Attheendofthetransactionthesystemmustbeinthepriorstateiftransactionfailsorthestatusofthesystemshouldreflectthesuccessfulcompletionifthetransactiongoesthrough. 
ANSWER 
QUESTION 32
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatarepropertiesofatransaction? 
34 
QUESTION 
PropertiesofthetransactioncanbesummarizedasACIDProperties. 
1.Atomicity:Atransactionconsistsofmanysteps.Whenallthestepsinatransactiongetscompleted,itwillgetreflectedinDBorifanystepfails,allthetransactionsarerolledback. 
2.Consistency:Thedatabasewillmovefromoneconsistentstatetoanother,ifthetransactionsucceedsandremainintheoriginalstate,ifthetransactionfails. 
3.Isolation:Everytransactionshouldoperateasifitistheonlytransactioninthesystem 
4.Durability:Onceatransactionhascompletedsuccessfully,theupdatedrows/recordsmustbeavailableforallothertransactionsonapermanentbasis 
ANSWER 
QUESTION 33
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisaDatabaseLock?Whatarethetypeoflocks? 
35 
QUESTION 
Databaselocktellatransaction,ifthedataiteminquestionsiscurrentlybeingusedbyothertransactions. 
1.SharedLock:Whenasharedlockisappliedondataitem,othertransactionscanonlyreadtheitem,butcan'twriteintoit. 
2.ExclusiveLock:Whenaexclusivelockisappliedondataitem,othertransactionscan'treadorwriteintothedataitem. 
ANSWER 
QUESTION 34
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisaCompositeKey? 
36 
QUESTION 
ACompositeprimarykeyisatypeofcandidatekey,whichrepresentsasetofcolumnswhosevaluesuniquelyidentifyeveryrowinatable. 
Forexample-if"Employee_ID"and"EmployeeName"inatableiscombinedtouniquelyidentifiesarowitscalledaCompositeKey. 
ANSWER 
QUESTION 35
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisaCompositePrimaryKey? 
37 
QUESTION 
ACompositeprimarykeyisasetofcolumnswhosevaluesuniquelyidentifyeveryrowinatable.Whatitmeansisthat,tablewhichcontainscompositeprimarykeywillbeindexedbasedoncolumnsspecifiedintheprimarykey. ThiskeywillbereferredinForeignKeytables. 
Forexample-ifcombinedeffectofcolumns,"Employee_ID"and"EmployeeName"inatableisrequiredtouniquelyidentifiesarow,itscalledaCompositePrimaryKey.Inthiscase,boththecolumnswillberepresentedasprimarykey. 
ANSWER 
QUESTION 36
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
DefineSQLInsertStatement? 
38 
QUESTION 
SQLINSERTstatementisusedtoaddrowstoatable.Forafullrowinsert,SQLQueryshouldstartwith―insertinto―statementfollowedbytablenameandvaluescommand,followedbythevaluesthatneedtobeinsertedintothetable.Insertcanbeusedinseveralways: 
1.Toinsertasinglecompleterow 
2.Toinsertasinglepartialrow 
ANSWER 
QUESTION 37
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
DefineSQLUpdateStatement? 
39 
QUESTION 
SQLUpdateisusedtoupdatedatainaroworsetofrowsspecifiedinthefiltercondition. 
ThebasicformatofanSQLUPDATEstatementis,UpdatecommandfollowedbytabletobeupdatedandSETcommandfollowedbycolumnnamesandtheirnewvaluesfollowedbyfilterconditionthatdetermineswhichrowsshouldbeupdated. 
ANSWER 
QUESTION 38
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatarewildcardsusedindatabaseforPatternMatching? 
40 
QUESTION 
SQLLikeoperatorisuserforpatternmatching.SQL'Like'commandtakesmoretimetoprocess.Sobeforeusinglikeoperator,considersuggestionsgivenbelowonwhenandwheretousewildcardsearch. 
1)Don'toverusewildcards.Ifanothersearchoperatorwilldo,useitinstead. 
2)Whenyoudousewildcards,trynottousethematthebeginningofthesearchpattern,unlessabsolutelynecessary.Searchpatternsthatbeginwithwildcardsaretheslowesttoprocess. 
3)Paycarefulattentiontotheplacementofthewildcardsymbols.Iftheyaremisplaced,youmightnotreturnthedatayouintended 
ANSWER 
QUESTION 39
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisCrossJoin? 
41 
QUESTION 
CrossJoinwillreturnallrecordswhereeachrowfromthefirsttableiscombinedwitheachrowfromthesecondtable. 
ANSWER 
QUESTION 40
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisaview? 
42 
QUESTION 
Viewsarevirtualtables.Unliketablesthatcontaindata,viewssimplycontainqueriesthatdynamicallyretrievedatawhenused. 
ANSWER 
QUESTION 41
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisamaterializedview? 
43 
QUESTION 
Materializedviewsisalsoaviewbutarediskbased.Materializedviewsgetupdatedonspecificduration,baseupontheintervalspecifiedinthequerydefinition.Wecanindexmaterializedview. 
ANSWER 
QUESTION 42
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whataretheadvantagesanddisadvantagesofviewsinadatabase? 
44 
QUESTION 
Advantages: 
1.Viewsdoesn'tstoredatainaphysicallocation. 
2.Viewcanbeusetohidesomeofthecolumnsfromthetable 
3.ViewscanprovideAccessRestriction,sincedatainsertion,updateanddeletionisnotpossibleontheview. 
Disadvantages: 
1.Whenatableisdropped,associatedviewbecomeirrelevant. 
2.Sinceviewarecreatedwhenaqueryrequestingdatafromviewistriggered,itsbitslow 
3.Whenviewsarecreatedforlargetables,itoccupymorememory. 
ANSWER 
QUESTION 43
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhendoyouuseUPDATE_STATISTICScommand? 
45 
QUESTION 
Thiscommandisusedwhenalargeprocessingofdatahasoccurred.Ifanylargeamountofdeletions,anymodifications,orBulkCopyintothetableshasoccurred,ithastoupdatetheindexestotakethesechangesintoaccount.UPDATE_STATISTICSupdatestheindexesonthesetablesaccordingly. 
ANSWER 
QUESTION 44
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisanIDENTITYcolumnininsertstatements? 
46 
QUESTION 
IDENTITYcolumnisusedintablecolumnstomakethatcolumnasAutoincrementalnumberorasurrogatekey. 
ANSWER 
QUESTION 45
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
HowwillIretrieveallrecordsofemployment1thoseshouldnotbepresentnemployment2? 
47 
QUESTION 
(Select*fromemployment2)-(Select*fromemployment1). 
ANSWER 
QUESTION 46
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhichTCP/IPportdoesSQLServerrunon?Howcanitbechanged? 
48 
QUESTION 
SQLServerrunsonport1433.ItcanbechangedfromtheNetworkUtilityTCP/IPproperties. 
ANSWER 
QUESTION 47
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisSQLServerAgent? 
49 
QUESTION 
SQLServeragentplaysanimportantroleintheday-to-daytasksofadatabaseadministrator(DBA).ItspurposeistoeasetheimplementationoftasksfortheDBA,withitsfull-functionschedulingengine,whichallowsyoutoscheduleyourownjobsandscripts. 
ANSWER 
QUESTION 48
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhichcommandusingQueryAnalyzerwillgiveyoutheversionofSQLserverandoperatingsystem? 
50 
QUESTION 
SELECTSERVERPROPERTY('productversion'),SERVERPROPERTY('productlevel')andSERVERPROPERTY('edition') 
ANSWER 
QUESTION 49
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
HowtocreaterecursivequeryinSQLServer? 
51 
QUESTION 
RecursivequerycanbecreateinSQLusingstoredprocedurebutyoucanalsouseCTE(Commontableexpression).ItmightbealsoworthaskingaboutperformanceasCTEisnotalwaysveryfast. 
ANSWER 
QUESTION 51
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisaconstraint? 
52 
QUESTION 
Constraintcanbeusedtospecifythelimitonthedatatypeoftable.Constraintcanbespecifiedwhilecreatingoralteringthetablestatement.Sampleofconstraintare. 
•NOTNULL. 
•CHECK. 
•DEFAULT. 
•UNIQUE. 
•PRIMARYKEY. 
•FOREIGNKEY. 
ANSWER 
QUESTION 51
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisAutoIncrement? 
53 
QUESTION 
Autoincrementkeywordallowstheusertocreateauniquenumbertobegeneratedwhenanewrecordisinsertedintothetable.AUTOINCREMENTkeywordcanbeusedinOracleandIDENTITYkeywordcanbeusedinSQLSERVER. 
MostlythiskeywordcanbeusedwheneverPRIMARYKEYisused. 
ANSWER 
QUESTION 52
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisDatawarehouse? 
54 
QUESTION 
Datawarehouseisacentralrepositoryofdatafrommultiplesourcesofinformation.Thosedataareconsolidated, transformedandmadeavailablefortheminingandonlineprocessing.WarehousedatahaveasubsetofdatacalledDataMarts. 
ANSWER 
QUESTION 53
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisuserdefinedfunctions? 
55 
QUESTION 
Userdefinedfunctionsarethefunctionswrittentousethatlogicwheneverrequired.Itisnotnecessarytowritethesamelogicseveraltimes.Instead,functioncanbecalledorexecutedwheneverneeded. 
ANSWER 
QUESTION 54
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatarealltypesofuserdefinedfunctions? 
56 
QUESTION 
Threetypesofuserdefinedfunctionsare. 
a.ScalarFunctions. 
b.InlineTablevaluedfunctions. 
c.Multistatementvaluedfunctions. 
ANSWER 
QUESTION 55
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatarealldifferenttypesofcollationsensitivity? 
57 
QUESTION 
Followingaredifferenttypesofcollationsensitivity-. 
•CaseSensitivity–AandaandBandb. 
•AccentSensitivity. 
•KanaSensitivity–JapaneseKanacharacters. 
•WidthSensitivity–Singlebytecharacteranddoublebytecharacter. 
ANSWER 
QUESTION 56
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisOnlineTransactionProcessing(OLTP)? 
58 
QUESTION 
OnlineTransactionProcessingorOLTPmanagestransactionbasedapplicationswhichcanbeusedfordataentryandeasyretrievalprocessingofdata.Thisprocessingmakeslikeeasieronsimplicityandefficiency.Itisfaster, moreaccurateresultsandexpenseswithrespecttoOTLP. 
Example–BankTransactionsonadailybasis. 
ANSWER 
QUESTION 57
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisanALIAScommand? 
59 
QUESTION 
ALIASnamecanbegiventoatableorcolumn.ThisaliasnamecanbereferredinWHEREclausetoidentifythetableorcolumn. 
Example-. 
Selectst.StudentID,Ex.Resultfromstudentst,ExamasExwherest.studentID=Ex.StudentID 
Here,streferstoaliasnameforstudenttableandExreferstoaliasnameforexamtable. 
ANSWER 
QUESTION 58
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatareaggregateandscalarfunctions? 
60 
QUESTION 
Aggregatefunctionsareusedtoevaluatemathematicalcalculationandreturnsinglevalues.Thiscanbecalculatedfromthecolumnsinatable.Scalarfunctionsreturnasinglevaluebasedontheinputvalue. 
Example-. 
Aggregate–max(),count–Calculatedwithrespecttonumeric. 
Scalar–UCASE(),NOW()–Calculatedwithrespecttostrings. 
ANSWER 
QUESTION 59
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Howcanyoucreateanemptytablefromanexistingtable? 
61 
QUESTION 
Select*intostudentcopyfromstudentwhere1=2 
Here,wearecopyingstudenttabletoanothertablewiththesamestructurewithnorowscopied. 
ANSWER 
QUESTION 60
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Howtofetchcommonrecordsfromtwotables? 
62 
QUESTION 
Commonrecordsresultsetcanbeachievedby-. 
SelectstudentIDfromstudent.<strong>INTERSECT</strong>SelectStudentIDfromExam 
ANSWER 
QUESTION 61
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Howtoselectuniquerecordsfromatable? 
63 
QUESTION 
SelectuniquerecordsfromatablebyusingDISTINCTkeyword. 
SelectDISTINCTStudentID,StudentNamefromStudent. 
ANSWER 
QUESTION 62
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatarethedifferentindexconfigurationsatablecanhave? 
64 
QUESTION 
Atablecanhaveoneofthefollowingindexconfigurations: 
1.Noindexes 
2.Aclusteredindex 
3.Aclusteredindexandmanynonclusteredindexes 
4.Anonclusteredindex 
5.Manynonclusteredindexes 
ANSWER 
QUESTION 63
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatarethepropertiesanddifferentTypesofSub-Queries? 
65 
QUESTION 
PropertiesofSub-Query 
a.Asub-querymustbeenclosedintheparenthesis. 
b.Asub-querymustbeputintherighthandofthecomparisonoperator,and 
c.Asub-querycannotcontainanORDER-BYclause. 
d.Aquerycancontainmorethanonesub-query. 
TypesofSub-Query 
e.Single-rowsub-query,wherethesub-queryreturnsonlyonerow. 
f.Multiple-rowsub-query,wherethesub-queryreturnsmultiplerows,.and 
g.Multiplecolumnsub-query,wherethesub-queryreturnsmultiplecolumns 
ANSWER 
QUESTION 64
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisSQLProfiler? 
66 
QUESTION 
SQLProfilerisagraphicaltoolthatallowssystemadministratorstomonitoreventsinaninstanceofMicrosoftSQLServer.YoucancaptureandsavedataabouteacheventtoafileorSQLServertabletoanalyzelater.Forexample,youcanmonitoraproductionenvironmenttoseewhichstoredproceduresarehamperingperformancesbyexecutingtooslowly. 
UseSQLProfilertomonitoronlytheeventsinwhichyouareinterested.Iftracesarebecomingtoolarge,youcanfilterthembasedontheinformationyouwant,sothatonlyasubsetoftheeventdataiscollected.Monitoringtoomanyeventsaddsoverheadtotheserverandthemonitoringprocessandcancausethetracefileortracetabletogrowverylarge,especiallywhenthemonitoringprocesstakesplaceoveralongperiodoftime. 
ANSWER 
QUESTION 65
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhataretheauthenticationmodesinSQLServer?Howcanitbechanged? 
67 
QUESTION 
WindowsmodeandMixedMode-SQLandWindows.TochangeauthenticationmodeinSQLServerclickStart, Programs,MicrosoftSQLServerandclickSQLEnterpriseManagertorunSQLEnterpriseManagerfromtheMicrosoftSQLServerprogramgroup.SelecttheserverthenfromtheToolsmenuselectSQLServerConfigurationProperties,andchoosetheSecuritypage. 
ANSWER 
QUESTION 66
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Canastoredprocedurecallitselforrecursivestoredprocedure?HowmuchlevelSPnestingispossible? 
68 
QUESTION 
Yes.BecauseTransact-SQLsupportsrecursion,youcanwritestoredproceduresthatcallthemselves.Recursioncanbedefinedasamethodofproblemsolvingwhereinthesolutionisarrivedatbyrepetitivelyapplyingittosubsetsoftheproblem.Acommonapplicationofrecursivelogicistoperformnumericcomputationsthatlendthemselvestorepetitiveevaluationbythesameprocessingsteps.StoredproceduresarenestedwhenonestoredprocedurecallsanotherorexecutesmanagedcodebyreferencingaCLRroutine,type,oraggregate.Youcanneststoredproceduresandmanagedcodereferencesupto32levels. 
ANSWER 
QUESTION 67
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisLogShipping? 
69 
QUESTION 
LogshippingistheprocessofautomatingthebackupofdatabaseandtransactionlogfilesonaproductionSQLserver,andthenrestoringthemontoastandbyserver.EnterpriseEditionsonlysupportslogshipping.Inlogshippingthetransactionallogfilefromoneserverisautomaticallyupdatedintothebackupdatabaseontheotherserver.Ifoneserverfails,theotherserverwillhavethesamedbandcanbeusedthisastheDisasterRecoveryplan.Thekeyfeatureoflogshippingisthatitwillautomaticallybackuptransactionlogsthroughoutthedayandautomaticallyrestorethemonthestandbyserveratdefinedinterval. 
ANSWER 
QUESTION 68
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Name3waystogetanaccuratecountofthenumberofrecordsinatable? 
70 
QUESTION 
SELECT*FROMtable1 
SELECTCOUNT(*)FROMtable1 
SELECTrowsFROMsysindexesWHEREid=OBJECT_ID(table1)ANDindid<2 
ANSWER 
QUESTION 69
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatdoesitmeantohaveQUOTED_IDENTIFIERON?WhataretheimplicationsofhavingitOFF? 
71 
QUESTION 
WhenSETQUOTED_IDENTIFIERisON,identifierscanbedelimitedbydoublequotationmarks,andliteralsmustbedelimitedbysinglequotationmarks.WhenSETQUOTED_IDENTIFIERisOFF,identifierscannotbequotedandmustfollowallTransact-SQLrulesforidentifiers. 
ANSWER 
QUESTION 70
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisthedifferencebetweenaLocalandaGlobaltemporarytable? 
72 
QUESTION 
1.Alocaltemporarytableexistsonlyforthedurationofaconnectionor,ifdefinedinsideacompoundstatement,forthedurationofthecompoundstatement. 
2.Aglobaltemporarytableremainsinthedatabasepermanently,buttherowsexistonlywithinagivenconnection. Whenconnectionisclosed,thedataintheglobaltemporarytabledisappears.However,thetabledefinitionremainswiththedatabaseforaccesswhendatabaseisopenednexttime. 
ANSWER 
QUESTION 71
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
HowGlobaltemporarytablesarerepresentedanditsscope? 
73 
QUESTION 
Globaltemporarytablesarerepresentedwith##beforethetablename.Scopewillbetheoutsidethesessionwhereaslocaltemporarytablesareinsidethesession.SessionIDcanbefoundusing@@SPID. 
ANSWER 
QUESTION 72
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatistheSTUFFfunctionandhowdoesitdifferfromtheREPLACEfunction? 
74 
QUESTION 
STUFFfunctionisusedtooverwriteexistingcharacters.Usingthissyntax,STUFF(string_expression,start,length, replacement_characters),string_expressionisthestringthatwillhavecharacterssubstituted,startisthestartingposition,lengthisthenumberofcharactersinthestringthataresubstituted,andreplacement_charactersarethenewcharactersinterjectedintothestring.REPLACEfunctiontoreplaceexistingcharactersofalloccurrences. UsingthesyntaxREPLACE(string_expression,search_string,replacement_string),whereeveryincidenceofsearch_stringfoundinthestring_expressionwillbereplacedwithreplacement_string. 
ANSWER 
QUESTION 73
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisCHECKConstraint? 
75 
QUESTION 
ACHECKconstraintisusedtolimitthevaluesthatcanbeplacedinacolumn.Thecheckconstraintsareusedtoenforcedomainintegrity. 
ANSWER 
QUESTION 74
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisthedifferencebetweenUNIONandUNIONALL? 
76 
QUESTION 
UNIONstatementismainlyusedtocombinethetablesincludingtheduplicaterowsandUNIONALLcombinebutdoesnotlookforduplicaterows.Withthis,UNIONALLwillbeveryfasterthanUNIONstatements. 
ANSWER 
QUESTION 75
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisNOTNULLConstraint? 
77 
QUESTION 
ANOTNULLconstraintenforcesthatthecolumnwillnotacceptnullvalues.Thenotnullconstraintsareusedtoenforcedomainintegrity,asthecheckconstraints. 
ANSWER 
QUESTION 76
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Howtoget@@ERRORand@@ROWCOUNTatthesametime? 
78 
QUESTION 
If@@RowcountischeckedafterErrorcheckingstatementthenitwillhave0asthevalueof@@Recordcountasitwouldhavebeenreset.Andif@@Recordcountischeckedbeforetheerror-checkingstatementthen@@Errorwouldgetreset.Toget@@errorand@@rowcountatthesametimedobothinsamestatementandstoretheminlocalvariable. 
SELECT@RC=@@ROWCOUNT,@ER=@@ERROR 
ANSWER 
QUESTION 77
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisaScheduledJobsorWhatisaScheduledTasks? 
79 
QUESTION 
Scheduledtasksletuserautomateprocessesthatrunonregularorpredictablecycles.Usercanscheduleadministrativetasks,suchascubeprocessing,torunduringtimesofslowbusinessactivity.UsercanalsodeterminetheorderinwhichtasksrunbycreatingjobstepswithinaSQLServerAgentjob.E.g.backupdatabase,UpdateStatsofTables.Jobstepsgiveusercontroloverflowofexecution.Ifonejobfails,usercanconfigureSQLServerAgenttocontinuetoruntheremainingtasksortostopexecution. 
ANSWER 
QUESTION 78
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisatablecalled,ifithasneitherClusternorNon-clusterIndex?Whatisitusedfor? 
80 
QUESTION 
UnindexedtableorHeap.MicrosoftPressBooksandBookonLine(BOL)refersitasHeap.Aheapisatablethatdoesnothaveaclusteredindexand,therefore,thepagesarenotlinkedbypointers.TheIAMpagesaretheonlystructuresthatlinkthepagesinatabletogether.Unindexedtablesaregoodforfaststoringofdata.Manytimesitisbettertodropallindexesfromtableandthendobulkofinsertsandtorestorethoseindexesafterthat. 
ANSWER 
QUESTION 79
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
CanSQLServerslinkedtootherserverslikeOracle? 
81 
QUESTION 
SQLServercanbelinkedtoanyserverprovidedithasOLE-DBproviderfromMicrosofttoallowalink.E.g.OraclehasanOLE-DBproviderfororaclethatMicrosoftprovidestoadditaslinkedservertoSQLServergroup. 
ANSWER 
QUESTION 80
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisBCP?Whendoesitused? 
82 
QUESTION 
BulkCopyisatoolusedtocopyhugeamountofdatafromtablesandviews.BCPdoesnotcopythestructuressameassourcetodestination.BULKINSERTcommandhelpstoimportadatafileintoadatabasetableorviewinauser-specifiedformat. 
ANSWER 
QUESTION 81
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Howtoimplementone-to-one,one-to-manyandmany-to-manyrelationshipswhiledesigningtables? 
83 
QUESTION 
One-to-Onerelationshipcanbeimplementedasasingletableandrarelyastwotableswithprimaryandforeignkeyrelationships.One-to-Manyrelationshipsareimplementedbysplittingthedataintotwotableswithprimarykeyandforeignkeyrelationships.Many-to-Manyrelationshipsareimplementedusingajunctiontablewiththekeysfromboththetablesformingthecompositeprimarykeyofthejunctiontable. 
ANSWER 
QUESTION 82
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisanexecutionplan?Whenwouldyouuseit?Howwouldyouviewtheexecutionplan? 
84 
QUESTION 
AnexecutionplanisbasicallyaroadmapthatgraphicallyortextuallyshowsthedataretrievalmethodschosenbytheSQLServerqueryoptimizerforastoredprocedureorad-hocqueryandisaveryusefultoolforadevelopertounderstandtheperformancecharacteristicsofaqueryorstoredproceduresincetheplanistheonethatSQLServerwillplaceinitscacheandusetoexecutethestoredprocedureorquery.FromwithinQueryAnalyzerisanoptioncalled"ShowExecutionPlan"(locatedontheQuerydrop-downmenu).Ifthisoptionisturnedonitwilldisplayqueryexecutionplaninseparatewindowwhenqueryisranagain. 
ANSWER 
QUESTION 83
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatarethetwoauthenticationmodesinSQLServer? 
85 
QUESTION 
Therearetwoauthenticationmodes– 
•WindowsMode 
•MixedMode 
ModescanbechangedbyselectingthetoolsmenuofSQLServerconfigurationpropertiesandchoosesecuritypage. 
ANSWER 
QUESTION 84
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisCOALESCEinSQLServer? 
86 
QUESTION 
COALESCEisusedtoreturnfirstnon-nullexpressionwithinthearguments.Thisfunctionisusedtoreturnanon- nullfrommorethanonecolumninthearguments. 
Example– 
SelectCOALESCE(empno,empname,salary)fromemployee; 
ANSWER 
QUESTION 85
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
HowexceptionscanbehandledinSQLServerProgramming? 
87 
QUESTION 
ExceptionsarehandledusingTRY—-CATCHconstructsanditishandlesbywritingscriptsinsidetheTRYblockanderrorhandlingintheCATCHblock. 
ANSWER 
QUESTION 86
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisthepurposeofFLOORfunction? 
88 
QUESTION 
FLOORfunctionisusedtoroundupanon-integervaluetothepreviousleastinteger.ExampleisgivenFLOOR(6.7) 
Returns6. 
ANSWER 
QUESTION 87
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Canwechecklocksindatabase?Ifso,howcanwedothislockcheck? 
89 
QUESTION 
Yes,wecanchecklocksinthedatabase.Itcanbeachievedbyusingin-builtstoredprocedurecalledsp_lock. 
ANSWER 
QUESTION 88
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatistheuseofSIGNfunction? 
90 
QUESTION 
SIGNfunctionisusedtodeterminewhetherthenumberspecifiedisPositive,NegativeandZero.Thiswillreturn+1,-1or0. 
Example:SIGN(-35)returns-1 
ANSWER 
QUESTION 89
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
HowistheSUBSTRkeywordusedinSQL? 
91 
QUESTION 
SUBSTRisusedforstringmanipulationwithcolumnname,firstpositionandstringlengthusedasarguments.E.g. 
SUBSTR(NAME,13)referstothefirstthreecharactersinthecolumnNAME. 
ANSWER 
QUESTION 90
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisaNULLvalue?WhataretheprosandconsofusingNULLS? 
92 
QUESTION 
ANULLvaluetakesuponebyteofstorageandindicatesthatavalueisnotpresentasopposedtoaspaceorzerovalue.It'stheDB2equivalentofTBDonanorganizationalchartandoftencorrectlyportraysabusinesssituation. Unfortunately,itrequiresextracodingforanapplicationprogramtohandlethissituation. 
ANSWER 
QUESTION 91
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisasynonym?Howisitused? 
93 
QUESTION 
Asynonymisusedtoreferenceatableorviewbyanothername.Theothernamecanthenbewrittenintheapplicationcodepointingtotesttablesinthedevelopmentstageandtoproductionentitieswhenthecodeismigrated.ThesynonymislinkedtotheAUTHIDthatcreatedit. 
ANSWER 
QUESTION 92
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisaCartesianproduct? 
94 
QUESTION 
ACartesianproductresultsfromafaultyquery.Itisarowintheresultsforeverycombinationinthejointables. 
ANSWER 
QUESTION 93
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisatuple? 
95 
QUESTION 
StaticSQLiscompiledandoptimizedpriortoitsexecution;dynamiciscompiledandoptimizedduringexecution. 
ANSWER 
QUESTION 94
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Whatisreferentialintegrity? 
96 
QUESTION 
Referentialintegrityreferstotheconsistencythatmustbemaintainedbetweenprimaryandforeignkeys,i.e.everyforeignkeyvaluemusthaveacorrespondingprimarykeyvalue. 
ANSWER 
QUESTION 95
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
What’sthemaximumsizeofarow? 
97 
QUESTION 
8060bytes. 
ANSWER 
QUESTION 96
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
HowtochangeDatabasenameinSQLserver? 
98 
QUESTION 
Usethefollowingcode: 
SupportedinSQLserver2000and2005 
Execsp_renamedb―test‖,―test1‖ 
SupportedinSQLServer2005andlaterversion 
ALTERDatabase―test1‖ModifyName=―test‖ 
ANSWER 
QUESTION 97
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisaCursor? 
99 
QUESTION 
AdatabaseCursorisacontrolwhichenablestraversalovertherowsorrecordsinthetable.Thiscanbeviewedasapointertoonerowinasetofrows.Cursorisverymuchusefulfortraversingsuchasretrieval,additionandremovalofdatabaserecords. 
ANSWER 
QUESTION 98
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatareMagicTablesinSQLServer? 
100 
QUESTION 
InsertandDeletetablesarecreatedwhenthetriggerisfiredforanyDMLcommand.ThosetablesarecalledMagicTablesinSQLServer.Thesemagictablesareusedinsidethetriggersfordatatransaction. 
ANSWER 
QUESTION 99
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
WhatisISNULL()operator? 
101 
QUESTION 
ISNULLfunctionisusedtocheckwhethervaluegivenisNULLornotNULLinsqlserver.ThisfunctionalsoprovidestoreplaceavaluewiththeNULL. 
ANSWER 
QUESTION 100
For the hottest SQL jobs, please visit www.hirist.com 
hirist 
.com 
Resources 
102 
http://www.itechaleart.com/2013/05/top-50-sql-question-answers_11.html 
https://www.katieandemil.com/sql-interview-questions-and- answers?tab=article#Question 4 
http://www.dwbiconcepts.com/tutorial/24-interview-questions/190-top-20-sql- interview-questions-with-answers.html 
http://a4academics.com/interview-questions/53-database-and-sql/411-sql- interview-questions-and-answers-database 
http://narendra86.blogspot.com/2013/10/top-80-sql-query-interview- questions.html 
http://crackaninterview.com/sql-queries-interview-questions-answers/ 
http://career.guru99.com/top-50-sql-question-answers/ 
http://www.indiabix.com/technical/sql-server-common-questions/ 
http://career.guru99.com/top-50-sql-server-questions-answers/ 
http://www.ittestpapers.com/sql-interview-questions(25-50).html 
http://www.dotnetfunda.com/interviews/cat/8/sql-server 
http://www.careerride.com/SQLServer-Interview-Questions.aspx
www.hirist.com 
SQL 
TOP 100 
INTERVIEW QUESTIONS & ANSWERS

More Related Content

What's hot (20)

PPTX
Sql queries presentation
NITISH KUMAR
 
PDF
Introduction to SQL
Ram Kedem
 
PDF
Exception handling in plsql
Arun Sial
 
PPTX
Introduction to SQL
Ehsan Hamzei
 
PPT
Introduction to structured query language (sql)
Sabana Maharjan
 
PPT
Mysql
TSUBHASHRI
 
PDF
Alter table command
ravikhandelwal41
 
PPTX
introdution to SQL and SQL functions
farwa waqar
 
PPTX
Sql commands
Pooja Dixit
 
PPTX
Normalization
Salman Memon
 
PPT
SQL subquery
Vikas Gupta
 
PPTX
Oracle
JIGAR MAKHIJA
 
PPTX
Nosql databases
ateeq ateeq
 
PPT
SQL.ppt
Ranjit273515
 
PDF
SQL
kaushal123
 
PDF
MySQL for beginners
Saeid Zebardast
 
DOCX
Top 40 sql queries for testers
tlvd
 
PDF
SQL - RDBMS Concepts
WebStackAcademy
 
DOCX
Index in sql server
Durgaprasad Yadav
 
PPT
PL/SQL Introduction and Concepts
Bharat Kalia
 
Sql queries presentation
NITISH KUMAR
 
Introduction to SQL
Ram Kedem
 
Exception handling in plsql
Arun Sial
 
Introduction to SQL
Ehsan Hamzei
 
Introduction to structured query language (sql)
Sabana Maharjan
 
Mysql
TSUBHASHRI
 
Alter table command
ravikhandelwal41
 
introdution to SQL and SQL functions
farwa waqar
 
Sql commands
Pooja Dixit
 
Normalization
Salman Memon
 
SQL subquery
Vikas Gupta
 
Nosql databases
ateeq ateeq
 
SQL.ppt
Ranjit273515
 
MySQL for beginners
Saeid Zebardast
 
Top 40 sql queries for testers
tlvd
 
SQL - RDBMS Concepts
WebStackAcademy
 
Index in sql server
Durgaprasad Yadav
 
PL/SQL Introduction and Concepts
Bharat Kalia
 

Similar to Top 100 SQL Interview Questions and Answers (20)

PDF
Dbms interview questions
Soba Arjun
 
PDF
MSSQL_Book.pdf
DubsmashTamizhan
 
PDF
Dbms interview questions s.pdf
Shivani139202
 
DOCX
Sql interview q&a
Syed Shah
 
PDF
Dbms interview questions
ambika93
 
PDF
SQL Interview Questions - InterviewBit.pdf
Aniket223719
 
PDF
Sql interview-book
Vipul Wankar
 
PDF
Sql interview-book
Vipul Wankar
 
PPTX
Sql interview question part 5
kaashiv1
 
PPTX
Ebook5
kaashiv1
 
PDF
DBMS Interview Questions PDF By ScholarHat
Scholarhat
 
PPTX
SQL.pptx
AmitDas125851
 
PDF
4.Database Management System.pdf
Export Promotion Bureau
 
PPTX
Mastering-SQL-Your-Guide-to-Database-Development.pptx
Tpoint Tech || Online Education
 
PPTX
Java class 8
Edureka!
 
PPTX
Relational Database Management System
Mian Abdul Raheem
 
PDF
DBMS Interview Questions PDF By ScholarHat
Scholarhat
 
DOCX
Viva voce
Sadhana Sreekanth
 
PPT
Lecture-9-10-11-12(a-b).ppt modern database
mee23nu
 
PDF
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
PreetiKushwah6
 
Dbms interview questions
Soba Arjun
 
MSSQL_Book.pdf
DubsmashTamizhan
 
Dbms interview questions s.pdf
Shivani139202
 
Sql interview q&a
Syed Shah
 
Dbms interview questions
ambika93
 
SQL Interview Questions - InterviewBit.pdf
Aniket223719
 
Sql interview-book
Vipul Wankar
 
Sql interview-book
Vipul Wankar
 
Sql interview question part 5
kaashiv1
 
Ebook5
kaashiv1
 
DBMS Interview Questions PDF By ScholarHat
Scholarhat
 
SQL.pptx
AmitDas125851
 
4.Database Management System.pdf
Export Promotion Bureau
 
Mastering-SQL-Your-Guide-to-Database-Development.pptx
Tpoint Tech || Online Education
 
Java class 8
Edureka!
 
Relational Database Management System
Mian Abdul Raheem
 
DBMS Interview Questions PDF By ScholarHat
Scholarhat
 
Lecture-9-10-11-12(a-b).ppt modern database
mee23nu
 
Complete SQL Tutorial In Hindi By Rishabh Mishra (Basic to Advance).pdf
PreetiKushwah6
 
Ad

Recently uploaded (20)

PDF
One Stop Career Solution to Grow Fast – MajhiNaukri.com
Reeshna Prajeesh
 
PPTX
Chemistry-Presentation-The-World-of-Silicates.pptx
swethasejal123
 
PPTX
Plant Growth and Development-Part I, ppt.pptx
7300511143
 
PDF
2025 - KPT - The best people are those you can't buy - Beata Mosór.pdf
bmosor
 
PPTX
Learn AI in Software Testing - Venkatesh (Rahul Shetty)
Venkatesh (Rahul Shetty)
 
PPTX
21st-Literature.pptxjsududhshsusushshsusuhsgsysh
JohnVJLBellen
 
PDF
Smart Steps to Choose the Right Career Path After 12th or Graduation
Reeshna Prajeesh
 
PDF
Buy Twitter Accounts_ Boost Your Brand and Reach in 2025 - Copy - Copy.pdf
Buy Old Twitter Accounts-100% Secure Aged With Followers
 
PDF
Certificate PMP kamel_rodrigue_adda_1879235
kamelard
 
PPTX
Matter_in_Our_Surroundings_Lesson_Plan.pptx
devendrabele16
 
PPT
bgasslideshow-141208014132-conversion-gate02 (1).ppt
mninspection1
 
PPTX
一比一原版(UWS毕业证)西苏格兰大学毕业证如何办理
Taqyea
 
PPTX
Water managements in Fruit Crops for PG Students of Agriculture.pptx
7300511143
 
PPTX
Mastering the Cloud with AWS: A Deep Dive into Amazon Web Services
cbitssnavjotdm
 
PDF
Stefano_Zorzi_Curriculum_short_english.pdf
stefanogeomzorzi
 
PDF
VisionIAS - UPSC GS Paper I Question Paper 2025 with Answer Key.pdf
saxenashubh937
 
PPTX
Cover-Letter-Writing-Workshop Slideshow Presentation.pptx
nmorales22
 
PPTX
A Guide for a Winning Interview July 2025
Bruce Bennett
 
PPTX
100%复刻西班牙学历认证范本科尔多瓦大学成绩单防伪UCO学费单
Taqyea
 
PDF
Top Benefits of Posting Jobs on a Job Portal with Formwalaa.in
Reeshna Prajeesh
 
One Stop Career Solution to Grow Fast – MajhiNaukri.com
Reeshna Prajeesh
 
Chemistry-Presentation-The-World-of-Silicates.pptx
swethasejal123
 
Plant Growth and Development-Part I, ppt.pptx
7300511143
 
2025 - KPT - The best people are those you can't buy - Beata Mosór.pdf
bmosor
 
Learn AI in Software Testing - Venkatesh (Rahul Shetty)
Venkatesh (Rahul Shetty)
 
21st-Literature.pptxjsududhshsusushshsusuhsgsysh
JohnVJLBellen
 
Smart Steps to Choose the Right Career Path After 12th or Graduation
Reeshna Prajeesh
 
Buy Twitter Accounts_ Boost Your Brand and Reach in 2025 - Copy - Copy.pdf
Buy Old Twitter Accounts-100% Secure Aged With Followers
 
Certificate PMP kamel_rodrigue_adda_1879235
kamelard
 
Matter_in_Our_Surroundings_Lesson_Plan.pptx
devendrabele16
 
bgasslideshow-141208014132-conversion-gate02 (1).ppt
mninspection1
 
一比一原版(UWS毕业证)西苏格兰大学毕业证如何办理
Taqyea
 
Water managements in Fruit Crops for PG Students of Agriculture.pptx
7300511143
 
Mastering the Cloud with AWS: A Deep Dive into Amazon Web Services
cbitssnavjotdm
 
Stefano_Zorzi_Curriculum_short_english.pdf
stefanogeomzorzi
 
VisionIAS - UPSC GS Paper I Question Paper 2025 with Answer Key.pdf
saxenashubh937
 
Cover-Letter-Writing-Workshop Slideshow Presentation.pptx
nmorales22
 
A Guide for a Winning Interview July 2025
Bruce Bennett
 
100%复刻西班牙学历认证范本科尔多瓦大学成绩单防伪UCO学费单
Taqyea
 
Top Benefits of Posting Jobs on a Job Portal with Formwalaa.in
Reeshna Prajeesh
 
Ad

Top 100 SQL Interview Questions and Answers

  • 1. hirist .com www.hirist.com SQL TOP 100 INTERVIEW QUESTIONS & ANSWERS
  • 2. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisDBMS? 2 QUESTION ADatabaseManagementSystem(DBMS)isaprogramthatcontrolscreation,maintenanceanduseofadatabase. DBMScanbetermedasFileManagerthatmanagesdatainadatabaseratherthansavingitinfilesystems. ANSWER QUESTION 1
  • 3. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisRDBMS? 3 QUESTION RDBMSstandsforRelationalDatabaseManagementSystem.RDBMSstorethedataintothecollectionoftables, whichisrelatedbycommonfieldsbetweenthecolumnsofthetable.Italsoprovidesrelationaloperatorstomanipulatethedatastoredintothetables. Example:SQLServer. ANSWER QUESTION 2
  • 4. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisSQL? 4 QUESTION SQLstandsforStructuredQueryLanguage,anditisusedtocommunicatewiththeDatabase.Thisisastandardlanguageusedtoperformtaskssuchasretrieval,updation,insertionanddeletionofdatafromadatabase. StandardSQLCommandsareSelect. ANSWER QUESTION 3
  • 5. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisaDatabase? 5 QUESTION Databaseisnothingbutanorganizedformofdataforeasyaccess,storing,retrievalandmanagingofdata.Thisisalsoknownasstructuredformofdatawhichcanbeaccessedinmanyways. Example:SchoolManagementDatabase,BankManagementDatabase. ANSWER QUESTION 4
  • 6. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhataretablesandFields? 6 QUESTION AtableisasetofdatathatareorganizedinamodelwithColumnsandRows.Columnscanbecategorizedasvertical,andRowsarehorizontal.Atablehasspecifiednumberofcolumncalledfieldsbutcanhaveanynumberofrowswhichiscalledrecord. Example:. Table:Employee. Field:EmpID,EmpName,DateofBirth. Data:201456,David,11/15/1960. ANSWER QUESTION 5
  • 7. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisaprimarykey? 7 QUESTION Aprimarykeyisacombinationoffieldswhichuniquelyspecifyarow.Thisisaspecialkindofuniquekey,andithasimplicitNOTNULLconstraint.Itmeans,PrimarykeyvaluescannotbeNULL. ANSWER QUESTION 6
  • 8. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisauniquekey? 8 QUESTION AUniquekeyconstraintuniquelyidentifiedeachrecordinthedatabase.Thisprovidesuniquenessforthecolumnorsetofcolumns. APrimarykeyconstrainthasautomaticuniqueconstraintdefinedonit.Butnot,inthecaseofUniqueKey. Therecanbemanyuniqueconstraintdefinedpertable,butonlyonePrimarykeyconstraintdefinedpertable. ANSWER QUESTION 7
  • 9. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisaforeignkey? 9 QUESTION Aforeignkeyisonetablewhichcanberelatedtotheprimarykeyofanothertable.Relationshipneedstobecreatedbetweentwotablesbyreferencingforeignkeywiththeprimarykeyofanothertable. ANSWER QUESTION 8
  • 10. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatarethetypesofjoinandexplaineach? 10 QUESTION Therearevarioustypesofjoinwhichcanbeusedtoretrievedataanditdependsontherelationshipbetweentables. InnerJoin:Innerjoinreturnrowswhenthereisatleastonematchofrowsbetweenthetables. RightJoin:RightjoinreturnrowswhicharecommonbetweenthetablesandallrowsofRighthandsidetable. Simply,itreturnsalltherowsfromtherighthandsidetableeventhoughtherearenomatchesinthelefthandsidetable. LeftJoin:LeftjoinreturnrowswhicharecommonbetweenthetablesandallrowsofLefthandsidetable.Simply,itreturnsalltherowsfromLefthandsidetableeventhoughtherearenomatchesintheRighthandsidetable. FullJoin:Fulljoinreturnrowswhentherearematchingrowsinanyoneofthetables.Thismeans,itreturnsalltherowsfromthelefthandsidetableandalltherowsfromtherighthandsidetable. ANSWER QUESTION 9
  • 11. For the hottest SQL jobs, please visit www.hirist.com hirist .com Explainanouterjoin? 11 QUESTION Anouterjoinincludesrowsfromtableswhentherearenomatchingvaluesinthetables. ANSWER QUESTION 10
  • 12. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisnormalization? 12 QUESTION Normalizationistheprocessofminimizingredundancyanddependencybyorganizingfieldsandtableofadatabase.ThemainaimofNormalizationistoadd,deleteormodifyfieldthatcanbemadeinasingletable. ANSWER QUESTION 11
  • 13. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisDenormalization? 13 QUESTION DeNormalizationisatechniqueusedtoaccessthedatafromhighertolowernormalformsofdatabase.Itisalsoprocessofintroducingredundancyintoatablebyincorporatingdatafromtherelatedtables. ANSWER QUESTION 12
  • 14. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatareallthedifferentnormalizations? 14 QUESTION Thenormalformscanbedividedinto4forms,andtheyareexplainedbelow-. FirstNormalForm(1NF):Thisshouldremovealltheduplicatecolumnsfromthetable.Creationoftablesfortherelateddataandidentificationofuniquecolumns. SecondNormalForm(2NF):Meetingallrequirementsofthefirstnormalform.PlacingthesubsetsofdatainseparatetablesandCreationofrelationshipsbetweenthetablesusingprimarykeys. ThirdNormalForm(3NF):Thisshouldmeetallrequirementsof2NF.Removingthecolumnswhicharenotdependentonprimarykeyconstraints. FourthNormalForm(4NF):Meetingalltherequirementsofthirdnormalformanditshouldnothavemulti- valueddependencies. ANSWER QUESTION 13
  • 15. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisanIndex?Whatareallthedifferenttypesofindexes? 15 QUESTION Anindexisperformancetuningmethodofallowingfasterretrievalofrecordsfromthetable.Anindexcreatesanentryforeachvalueanditwillbefastertoretrievedata. Thisindexingdoesnotallowthefieldtohaveduplicatevaluesifthecolumnisuniqueindexed.Uniqueindexcanbeappliedautomaticallywhenprimarykeyisdefined. ClusteredIndex:Thistypeofindexreordersthephysicalorderofthetableandsearchbasedonthekeyvalues. Eachtablecanhaveonlyoneclusteredindex. NonClusteredIndex:NonClusteredIndexdoesnotalterthephysicalorderofthetableandmaintainslogicalorderofdata.Eachtablecanhave999nonclusteredindexes. ANSWER QUESTION 14
  • 16. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisarelationshipandwhatarethey? 16 QUESTION DatabaseRelationshipisdefinedastheconnectionbetweenthetablesinadatabase.Therearevariousdatabasingrelationships,andtheyareasfollows:. OnetoOneRelationship. OnetoManyRelationship. ManytoOneRelationship. Self-ReferencingRelationship. ANSWER QUESTION 15
  • 17. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisaquery? 17 QUESTION ADBqueryisacodewritteninordertogettheinformationbackfromthedatabase.Querycanbedesignedinsuchawaythatitmatchedwithourexpectationoftheresultset.Simply,aquestiontotheDatabase. ANSWER QUESTION 16
  • 18. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatissubquery?Whatarethetypesofsubquery? 18 QUESTION Asubqueryisaquerywithinanotherquery.Theouterqueryiscalledasmainquery,andinnerqueryiscalledsubquery.SubQueryisalwaysexecutedfirst,andtheresultofsubqueryispassedontothemainquery. Therearetwotypesofsubquery–CorrelatedandNon-Correlated. Acorrelatedsubquerycannotbeconsideredasindependentquery,butitcanreferthecolumninatablelistedintheFROMthelistofthemainquery. ANon-Correlatedsubquerycanbeconsideredasindependentqueryandtheoutputofsubqueryaresubstitutedinthemainquery. ANSWER QUESTION 17
  • 19. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisatrigger? 19 QUESTION ADBtriggerisacodeorprogramsthatautomaticallyexecutewithresponsetosomeeventonatableorviewinadatabase.Mainly,triggerhelpstomaintaintheintegrityofthedatabase. Example:Whenanewstudentisaddedtothestudentdatabase,newrecordsshouldbecreatedintherelatedtableslikeExam,ScoreandAttendancetables. ANSWER QUESTION 18
  • 20. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatarethetypesofTriggers? 20 QUESTION Therearefourtypesoftriggersandtheyare: •Insert •Delete •Update •Insteadof ANSWER QUESTION 19
  • 21. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisthedifferencebetweenDELETETRUNCATEandDROPcommands? 21 QUESTION DELETEcommandisusedtoremoverowsfromthetable,andWHEREclausecanbeusedforconditionalsetofparameters.CommitandRollbackcanbeperformedafterdeletestatement. TRUNCATEremovesallrowsfromthetable.Truncateoperationcannotberolledback. Dropcommandisusedtodropthetableorkeyslikeprimary,foreignfromatable. ANSWER QUESTION 20
  • 22. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisdataIntegrity? 22 QUESTION DataIntegritydefinestheaccuracyandconsistencyofdatastoredinadatabase.Itcanalsodefineintegrityconstraintstoenforcebusinessrulesonthedatawhenitisenteredintotheapplicationordatabase. ANSWER QUESTION 21
  • 23. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatiscollation? 23 QUESTION Collationisdefinedassetofrulesthatdeterminehowcharacterdatacanbesortedandcompared.ThiscanbeusedtocompareAand,otherlanguagecharactersandalsodependsonthewidthofthecharacters. ASCIIvaluecanbeusedtocomparethesecharacterdata. ANSWER QUESTION 22
  • 24. For the hottest SQL jobs, please visit www.hirist.com hirist .com AdvantagesandDisadvantagesofStoredProcedure? 24 QUESTION Storedprocedurecanbeusedasamodularprogramming–meanscreateonce,storeandcallforseveraltimeswheneverrequired.Thissupportsfasterexecutioninsteadofexecutingmultiplequeries.Thisreducesnetworktrafficandprovidesbettersecuritytothedata. DisadvantageisthatitcanbeexecutedonlyintheDatabaseandutilizesmorememoryinthedatabaseserver. ANSWER QUESTION 23
  • 25. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisSQLInjection? 25 QUESTION SQLInjectionisoneofthetechniquesusesbyhackerstohackawebsitebyinjectingSQLcommandsindatafields. ANSWER QUESTION 24
  • 26. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisthedifferencebetweenaHAVINGCLAUSEandaWHERECLAUSE? 26 QUESTION Theyspecifyasearchconditionforagrouporanaggregate.ButthedifferenceisthatHAVINGcanbeusedonlywiththeSELECTstatement.HAVINGistypicallyusedinaGROUPBYclause.WhenGROUPBYisnotused, HAVINGbehaveslikeaWHEREclause.HavingClauseisbasicallyusedonlywiththeGROUPBYfunctioninaquerywhereasWHEREClauseisappliedtoeachrowbeforetheyarepartoftheGROUPBYfunctioninaquery. ANSWER QUESTION 25
  • 27. For the hottest SQL jobs, please visit www.hirist.com hirist .com Howwouldapplydaterangefilter? 27 QUESTION a.Youcanusesimplecondition>=and<=orsimilarorusebetween/andbutthetrickistoknowyourexactdatatype. b.Sometimesdatefieldscontaintimeandthatiswherethequerycangowrongsoitisrecommendedtousesomedaterelatedfunctionstoremovethetimeissue.InSQLServercommonfunctiontodothatisdatedifffunction. c.Youalsohavetobeawareofdifferenttimezonesandservertimezone. d.Toincreasequeryperformanceyoumaystillwanttousebetweenhoweveryoushouldbeawareofproperformatyoushoulduseifnotitmightmisbehaveduringfiltering. ANSWER QUESTION 26
  • 28. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisthedifferencebetweenJOINandUNION? 28 QUESTION SQLJOINallowsusto―lookup‖recordsonothertablebasedonthegivenconditionsbetweentwotables.Forexample,ifwehavethedepartmentIDofeachemployee,thenwecanusethisdepartmentIDoftheemployeetabletojoinwiththedepartmentIDofdepartmenttabletolookupdepartmentnames. UNIONoperationallowsustoadd2similardatasetstocreateresultingdatasetthatcontainsallthedatafromthesourcedatasets.Uniondoesnotrequireanyconditionforjoining.Forexample,ifyouhave2employeetableswithsamestructure,youcanUNIONthemtocreateoneresultsetthatwillcontainalltheemployeesfrombothofthetables. SELECT*FROMEMP1 UNION SELECT*FROMEMP2; ANSWER QUESTION 27
  • 29. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisthedifferenceamongUNION,MINUSandINTERSECT? 29 QUESTION UNIONcombinestheresultsfrom2tablesandeliminatesduplicaterecordsfromtheresultset. MINUSoperatorwhenusedbetween2tables,givesusalltherowsfromthefirsttableexcepttherowswhicharepresentinthesecondtable. INTERSECToperatorreturnsusonlythematchingorcommonrowsbetween2resultsets. ANSWER QUESTION 28
  • 30. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisSelfJoinandwhyisitrequired? 30 QUESTION SelfJoinistheactofjoiningonetablewithitself.SelfJoinisoftenveryusefultoconvertahierarchicalstructureintoaflatstructure ANSWER QUESTION 29
  • 31. For the hottest SQL jobs, please visit www.hirist.com hirist .com HowcanwetransposeatableusingSQL(changingrowstocolumnorvice-versa)? 31 QUESTION TheusualwaytodoitinSQListouseCASEstatementorDECODEstatement. ANSWER QUESTION 30
  • 32. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatarethedifferencesamongROWNUM,RANKandDENSE_RANK? 32 QUESTION ROW_NUMBERassignscontiguous,uniquenumbersfrom1..Ntoaresultset. RANKdoesnotassignuniquenumbers—nordoesitassigncontiguousnumbers.Iftworecordstieforsecondplace,norecordwillbeassignedthe3rdrankasnoonecameinthird,accordingtoRANK. DENSE_RANK,likeRANK,doesnotassignuniquenumbers,butitdoesassigncontiguousnumbers.Eventhoughtworecordstiedforsecondplace,thereisathird-placerecord. ANSWER QUESTION 31
  • 33. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisadatabasetransaction? 33 QUESTION Databasetransactiontakedatabasefromoneconsistentstatetoanother.Attheendofthetransactionthesystemmustbeinthepriorstateiftransactionfailsorthestatusofthesystemshouldreflectthesuccessfulcompletionifthetransactiongoesthrough. ANSWER QUESTION 32
  • 34. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatarepropertiesofatransaction? 34 QUESTION PropertiesofthetransactioncanbesummarizedasACIDProperties. 1.Atomicity:Atransactionconsistsofmanysteps.Whenallthestepsinatransactiongetscompleted,itwillgetreflectedinDBorifanystepfails,allthetransactionsarerolledback. 2.Consistency:Thedatabasewillmovefromoneconsistentstatetoanother,ifthetransactionsucceedsandremainintheoriginalstate,ifthetransactionfails. 3.Isolation:Everytransactionshouldoperateasifitistheonlytransactioninthesystem 4.Durability:Onceatransactionhascompletedsuccessfully,theupdatedrows/recordsmustbeavailableforallothertransactionsonapermanentbasis ANSWER QUESTION 33
  • 35. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisaDatabaseLock?Whatarethetypeoflocks? 35 QUESTION Databaselocktellatransaction,ifthedataiteminquestionsiscurrentlybeingusedbyothertransactions. 1.SharedLock:Whenasharedlockisappliedondataitem,othertransactionscanonlyreadtheitem,butcan'twriteintoit. 2.ExclusiveLock:Whenaexclusivelockisappliedondataitem,othertransactionscan'treadorwriteintothedataitem. ANSWER QUESTION 34
  • 36. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisaCompositeKey? 36 QUESTION ACompositeprimarykeyisatypeofcandidatekey,whichrepresentsasetofcolumnswhosevaluesuniquelyidentifyeveryrowinatable. Forexample-if"Employee_ID"and"EmployeeName"inatableiscombinedtouniquelyidentifiesarowitscalledaCompositeKey. ANSWER QUESTION 35
  • 37. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisaCompositePrimaryKey? 37 QUESTION ACompositeprimarykeyisasetofcolumnswhosevaluesuniquelyidentifyeveryrowinatable.Whatitmeansisthat,tablewhichcontainscompositeprimarykeywillbeindexedbasedoncolumnsspecifiedintheprimarykey. ThiskeywillbereferredinForeignKeytables. Forexample-ifcombinedeffectofcolumns,"Employee_ID"and"EmployeeName"inatableisrequiredtouniquelyidentifiesarow,itscalledaCompositePrimaryKey.Inthiscase,boththecolumnswillberepresentedasprimarykey. ANSWER QUESTION 36
  • 38. For the hottest SQL jobs, please visit www.hirist.com hirist .com DefineSQLInsertStatement? 38 QUESTION SQLINSERTstatementisusedtoaddrowstoatable.Forafullrowinsert,SQLQueryshouldstartwith―insertinto―statementfollowedbytablenameandvaluescommand,followedbythevaluesthatneedtobeinsertedintothetable.Insertcanbeusedinseveralways: 1.Toinsertasinglecompleterow 2.Toinsertasinglepartialrow ANSWER QUESTION 37
  • 39. For the hottest SQL jobs, please visit www.hirist.com hirist .com DefineSQLUpdateStatement? 39 QUESTION SQLUpdateisusedtoupdatedatainaroworsetofrowsspecifiedinthefiltercondition. ThebasicformatofanSQLUPDATEstatementis,UpdatecommandfollowedbytabletobeupdatedandSETcommandfollowedbycolumnnamesandtheirnewvaluesfollowedbyfilterconditionthatdetermineswhichrowsshouldbeupdated. ANSWER QUESTION 38
  • 40. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatarewildcardsusedindatabaseforPatternMatching? 40 QUESTION SQLLikeoperatorisuserforpatternmatching.SQL'Like'commandtakesmoretimetoprocess.Sobeforeusinglikeoperator,considersuggestionsgivenbelowonwhenandwheretousewildcardsearch. 1)Don'toverusewildcards.Ifanothersearchoperatorwilldo,useitinstead. 2)Whenyoudousewildcards,trynottousethematthebeginningofthesearchpattern,unlessabsolutelynecessary.Searchpatternsthatbeginwithwildcardsaretheslowesttoprocess. 3)Paycarefulattentiontotheplacementofthewildcardsymbols.Iftheyaremisplaced,youmightnotreturnthedatayouintended ANSWER QUESTION 39
  • 41. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisCrossJoin? 41 QUESTION CrossJoinwillreturnallrecordswhereeachrowfromthefirsttableiscombinedwitheachrowfromthesecondtable. ANSWER QUESTION 40
  • 42. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisaview? 42 QUESTION Viewsarevirtualtables.Unliketablesthatcontaindata,viewssimplycontainqueriesthatdynamicallyretrievedatawhenused. ANSWER QUESTION 41
  • 43. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisamaterializedview? 43 QUESTION Materializedviewsisalsoaviewbutarediskbased.Materializedviewsgetupdatedonspecificduration,baseupontheintervalspecifiedinthequerydefinition.Wecanindexmaterializedview. ANSWER QUESTION 42
  • 44. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whataretheadvantagesanddisadvantagesofviewsinadatabase? 44 QUESTION Advantages: 1.Viewsdoesn'tstoredatainaphysicallocation. 2.Viewcanbeusetohidesomeofthecolumnsfromthetable 3.ViewscanprovideAccessRestriction,sincedatainsertion,updateanddeletionisnotpossibleontheview. Disadvantages: 1.Whenatableisdropped,associatedviewbecomeirrelevant. 2.Sinceviewarecreatedwhenaqueryrequestingdatafromviewistriggered,itsbitslow 3.Whenviewsarecreatedforlargetables,itoccupymorememory. ANSWER QUESTION 43
  • 45. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhendoyouuseUPDATE_STATISTICScommand? 45 QUESTION Thiscommandisusedwhenalargeprocessingofdatahasoccurred.Ifanylargeamountofdeletions,anymodifications,orBulkCopyintothetableshasoccurred,ithastoupdatetheindexestotakethesechangesintoaccount.UPDATE_STATISTICSupdatestheindexesonthesetablesaccordingly. ANSWER QUESTION 44
  • 46. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisanIDENTITYcolumnininsertstatements? 46 QUESTION IDENTITYcolumnisusedintablecolumnstomakethatcolumnasAutoincrementalnumberorasurrogatekey. ANSWER QUESTION 45
  • 47. For the hottest SQL jobs, please visit www.hirist.com hirist .com HowwillIretrieveallrecordsofemployment1thoseshouldnotbepresentnemployment2? 47 QUESTION (Select*fromemployment2)-(Select*fromemployment1). ANSWER QUESTION 46
  • 48. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhichTCP/IPportdoesSQLServerrunon?Howcanitbechanged? 48 QUESTION SQLServerrunsonport1433.ItcanbechangedfromtheNetworkUtilityTCP/IPproperties. ANSWER QUESTION 47
  • 49. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisSQLServerAgent? 49 QUESTION SQLServeragentplaysanimportantroleintheday-to-daytasksofadatabaseadministrator(DBA).ItspurposeistoeasetheimplementationoftasksfortheDBA,withitsfull-functionschedulingengine,whichallowsyoutoscheduleyourownjobsandscripts. ANSWER QUESTION 48
  • 50. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhichcommandusingQueryAnalyzerwillgiveyoutheversionofSQLserverandoperatingsystem? 50 QUESTION SELECTSERVERPROPERTY('productversion'),SERVERPROPERTY('productlevel')andSERVERPROPERTY('edition') ANSWER QUESTION 49
  • 51. For the hottest SQL jobs, please visit www.hirist.com hirist .com HowtocreaterecursivequeryinSQLServer? 51 QUESTION RecursivequerycanbecreateinSQLusingstoredprocedurebutyoucanalsouseCTE(Commontableexpression).ItmightbealsoworthaskingaboutperformanceasCTEisnotalwaysveryfast. ANSWER QUESTION 51
  • 52. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisaconstraint? 52 QUESTION Constraintcanbeusedtospecifythelimitonthedatatypeoftable.Constraintcanbespecifiedwhilecreatingoralteringthetablestatement.Sampleofconstraintare. •NOTNULL. •CHECK. •DEFAULT. •UNIQUE. •PRIMARYKEY. •FOREIGNKEY. ANSWER QUESTION 51
  • 53. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisAutoIncrement? 53 QUESTION Autoincrementkeywordallowstheusertocreateauniquenumbertobegeneratedwhenanewrecordisinsertedintothetable.AUTOINCREMENTkeywordcanbeusedinOracleandIDENTITYkeywordcanbeusedinSQLSERVER. MostlythiskeywordcanbeusedwheneverPRIMARYKEYisused. ANSWER QUESTION 52
  • 54. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisDatawarehouse? 54 QUESTION Datawarehouseisacentralrepositoryofdatafrommultiplesourcesofinformation.Thosedataareconsolidated, transformedandmadeavailablefortheminingandonlineprocessing.WarehousedatahaveasubsetofdatacalledDataMarts. ANSWER QUESTION 53
  • 55. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisuserdefinedfunctions? 55 QUESTION Userdefinedfunctionsarethefunctionswrittentousethatlogicwheneverrequired.Itisnotnecessarytowritethesamelogicseveraltimes.Instead,functioncanbecalledorexecutedwheneverneeded. ANSWER QUESTION 54
  • 56. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatarealltypesofuserdefinedfunctions? 56 QUESTION Threetypesofuserdefinedfunctionsare. a.ScalarFunctions. b.InlineTablevaluedfunctions. c.Multistatementvaluedfunctions. ANSWER QUESTION 55
  • 57. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatarealldifferenttypesofcollationsensitivity? 57 QUESTION Followingaredifferenttypesofcollationsensitivity-. •CaseSensitivity–AandaandBandb. •AccentSensitivity. •KanaSensitivity–JapaneseKanacharacters. •WidthSensitivity–Singlebytecharacteranddoublebytecharacter. ANSWER QUESTION 56
  • 58. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisOnlineTransactionProcessing(OLTP)? 58 QUESTION OnlineTransactionProcessingorOLTPmanagestransactionbasedapplicationswhichcanbeusedfordataentryandeasyretrievalprocessingofdata.Thisprocessingmakeslikeeasieronsimplicityandefficiency.Itisfaster, moreaccurateresultsandexpenseswithrespecttoOTLP. Example–BankTransactionsonadailybasis. ANSWER QUESTION 57
  • 59. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisanALIAScommand? 59 QUESTION ALIASnamecanbegiventoatableorcolumn.ThisaliasnamecanbereferredinWHEREclausetoidentifythetableorcolumn. Example-. Selectst.StudentID,Ex.Resultfromstudentst,ExamasExwherest.studentID=Ex.StudentID Here,streferstoaliasnameforstudenttableandExreferstoaliasnameforexamtable. ANSWER QUESTION 58
  • 60. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatareaggregateandscalarfunctions? 60 QUESTION Aggregatefunctionsareusedtoevaluatemathematicalcalculationandreturnsinglevalues.Thiscanbecalculatedfromthecolumnsinatable.Scalarfunctionsreturnasinglevaluebasedontheinputvalue. Example-. Aggregate–max(),count–Calculatedwithrespecttonumeric. Scalar–UCASE(),NOW()–Calculatedwithrespecttostrings. ANSWER QUESTION 59
  • 61. For the hottest SQL jobs, please visit www.hirist.com hirist .com Howcanyoucreateanemptytablefromanexistingtable? 61 QUESTION Select*intostudentcopyfromstudentwhere1=2 Here,wearecopyingstudenttabletoanothertablewiththesamestructurewithnorowscopied. ANSWER QUESTION 60
  • 62. For the hottest SQL jobs, please visit www.hirist.com hirist .com Howtofetchcommonrecordsfromtwotables? 62 QUESTION Commonrecordsresultsetcanbeachievedby-. SelectstudentIDfromstudent.<strong>INTERSECT</strong>SelectStudentIDfromExam ANSWER QUESTION 61
  • 63. For the hottest SQL jobs, please visit www.hirist.com hirist .com Howtoselectuniquerecordsfromatable? 63 QUESTION SelectuniquerecordsfromatablebyusingDISTINCTkeyword. SelectDISTINCTStudentID,StudentNamefromStudent. ANSWER QUESTION 62
  • 64. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatarethedifferentindexconfigurationsatablecanhave? 64 QUESTION Atablecanhaveoneofthefollowingindexconfigurations: 1.Noindexes 2.Aclusteredindex 3.Aclusteredindexandmanynonclusteredindexes 4.Anonclusteredindex 5.Manynonclusteredindexes ANSWER QUESTION 63
  • 65. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatarethepropertiesanddifferentTypesofSub-Queries? 65 QUESTION PropertiesofSub-Query a.Asub-querymustbeenclosedintheparenthesis. b.Asub-querymustbeputintherighthandofthecomparisonoperator,and c.Asub-querycannotcontainanORDER-BYclause. d.Aquerycancontainmorethanonesub-query. TypesofSub-Query e.Single-rowsub-query,wherethesub-queryreturnsonlyonerow. f.Multiple-rowsub-query,wherethesub-queryreturnsmultiplerows,.and g.Multiplecolumnsub-query,wherethesub-queryreturnsmultiplecolumns ANSWER QUESTION 64
  • 66. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisSQLProfiler? 66 QUESTION SQLProfilerisagraphicaltoolthatallowssystemadministratorstomonitoreventsinaninstanceofMicrosoftSQLServer.YoucancaptureandsavedataabouteacheventtoafileorSQLServertabletoanalyzelater.Forexample,youcanmonitoraproductionenvironmenttoseewhichstoredproceduresarehamperingperformancesbyexecutingtooslowly. UseSQLProfilertomonitoronlytheeventsinwhichyouareinterested.Iftracesarebecomingtoolarge,youcanfilterthembasedontheinformationyouwant,sothatonlyasubsetoftheeventdataiscollected.Monitoringtoomanyeventsaddsoverheadtotheserverandthemonitoringprocessandcancausethetracefileortracetabletogrowverylarge,especiallywhenthemonitoringprocesstakesplaceoveralongperiodoftime. ANSWER QUESTION 65
  • 67. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhataretheauthenticationmodesinSQLServer?Howcanitbechanged? 67 QUESTION WindowsmodeandMixedMode-SQLandWindows.TochangeauthenticationmodeinSQLServerclickStart, Programs,MicrosoftSQLServerandclickSQLEnterpriseManagertorunSQLEnterpriseManagerfromtheMicrosoftSQLServerprogramgroup.SelecttheserverthenfromtheToolsmenuselectSQLServerConfigurationProperties,andchoosetheSecuritypage. ANSWER QUESTION 66
  • 68. For the hottest SQL jobs, please visit www.hirist.com hirist .com Canastoredprocedurecallitselforrecursivestoredprocedure?HowmuchlevelSPnestingispossible? 68 QUESTION Yes.BecauseTransact-SQLsupportsrecursion,youcanwritestoredproceduresthatcallthemselves.Recursioncanbedefinedasamethodofproblemsolvingwhereinthesolutionisarrivedatbyrepetitivelyapplyingittosubsetsoftheproblem.Acommonapplicationofrecursivelogicistoperformnumericcomputationsthatlendthemselvestorepetitiveevaluationbythesameprocessingsteps.StoredproceduresarenestedwhenonestoredprocedurecallsanotherorexecutesmanagedcodebyreferencingaCLRroutine,type,oraggregate.Youcanneststoredproceduresandmanagedcodereferencesupto32levels. ANSWER QUESTION 67
  • 69. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisLogShipping? 69 QUESTION LogshippingistheprocessofautomatingthebackupofdatabaseandtransactionlogfilesonaproductionSQLserver,andthenrestoringthemontoastandbyserver.EnterpriseEditionsonlysupportslogshipping.Inlogshippingthetransactionallogfilefromoneserverisautomaticallyupdatedintothebackupdatabaseontheotherserver.Ifoneserverfails,theotherserverwillhavethesamedbandcanbeusedthisastheDisasterRecoveryplan.Thekeyfeatureoflogshippingisthatitwillautomaticallybackuptransactionlogsthroughoutthedayandautomaticallyrestorethemonthestandbyserveratdefinedinterval. ANSWER QUESTION 68
  • 70. For the hottest SQL jobs, please visit www.hirist.com hirist .com Name3waystogetanaccuratecountofthenumberofrecordsinatable? 70 QUESTION SELECT*FROMtable1 SELECTCOUNT(*)FROMtable1 SELECTrowsFROMsysindexesWHEREid=OBJECT_ID(table1)ANDindid<2 ANSWER QUESTION 69
  • 71. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatdoesitmeantohaveQUOTED_IDENTIFIERON?WhataretheimplicationsofhavingitOFF? 71 QUESTION WhenSETQUOTED_IDENTIFIERisON,identifierscanbedelimitedbydoublequotationmarks,andliteralsmustbedelimitedbysinglequotationmarks.WhenSETQUOTED_IDENTIFIERisOFF,identifierscannotbequotedandmustfollowallTransact-SQLrulesforidentifiers. ANSWER QUESTION 70
  • 72. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisthedifferencebetweenaLocalandaGlobaltemporarytable? 72 QUESTION 1.Alocaltemporarytableexistsonlyforthedurationofaconnectionor,ifdefinedinsideacompoundstatement,forthedurationofthecompoundstatement. 2.Aglobaltemporarytableremainsinthedatabasepermanently,buttherowsexistonlywithinagivenconnection. Whenconnectionisclosed,thedataintheglobaltemporarytabledisappears.However,thetabledefinitionremainswiththedatabaseforaccesswhendatabaseisopenednexttime. ANSWER QUESTION 71
  • 73. For the hottest SQL jobs, please visit www.hirist.com hirist .com HowGlobaltemporarytablesarerepresentedanditsscope? 73 QUESTION Globaltemporarytablesarerepresentedwith##beforethetablename.Scopewillbetheoutsidethesessionwhereaslocaltemporarytablesareinsidethesession.SessionIDcanbefoundusing@@SPID. ANSWER QUESTION 72
  • 74. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatistheSTUFFfunctionandhowdoesitdifferfromtheREPLACEfunction? 74 QUESTION STUFFfunctionisusedtooverwriteexistingcharacters.Usingthissyntax,STUFF(string_expression,start,length, replacement_characters),string_expressionisthestringthatwillhavecharacterssubstituted,startisthestartingposition,lengthisthenumberofcharactersinthestringthataresubstituted,andreplacement_charactersarethenewcharactersinterjectedintothestring.REPLACEfunctiontoreplaceexistingcharactersofalloccurrences. UsingthesyntaxREPLACE(string_expression,search_string,replacement_string),whereeveryincidenceofsearch_stringfoundinthestring_expressionwillbereplacedwithreplacement_string. ANSWER QUESTION 73
  • 75. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisCHECKConstraint? 75 QUESTION ACHECKconstraintisusedtolimitthevaluesthatcanbeplacedinacolumn.Thecheckconstraintsareusedtoenforcedomainintegrity. ANSWER QUESTION 74
  • 76. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisthedifferencebetweenUNIONandUNIONALL? 76 QUESTION UNIONstatementismainlyusedtocombinethetablesincludingtheduplicaterowsandUNIONALLcombinebutdoesnotlookforduplicaterows.Withthis,UNIONALLwillbeveryfasterthanUNIONstatements. ANSWER QUESTION 75
  • 77. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisNOTNULLConstraint? 77 QUESTION ANOTNULLconstraintenforcesthatthecolumnwillnotacceptnullvalues.Thenotnullconstraintsareusedtoenforcedomainintegrity,asthecheckconstraints. ANSWER QUESTION 76
  • 78. For the hottest SQL jobs, please visit www.hirist.com hirist .com Howtoget@@ERRORand@@ROWCOUNTatthesametime? 78 QUESTION If@@RowcountischeckedafterErrorcheckingstatementthenitwillhave0asthevalueof@@Recordcountasitwouldhavebeenreset.Andif@@Recordcountischeckedbeforetheerror-checkingstatementthen@@Errorwouldgetreset.Toget@@errorand@@rowcountatthesametimedobothinsamestatementandstoretheminlocalvariable. SELECT@RC=@@ROWCOUNT,@ER=@@ERROR ANSWER QUESTION 77
  • 79. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisaScheduledJobsorWhatisaScheduledTasks? 79 QUESTION Scheduledtasksletuserautomateprocessesthatrunonregularorpredictablecycles.Usercanscheduleadministrativetasks,suchascubeprocessing,torunduringtimesofslowbusinessactivity.UsercanalsodeterminetheorderinwhichtasksrunbycreatingjobstepswithinaSQLServerAgentjob.E.g.backupdatabase,UpdateStatsofTables.Jobstepsgiveusercontroloverflowofexecution.Ifonejobfails,usercanconfigureSQLServerAgenttocontinuetoruntheremainingtasksortostopexecution. ANSWER QUESTION 78
  • 80. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisatablecalled,ifithasneitherClusternorNon-clusterIndex?Whatisitusedfor? 80 QUESTION UnindexedtableorHeap.MicrosoftPressBooksandBookonLine(BOL)refersitasHeap.Aheapisatablethatdoesnothaveaclusteredindexand,therefore,thepagesarenotlinkedbypointers.TheIAMpagesaretheonlystructuresthatlinkthepagesinatabletogether.Unindexedtablesaregoodforfaststoringofdata.Manytimesitisbettertodropallindexesfromtableandthendobulkofinsertsandtorestorethoseindexesafterthat. ANSWER QUESTION 79
  • 81. For the hottest SQL jobs, please visit www.hirist.com hirist .com CanSQLServerslinkedtootherserverslikeOracle? 81 QUESTION SQLServercanbelinkedtoanyserverprovidedithasOLE-DBproviderfromMicrosofttoallowalink.E.g.OraclehasanOLE-DBproviderfororaclethatMicrosoftprovidestoadditaslinkedservertoSQLServergroup. ANSWER QUESTION 80
  • 82. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisBCP?Whendoesitused? 82 QUESTION BulkCopyisatoolusedtocopyhugeamountofdatafromtablesandviews.BCPdoesnotcopythestructuressameassourcetodestination.BULKINSERTcommandhelpstoimportadatafileintoadatabasetableorviewinauser-specifiedformat. ANSWER QUESTION 81
  • 83. For the hottest SQL jobs, please visit www.hirist.com hirist .com Howtoimplementone-to-one,one-to-manyandmany-to-manyrelationshipswhiledesigningtables? 83 QUESTION One-to-Onerelationshipcanbeimplementedasasingletableandrarelyastwotableswithprimaryandforeignkeyrelationships.One-to-Manyrelationshipsareimplementedbysplittingthedataintotwotableswithprimarykeyandforeignkeyrelationships.Many-to-Manyrelationshipsareimplementedusingajunctiontablewiththekeysfromboththetablesformingthecompositeprimarykeyofthejunctiontable. ANSWER QUESTION 82
  • 84. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisanexecutionplan?Whenwouldyouuseit?Howwouldyouviewtheexecutionplan? 84 QUESTION AnexecutionplanisbasicallyaroadmapthatgraphicallyortextuallyshowsthedataretrievalmethodschosenbytheSQLServerqueryoptimizerforastoredprocedureorad-hocqueryandisaveryusefultoolforadevelopertounderstandtheperformancecharacteristicsofaqueryorstoredproceduresincetheplanistheonethatSQLServerwillplaceinitscacheandusetoexecutethestoredprocedureorquery.FromwithinQueryAnalyzerisanoptioncalled"ShowExecutionPlan"(locatedontheQuerydrop-downmenu).Ifthisoptionisturnedonitwilldisplayqueryexecutionplaninseparatewindowwhenqueryisranagain. ANSWER QUESTION 83
  • 85. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatarethetwoauthenticationmodesinSQLServer? 85 QUESTION Therearetwoauthenticationmodes– •WindowsMode •MixedMode ModescanbechangedbyselectingthetoolsmenuofSQLServerconfigurationpropertiesandchoosesecuritypage. ANSWER QUESTION 84
  • 86. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisCOALESCEinSQLServer? 86 QUESTION COALESCEisusedtoreturnfirstnon-nullexpressionwithinthearguments.Thisfunctionisusedtoreturnanon- nullfrommorethanonecolumninthearguments. Example– SelectCOALESCE(empno,empname,salary)fromemployee; ANSWER QUESTION 85
  • 87. For the hottest SQL jobs, please visit www.hirist.com hirist .com HowexceptionscanbehandledinSQLServerProgramming? 87 QUESTION ExceptionsarehandledusingTRY—-CATCHconstructsanditishandlesbywritingscriptsinsidetheTRYblockanderrorhandlingintheCATCHblock. ANSWER QUESTION 86
  • 88. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisthepurposeofFLOORfunction? 88 QUESTION FLOORfunctionisusedtoroundupanon-integervaluetothepreviousleastinteger.ExampleisgivenFLOOR(6.7) Returns6. ANSWER QUESTION 87
  • 89. For the hottest SQL jobs, please visit www.hirist.com hirist .com Canwechecklocksindatabase?Ifso,howcanwedothislockcheck? 89 QUESTION Yes,wecanchecklocksinthedatabase.Itcanbeachievedbyusingin-builtstoredprocedurecalledsp_lock. ANSWER QUESTION 88
  • 90. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatistheuseofSIGNfunction? 90 QUESTION SIGNfunctionisusedtodeterminewhetherthenumberspecifiedisPositive,NegativeandZero.Thiswillreturn+1,-1or0. Example:SIGN(-35)returns-1 ANSWER QUESTION 89
  • 91. For the hottest SQL jobs, please visit www.hirist.com hirist .com HowistheSUBSTRkeywordusedinSQL? 91 QUESTION SUBSTRisusedforstringmanipulationwithcolumnname,firstpositionandstringlengthusedasarguments.E.g. SUBSTR(NAME,13)referstothefirstthreecharactersinthecolumnNAME. ANSWER QUESTION 90
  • 92. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisaNULLvalue?WhataretheprosandconsofusingNULLS? 92 QUESTION ANULLvaluetakesuponebyteofstorageandindicatesthatavalueisnotpresentasopposedtoaspaceorzerovalue.It'stheDB2equivalentofTBDonanorganizationalchartandoftencorrectlyportraysabusinesssituation. Unfortunately,itrequiresextracodingforanapplicationprogramtohandlethissituation. ANSWER QUESTION 91
  • 93. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisasynonym?Howisitused? 93 QUESTION Asynonymisusedtoreferenceatableorviewbyanothername.Theothernamecanthenbewrittenintheapplicationcodepointingtotesttablesinthedevelopmentstageandtoproductionentitieswhenthecodeismigrated.ThesynonymislinkedtotheAUTHIDthatcreatedit. ANSWER QUESTION 92
  • 94. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisaCartesianproduct? 94 QUESTION ACartesianproductresultsfromafaultyquery.Itisarowintheresultsforeverycombinationinthejointables. ANSWER QUESTION 93
  • 95. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisatuple? 95 QUESTION StaticSQLiscompiledandoptimizedpriortoitsexecution;dynamiciscompiledandoptimizedduringexecution. ANSWER QUESTION 94
  • 96. For the hottest SQL jobs, please visit www.hirist.com hirist .com Whatisreferentialintegrity? 96 QUESTION Referentialintegrityreferstotheconsistencythatmustbemaintainedbetweenprimaryandforeignkeys,i.e.everyforeignkeyvaluemusthaveacorrespondingprimarykeyvalue. ANSWER QUESTION 95
  • 97. For the hottest SQL jobs, please visit www.hirist.com hirist .com What’sthemaximumsizeofarow? 97 QUESTION 8060bytes. ANSWER QUESTION 96
  • 98. For the hottest SQL jobs, please visit www.hirist.com hirist .com HowtochangeDatabasenameinSQLserver? 98 QUESTION Usethefollowingcode: SupportedinSQLserver2000and2005 Execsp_renamedb―test‖,―test1‖ SupportedinSQLServer2005andlaterversion ALTERDatabase―test1‖ModifyName=―test‖ ANSWER QUESTION 97
  • 99. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisaCursor? 99 QUESTION AdatabaseCursorisacontrolwhichenablestraversalovertherowsorrecordsinthetable.Thiscanbeviewedasapointertoonerowinasetofrows.Cursorisverymuchusefulfortraversingsuchasretrieval,additionandremovalofdatabaserecords. ANSWER QUESTION 98
  • 100. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatareMagicTablesinSQLServer? 100 QUESTION InsertandDeletetablesarecreatedwhenthetriggerisfiredforanyDMLcommand.ThosetablesarecalledMagicTablesinSQLServer.Thesemagictablesareusedinsidethetriggersfordatatransaction. ANSWER QUESTION 99
  • 101. For the hottest SQL jobs, please visit www.hirist.com hirist .com WhatisISNULL()operator? 101 QUESTION ISNULLfunctionisusedtocheckwhethervaluegivenisNULLornotNULLinsqlserver.ThisfunctionalsoprovidestoreplaceavaluewiththeNULL. ANSWER QUESTION 100
  • 102. For the hottest SQL jobs, please visit www.hirist.com hirist .com Resources 102 http://www.itechaleart.com/2013/05/top-50-sql-question-answers_11.html https://www.katieandemil.com/sql-interview-questions-and- answers?tab=article#Question 4 http://www.dwbiconcepts.com/tutorial/24-interview-questions/190-top-20-sql- interview-questions-with-answers.html http://a4academics.com/interview-questions/53-database-and-sql/411-sql- interview-questions-and-answers-database http://narendra86.blogspot.com/2013/10/top-80-sql-query-interview- questions.html http://crackaninterview.com/sql-queries-interview-questions-answers/ http://career.guru99.com/top-50-sql-question-answers/ http://www.indiabix.com/technical/sql-server-common-questions/ http://career.guru99.com/top-50-sql-server-questions-answers/ http://www.ittestpapers.com/sql-interview-questions(25-50).html http://www.dotnetfunda.com/interviews/cat/8/sql-server http://www.careerride.com/SQLServer-Interview-Questions.aspx
  • 103. www.hirist.com SQL TOP 100 INTERVIEW QUESTIONS & ANSWERS