Anda di halaman 1dari 15

4/16/2015

Top50SQLQuestion&Answers

Top 50 SQL Question & Answers


DownloadPDF[/top50sqlquestionanswers/?
format=pdf]

1.WhatisDBMS?
ADatabaseManagementSystem(DBMS)isaprogram
thatcontrolscreation,maintenanceanduseofa
database.DBMScanbetermedasFileManagerthat
managesdatainadatabaseratherthansavingitinfile
systems.
2.WhatisRDBMS?
RDBMSstandsforRelationalDatabaseManagement
System.RDBMSstorethedataintothecollectionof
tables,whichisrelatedbycommonfieldsbetweenthe
columnsofthetable.Italsoprovidesrelationaloperators
tomanipulatethedatastoredintothetables.
Example:SQLServer.
3.WhatisSQL?
http://career.guru99.com/top50sqlquestionanswers/

1/15

4/16/2015

Top50SQLQuestion&Answers

SQLstandsforStructuredQueryLanguage,anditis
usedtocommunicatewiththeDatabase.Thisisa
standardlanguageusedtoperformtaskssuchas
retrieval,updation,insertionanddeletionofdatafroma
database.
StandardSQLCommandsareSelect.
4.WhatisaDatabase?
Databaseisnothingbutanorganizedformofdatafor
easyaccess,storing,retrievalandmanagingofdata.
Thisisalsoknownasstructuredformofdatawhichcan
beaccessedinmanyways.
Example:SchoolManagementDatabase,Bank
ManagementDatabase.
5.WhataretablesandFields?
Atableisasetofdatathatareorganizedinamodelwith
ColumnsandRows.Columnscanbecategorizedas
vertical,andRowsarehorizontal.Atablehasspecified
numberofcolumncalledfieldsbutcanhaveanynumber
ofrowswhichiscalledrecord.
Example:.
Table:Employee.
Field:EmpID,EmpName,DateofBirth.
Data:201456,David,11/15/1960.
6.Whatisaprimarykey?
Aprimarykeyisacombinationoffieldswhichuniquely
specifyarow.Thisisaspecialkindofuniquekey,andit
hasimplicitNOTNULLconstraint.Itmeans,Primary
keyvaluescannotbeNULL.
7.Whatisauniquekey?
AUniquekeyconstraintuniquelyidentifiedeachrecord
inthedatabase.Thisprovidesuniquenessforthe
columnorsetofcolumns.
APrimarykeyconstrainthasautomaticunique
http://career.guru99.com/top50sqlquestionanswers/

2/15

4/16/2015

Top50SQLQuestion&Answers

constraintdefinedonit.Butnot,inthecaseofUnique
Key.
Therecanbemanyuniqueconstraintdefinedpertable,
butonlyonePrimarykeyconstraintdefinedpertable.
8.Whatisaforeignkey?
Aforeignkeyisonetablewhichcanberelatedtothe
primarykeyofanothertable.Relationshipneedstobe
createdbetweentwotablesbyreferencingforeignkey
withtheprimarykeyofanothertable.
9.Whatisajoin?
Thisisakeywordusedtoquerydatafrommoretables
basedontherelationshipbetweenthefieldsofthe
tables.KeysplayamajorrolewhenJOINsareused.
10.Whatarethetypesofjoinandexplaineach?
Therearevarioustypesofjoinwhichcanbeusedto
retrievedataanditdependsontherelationshipbetween
tables.
Innerjoin.
Innerjoinreturnrowswhenthereisatleastonematchof
rowsbetweenthetables.
RightJoin.
Rightjoinreturnrowswhicharecommonbetweenthe
tablesandallrowsofRighthandsidetable.Simply,it
returnsalltherowsfromtherighthandsidetableeven
thoughtherearenomatchesinthelefthandsidetable.
LeftJoin.
Leftjoinreturnrowswhicharecommonbetweenthe
tablesandallrowsofLefthandsidetable.Simply,it
returnsalltherowsfromLefthandsidetableeven
thoughtherearenomatchesintheRighthandside
table.
FullJoin.
Fulljoinreturnrowswhentherearematchingrowsin
http://career.guru99.com/top50sqlquestionanswers/

3/15

4/16/2015

Top50SQLQuestion&Answers

anyoneofthetables.Thismeans,itreturnsalltherows
fromthelefthandsidetableandalltherowsfromthe
righthandsidetable.
11.Whatisnormalization?
Normalizationistheprocessofminimizingredundancy
anddependencybyorganizingfieldsandtableofa
database.ThemainaimofNormalizationistoadd,
deleteormodifyfieldthatcanbemadeinasingletable.
12.WhatisDenormalization.
DeNormalizationisatechniqueusedtoaccessthedata
fromhighertolowernormalformsofdatabase.Itisalso
processofintroducingredundancyintoatableby
incorporatingdatafromtherelatedtables.
13.Whatareallthedifferentnormalizations?
Thenormalformscanbedividedinto5forms,andthey
areexplainedbelow.
FirstNormalForm(1NF):.
Thisshouldremovealltheduplicatecolumnsfromthe
table.Creationoftablesfortherelateddataand
identificationofuniquecolumns.
SecondNormalForm(2NF):.
Meetingallrequirementsofthefirstnormalform.Placing
thesubsetsofdatainseparatetablesandCreationof
relationshipsbetweenthetablesusingprimarykeys.
ThirdNormalForm(3NF):.
Thisshouldmeetallrequirementsof2NF.Removingthe
columnswhicharenotdependentonprimarykey
constraints.
FourthNormalForm(3NF):.
Meetingalltherequirementsofthirdnormalformandit
shouldnothavemultivalueddependencies.
14.WhatisaView?
Aviewisavirtualtablewhichconsistsofasubsetof
http://career.guru99.com/top50sqlquestionanswers/

4/15

4/16/2015

Top50SQLQuestion&Answers

Aviewisavirtualtablewhichconsistsofasubsetof
datacontainedinatable.Viewsarenotvirtuallypresent,
andittakeslessspacetostore.Viewcanhavedataof
oneormoretablescombined,anditisdependingonthe
relationship.
15.WhatisanIndex?
Anindexisperformancetuningmethodofallowingfaster
retrievalofrecordsfromthetable.Anindexcreatesan
entryforeachvalueanditwillbefastertoretrievedata.
16.Whatareallthedifferenttypesofindexes?
Therearethreetypesofindexes.
UniqueIndex.
Thisindexingdoesnotallowthefieldtohaveduplicate
valuesifthecolumnisuniqueindexed.Uniqueindexcan
beappliedautomaticallywhenprimarykeyisdefined.
ClusteredIndex.
Thistypeofindexreordersthephysicalorderofthe
tableandsearchbasedonthekeyvalues.Eachtable
canhaveonlyoneclusteredindex.
NonClusteredIndex.
NonClusteredIndexdoesnotalterthephysicalorderof
thetableandmaintainslogicalorderofdata.Eachtable
canhave999nonclusteredindexes.
17.WhatisaCursor?
AdatabaseCursorisacontrolwhichenablestraversal
overtherowsorrecordsinthetable.Thiscanbeviewed
asapointertoonerowinasetofrows.Cursorisvery
muchusefulfortraversingsuchasretrieval,additionand
removalofdatabaserecords.
18.Whatisarelationshipandwhatarethey?
DatabaseRelationshipisdefinedastheconnection
betweenthetablesinadatabase.Therearevariousdata
basingrelationships,andtheyareasfollows:.
http://career.guru99.com/top50sqlquestionanswers/

5/15

4/16/2015

Top50SQLQuestion&Answers

OnetoOneRelationship.
OnetoManyRelationship.
ManytoOneRelationship.
SelfReferencingRelationship.
19.Whatisaquery?
ADBqueryisacodewritteninordertogetthe
informationbackfromthedatabase.Querycanbe
designedinsuchawaythatitmatchedwithour
expectationoftheresultset.Simply,aquestiontothe
Database.
20.Whatissubquery?
Asubqueryisaquerywithinanotherquery.Theouter
queryiscalledasmainquery,andinnerqueryiscalled
subquery.SubQueryisalwaysexecutedfirst,andthe
resultofsubqueryispassedontothemainquery.
21.Whatarethetypesofsubquery?
TherearetwotypesofsubqueryCorrelatedandNon
Correlated.
Acorrelatedsubquerycannotbeconsideredas
independentquery,butitcanreferthecolumninatable
listedintheFROMthelistofthemainquery.
ANonCorrelatedsubquerycanbeconsideredas
independentqueryandtheoutputofsubqueryare
substitutedinthemainquery.
22.Whatisastoredprocedure?
StoredProcedureisafunctionconsistsofmanySQL
statementtoaccessthedatabasesystem.SeveralSQL
statementsareconsolidatedintoastoredprocedureand
executethemwheneverandwhereverrequired.
23.Whatisatrigger?

CognizantHiringApril'15
562+NewJobsForExp:515YearsApplyNow&getMultipleInterviews
http://career.guru99.com/top50sqlquestionanswers/

6/15

4/16/2015

Top50SQLQuestion&Answers

ADBtriggerisacodeorprogramsthatautomatically
executewithresponsetosomeeventonatableorview
inadatabase.Mainly,triggerhelpstomaintainthe
integrityofthedatabase.
Example:Whenanewstudentisaddedtothestudent
database,newrecordsshouldbecreatedintherelated
tableslikeExam,ScoreandAttendancetables.
24.WhatisthedifferencebetweenDELETEand
TRUNCATEcommands?
DELETEcommandisusedtoremoverowsfromthe
table,andWHEREclausecanbeusedforconditional
setofparameters.CommitandRollbackcanbe
performedafterdeletestatement.
TRUNCATEremovesallrowsfromthetable.Truncate
operationcannotberolledback.
25.Whatarelocalandglobalvariablesandtheir
differences?
Localvariablesarethevariableswhichcanbeusedor
existinsidethefunction.Theyarenotknowntotheother
functionsandthosevariablescannotbereferredor
used.Variablescanbecreatedwheneverthatfunctionis
called.
Globalvariablesarethevariableswhichcanbeusedor
existthroughouttheprogram.Samevariabledeclaredin
globalcannotbeusedinfunctions.Globalvariables
cannotbecreatedwheneverthatfunctioniscalled.
26.Whatisaconstraint?
Constraintcanbeusedtospecifythelimitonthedata
typeoftable.Constraintcanbespecifiedwhilecreating
oralteringthetablestatement.Sampleofconstraintare.
NOTNULL.
CHECK.
DEFAULT.
UNIQUE.
http://career.guru99.com/top50sqlquestionanswers/

7/15

4/16/2015

Top50SQLQuestion&Answers

UNIQUE.
PRIMARYKEY.
FOREIGNKEY.
27.WhatisdataIntegrity?
DataIntegritydefinestheaccuracyandconsistencyof
datastoredinadatabase.Itcanalsodefineintegrity
constraintstoenforcebusinessrulesonthedatawhenit
isenteredintotheapplicationordatabase.
28.WhatisAutoIncrement?
Autoincrementkeywordallowstheusertocreatea
uniquenumbertobegeneratedwhenanewrecordis
insertedintothetable.AUTOINCREMENTkeyword
canbeusedinOracleandIDENTITYkeywordcanbe
usedinSQLSERVER.
MostlythiskeywordcanbeusedwheneverPRIMARY
KEYisused.
29.WhatisthedifferencebetweenClusterandNon
ClusterIndex?
Clusteredindexisusedforeasyretrievalofdatafrom
thedatabasebyalteringthewaythattherecordsare
stored.Databasesortsoutrowsbythecolumnwhichis
settobeclusteredindex.
Anonclusteredindexdoesnotalterthewayitwas
storedbutcreatesacompleteseparateobjectwithinthe
table.Itpointbacktotheoriginaltablerowsafter
searching.
30.WhatisDatawarehouse?
Datawarehouseisacentralrepositoryofdatafrom
multiplesourcesofinformation.Thosedataare
consolidated,transformedandmadeavailableforthe
miningandonlineprocessing.Warehousedatahavea
subsetofdatacalledDataMarts.
31.WhatisSelfJoin?
Selfjoinissettobequeryusedtocomparetoitself.This
http://career.guru99.com/top50sqlquestionanswers/

8/15

4/16/2015

Top50SQLQuestion&Answers
Selfjoinissettobequeryusedtocomparetoitself.This

isusedtocomparevaluesinacolumnwithothervalues
inthesamecolumninthesametable.ALIASEScanbe
usedforthesametablecomparison.
32.WhatisCrossJoin?
CrossjoindefinesasCartesianproductwherenumber
ofrowsinthefirsttablemultipliedbynumberofrowsin
thesecondtable.Ifsuppose,WHEREclauseisusedin
crossjointhenthequerywillworklikeanINNERJOIN.
33.Whatisuserdefinedfunctions?
Userdefinedfunctionsarethefunctionswrittentouse
thatlogicwheneverrequired.Itisnotnecessarytowrite
thesamelogicseveraltimes.Instead,functioncanbe
calledorexecutedwheneverneeded.
34.Whatarealltypesofuserdefinedfunctions?
Threetypesofuserdefinedfunctionsare.
ScalarFunctions.
InlineTablevaluedfunctions.
Multistatementvaluedfunctions.
Scalarreturnsunit,variantdefinedthereturnclause.
Othertwotypesreturntableasareturn.
35.Whatiscollation?
Collationisdefinedassetofrulesthatdeterminehow
characterdatacanbesortedandcompared.Thiscanbe
usedtocompareAand,otherlanguagecharactersand
alsodependsonthewidthofthecharacters.
ASCIIvaluecanbeusedtocomparethesecharacter
data.

36.Whatarealldifferenttypesofcollation
sensitivity?
Followingaredifferenttypesofcollationsensitivity.
CaseSensitivityAandaandBandb.

http://career.guru99.com/top50sqlquestionanswers/

9/15

4/16/2015

Top50SQLQuestion&Answers

CaseSensitivityAandaandBandb.
AccentSensitivity.

KanaSensitivityJapaneseKanacharacters.
WidthSensitivitySinglebytecharacteranddouble
bytecharacter.
37.AdvantagesandDisadvantagesofStored
Procedure?
Storedprocedurecanbeusedasamodular
programmingmeanscreateonce,storeandcallfor
severaltimeswheneverrequired.Thissupportsfaster
executioninsteadofexecutingmultiplequeries.This
reducesnetworktrafficandprovidesbettersecurityto
thedata.
Disadvantageisthatitcanbeexecutedonlyinthe
Databaseandutilizesmorememoryinthedatabase
server.
38.WhatisOnlineTransactionProcessing(OLTP)?
OnlineTransactionProcessingorOLTPmanages
transactionbasedapplicationswhichcanbeusedfor
dataentryandeasyretrievalprocessingofdata.This
processingmakeslikeeasieronsimplicityand
efficiency.Itisfaster,moreaccurateresultsand
expenseswithrespecttoOTLP.
ExampleBankTransactionsonadailybasis.
39.WhatisCLAUSE?
SQLclauseisdefinedtolimittheresultsetbyproviding
conditiontothequery.Thisusuallyfilterssomerows
fromthewholesetofrecords.
ExampleQuerythathasWHEREcondition
QuerythathasHAVINGcondition.
40.Whatisrecursivestoredprocedure?
Astoredprocedurewhichcallsbyitselfuntilitreaches
someboundarycondition.Thisrecursivefunctionor
procedurehelpsprogrammerstousethesamesetof
http://career.guru99.com/top50sqlquestionanswers/

10/15

4/16/2015

Top50SQLQuestion&Answers

procedurehelpsprogrammerstousethesamesetof
codeanynumberoftimes.

41.WhatisUnion,minusandInteractcommands?
UNIONoperatorisusedtocombinetheresultsoftwo
tables,anditeliminatesduplicaterowsfromthetables.
MINUSoperatorisusedtoreturnrowsfromthefirst
querybutnotfromthesecondquery.Matchingrecords
offirstandsecondqueryandotherrowsfromthefirst
querywillbedisplayedasaresultset.
INTERSECToperatorisusedtoreturnrowsreturnedby
boththequeries.
42.WhatisanALIAScommand?
ALIASnamecanbegiventoatableorcolumn.This
aliasnamecanbereferredinWHEREclausetoidentify
thetableorcolumn.
Example.
1 Select st.StudentID, Ex.Result from student st,

Here,streferstoaliasnameforstudenttableandEx
referstoaliasnameforexamtable.
43.WhatisthedifferencebetweenTRUNCATEand
DROPstatements?
TRUNCATEremovesalltherowsfromthetable,andit
cannotberolledback.DROPcommandremovesatable
fromthedatabaseandoperationcannotberolledback.
44.Whatareaggregateandscalarfunctions?
Aggregatefunctionsareusedtoevaluatemathematical
calculationandreturnsinglevalues.Thiscanbe
calculatedfromthecolumnsinatable.Scalarfunctions
returnasinglevaluebasedontheinputvalue.
Example.
Aggregatemax(),countCalculatedwithrespectto
numeric.
http://career.guru99.com/top50sqlquestionanswers/

11/15

4/16/2015

Top50SQLQuestion&Answers

ScalarUCASE(),NOW()Calculatedwithrespectto
strings.
45.Howcanyoucreateanemptytablefroman
existingtable?
Examplewillbe.
1 Select * into studentcopy from student where 1=2

Here,wearecopyingstudenttabletoanothertablewith
thesamestructurewithnorowscopied.
46.Howtofetchcommonrecordsfromtwotables?
Commonrecordsresultsetcanbeachievedby.
1 Select studentID from student. <strong>INTERSECT

47.Howtofetchalternaterecordsfromatable?
RecordscanbefetchedforbothOddandEvenrow
numbers.
Todisplayevennumbers.
1 Select studentId from (Select rowno, studentId from

Todisplayoddnumbers.
1 Select studentId from (Select rowno, studentId from

from(Selectrowno,studentIdfromstudent)where
mod(rowno,2)=1.[/sql]
48.Howtoselectuniquerecordsfromatable?
SelectuniquerecordsfromatablebyusingDISTINCT
keyword.
1 Select DISTINCT StudentID, StudentName from Student

49.Whatisthecommandusedtofetchfirst5
http://career.guru99.com/top50sqlquestionanswers/

12/15

4/16/2015

Top50SQLQuestion&Answers

charactersofthestring?
Therearemanywaystofetchfirst5charactersofthe
string.
1 Select SUBSTRING(StudentName,1,5) as studentname
1 Select RIGHT(Studentname,5) as studentname from

50.Whichoperatorisusedinqueryforpattern
matching?
LIKEoperatorisusedforpatternmatching,anditcanbe
usedas.
1. %Matcheszeroormorecharacters.
2. _(Underscore)Matchingexactlyonecharacter.
Example.
1 Select * from Student where studentname like a%
1 Select * from Student where studentname like ami

SQL Quiz

Start
Axis Bank
Axis Bank is proud to partner with
You Might Like

Top50Oracle
Interview

Top50Database
Interview

http://career.guru99.com/top50sqlquestionanswers/

13/15

4/16/2015

Top50SQLQuestion&Answers

Top25Database
TestingInterview

Top13Hbase
interview

Share this entry

WHAT'STHIS?

AROUNDTHEWEB

WSJCustomStudiosNarratives
Stack

Nigeria'sPartnership VIDEO:Eastbay
withMasterCardCouldPresents
ProvideMillionswith PreparationNation:
FinancialAccess
Crespi

Web2Carz.com

FlyingCarsHave
Arrived.SoWhat?
ALSOONCAREERGURU99

Top50LinuxInterview
Questions4comments

Top100JavaInterview
QuestionswithAnswers

Top50Datawarehousing
Questions&Answers

Top85JavaScriptInterview
Questions4comments

Comments

Community

http://career.guru99.com/top50sqlquestionanswers/

Login
14/15

4/16/2015

Comments

Community

Recommend 1

Top50SQLQuestion&Answers

Login

SortbyBest

Startthediscussion

CopyrightCareerGuru992015

http://career.guru99.com/top50sqlquestionanswers/

15/15

Anda mungkin juga menyukai