SQL Server

Published on May 2016 | Categories: Documents | Downloads: 47 | Comments: 0 | Views: 304
of 11
Download PDF   Embed   Report

sql server interview question

Comments

Content

SQL Server interview questions
Explain the use of keyword WITH ENC !"TI#N$ Create a Store "ro%edure with En%ryption$ It is a way to convert the original text of the stored procedure into encrypted form. The stored procedure gets obfuscated and the output of this is not visible to CREATE PR CE!"RE Abc #IT$ E%CR&PTI % A' (( 'E)ECT statement** + What is a linked server in SQL Server& It enables ',) server to address diverse data sources li-e )E !. similarly. It allows Remote server access and has the ability to issue distributed /ueries0 updates0 commands and transactions. 'eatures and %on%epts of (nalysis Servi%es Analysis 'ervices is a middle tier server for analytical processing0 )AP0 and !ata mining. It manages multidimensional cubes of data and provides access to heaps of information including aggregation of data ne can create data mining models from data sources and use it for .usiness Intelligence also including reporting features. 'ome of the -ey features are1 • Ease of use with a lot of wi2ards and designers. • 3lexible data model creation and management • 'calable architecture to handle )AP • Provides integration of administration tools0 data sources0 security0 caching0 and reporting etc. • Provides extensive support for custom applications What is (nalysis servi%e repository& Every Analysis server has a repository to store metadata for the ob4ects li-e cubes0 data sources etc. It5s by default stored in a 6' Access database which can be also migrated to a ',) 'erver database. What is SQL servi%e )roker&

'ervice .ro-er allows internal and external processes to send and receive guaranteed0 asynchronous messaging. 6essages can also be sent to remote servers hosting databases as well. The concept of /ueues is used by the bro-er to put a message in a /ueue and continue with other applications asynchronously. This enables client applications to process messages at their leisure without bloc-ing the bro-er. 'ervice .ro-er uses the concepts of message ordering0 coordination0 multithreading and receiver management to solve some ma4or message /ueuing problems. It allows for loosely coupled services0 for database applications. What is user defined datatypes and when you should *o for the+& "ser defined data types are based on system data types. They should be used when multiple tables need to store the same type of data in a column and you need to ensure that all these columns are exactly the same including length0 and nullability. Parameters for user defined datatype1 %ame 'ystem data type on which user defined data type is based upon. %ullability. 3or example0 a user7defined data type called post,%ode could be created based on %har system data type. What is )it datatype& A bit datatype is an integer data type which can store either a 8 or 9 or null value. -es%ri)e the ./L support SQL server extends$ ',) 'erver :server7side; supports < ma4or elements1 a. Creation of =6) fragments1 This is done from the relational data using 3 R =6) to the select /uery. b. Ability to shred xml data to be stored in the database. c. 3inally0 storing the xml data. Client7side =6) support in ',) 'erver is in the form of ',)=6). It can be described in terms of
• •

./L 0iews1 providing bidirectional mapping between =6) schemas and relational tables. Creation of ./L Te+plates1 allows creation of dynamic sections in =6).

What is SQL Server En*lish Query&

English /uery allows accessing the relational databases through English ,uery applications. 'uch applications permit the users to as- the database to fetch data based on simple English instead of using ',) statements. What is the purpose of SQL "rofiler in SQL server& ',) profiler is a tool to monitor performance of various stored procedures. It is used to debug the /ueries and procedures. .ased on performance0 it identifies the slow executing /ueries. Capture any problems by capturing the events on production environment so that they can be solved. What is ."ath& =Path is an expressions to select a xml node in an =6) document. It allows the navigation on the =6) document to the straight to the element where we need to reach and access the attributes. What are the (uthenti%ation /odes in SQL Server& a. #indows Authentication 6ode :#indows Authentication;1 uses user5s #indows account b. 6ixed 6ode :#indows Authentication and ',) 'erver Authentication;1 uses either windows or ',) server Explain -ata -efinition Lan*ua*e2 -ata Control Lan*ua*e and -ata /anipulation Lan*ua*e$ !ata !efinition )anguage :!!);17 are the ',) statements that define the database structure. Example1 a. CREATE b. A)TER c. !R P d. TR"%CATE e. C 66E%T f. RE%A6E

!ata 6anipulation )anguage :!6);17 statements are used for manipulate or edit data. Example1 a. 'E)ECT 7 retrieve data from the a database b. I%'ERT 7 insert data into a table

c. "P!ATE 7 updates existing data within a table d. !E)ETE e. 6ER+E f. CA))

g. E=P)AI% P)A% h. ) C> TA.)E !ata Control )anguage :!C);17statements to ta-e care of the security and authori2ation. Examples1 a. +RA%T b. RE? >E What are the steps to pro%ess a sin*le SELECT state+ent& 'teps a. The select statement is bro-en into logical units b. A se/uence tree is built based on the -eywords and expressions in the form of the logical units. c. ,uery optimi2er chec-s for various permutations and combinations to figure out the fastest way using minimum resources to access the source tables. The best found way is called as an execution plan. d. Relational engine executes the plan and processes the data Explain 3# Co++and$ +o command is a signal to execute the entire batch of ',) statements after previous +o. What is the si*nifi%an%e of N4LL value and why should we avoid per+ittin* null values& %")) value means that no entry has been made into the column. It states that the corresponding value is either un-nown or undefined. It is different from 2ero or @@. They should be avoided to avoid the complexity in select A update /ueries and also because columns which have constraints li-e primary or foreign -ey constraints cannot contain a %")) value.

What is the differen%e )etween 4NI#N and 4NI#N (LL& "%I % selects only distinct values whereas "%I % A)) selects all values and not 4ust distinct ones.

4NI#N1 'E)ECT columnBnames 3R 6 tableBname9 "%I % 'E)ECT columnBnames 3R 6 tableBnameC 4NI#N (ll1 'E)ECT columnBnames 3R 6 tableBname9 "%I % A)) 'E)ECT columnBnames 3R 6 tableBnameC What is use of -5CC Co++ands& !.CC :!atabase consistency chec-er; act as !atabase console commands for ',) 'erver to chec- database consistency. They are grouped as1 6aintenance1 6aintenance tas-s on !b0 filegroup0 index etc. Commands include !.CC C)EA%TA.)E0 !.CC I%!E=!E3RA+0 !.CC !.REI%!E=0 !.CC '$RI%>!ATA.A'E0 !.CC !R PC)EA%."33ER'0 !.CC '$RI%>3I)E0 !.CC 3REEPR CCAC$E0 and !.CC "P!ATE"'A+E. 6iscellaneous1 Tas-s such as enabling tracing0 removing dll from memory. Commands include !.CC dllname0 !.CC $E)P0 !.CC 3REE'E''I %CAC$E0 !.CC TRACE 330 !.CC 3REE'&'TE6CAC$E0 and !.CC TRACE %. Informational1 Tas-s which gather and display various types of information. Commands include !.CC I%P"T."33ER0 !.CC '$ #C %TI+0 !.CC PE%TRA%0 !.CC ',)PER30 !.CC "TP"T."33ER0 !.CC TRACE'TAT"'0 !.CC PR CCAC$E0 !.CC "'ER PTI %'0 and !.CC '$ #B'TATI'TIC'. ?alidation1 perations for validating on !b0 index0 table etc. Commands include !.CC C$EC>A)) C0 !.CC C$EC>3I)E+R "P0 !.CC C$EC>CATA) +0 !.CC C$EC>I!E%T0 !.CC C$EC>C %'TRAI%T'0 !.CC C$EC>TA.)E0 and !.CC C$EC>!.. What is Lo* Shippin*& )og shipping defines the process for automatically ta-ing bac-up of the database and transaction files on a ',) 'erver and then restoring them on a standbyDbac-up server. This -eeps the two ',) 'erver instances in sync with each other. In case production server fails0 users simply need to be pointed to the standbyDbac-up server. )og shipping primarily consists of < operations1 .ac-up transaction logs of the Production server. Copy these logs on the standbyDbac-up server. Restore the log on standbyDbac-up server.

What is the differen%e )etween a Lo%al and a 3lo)al te+porary ta)le& Temporary tables are used to allow short term use of data in ',) 'erver. They are of C types1 Lo%al 3lo)al nly available to the current !b connection for Available to any connection once created. current user and are cleared when connection They are cleared when the last connection is is closed. closed.

6ultiple users can5t share a local temporary table.

Can be shared by multiple user sessions.

What is the ST4'' and how does it differ fro+ the E"L(CE fun%tion& .oth 'T"33 and REP)ACE are used to replace characters in a string. select replace:EabcdefE0EabE0ExxE; results in xxcdef select replace:EdefdefdefE0EdefE0EabcE; results in abcabcabc #e cannot replace a specific occurrence of FdefG using REP)ACE. select stuff:EdefdefdefE0H0 <0EabcE; results in defabcdef where H is the character to begin replace from and < is the number of characters to replace. What are the rules to use the #W34I-C#L property to define a *lo)ally unique identifier %olu+n& nly one column can exist per table that is attached with R #+"I!C ) property. then use IR #+"I! instead of column name in select list. What is the a%tions prevented on%e referential inte*rity is enfor%ed& Actions prevented are1 • .rea-ing of relationships is prevented once referential integrity on a database is enforced. • Can5t delete a row from primary table if there are related rows in secondary table. • Can5t update primary table5s primary -ey if row being modified has related rows in secondary table. • Can5t insert a new row in secondary table if there are not related rows in primary table. • Can5t update secondary table5s foreign -ey if there is no related row in primary table. What are the %o++ands availa)le for Su++ari6in* -ata in SQL Server& Commands for summari2ing data in ',) 'erver1 Command !escription '"6 'ums related values A?+ C "%T 6A= 6I% Average value Returns number of rows of resultset Returns max value from a resultset Returns min value from a 'yntaxDExample 'E)ECT '"6:'al; as Tot from Table9J 'E)ECT A?+:'al; as AvgB'al from Table9J 'E)ECT C "%T:K; from Table9J 'E)ECT 6A=:'al; from Table9J 'E)ECT 6I%:'al; from ne can

+R "P .& R!ER .&

resultset Arrange resultset in groups 'ort resultset

Table9J
SELECT ZIP,City FROM Emp GROUP BY ZIP SELECT ZIP,City FROM Emp ORDER BY City

List out the differen%e )etween C45E operator and #LL4" operator !ifference between C".E and R ))"P1 C".E It5s an additional switch to +R "P .& clause. It can be applied to all aggregation functions to return cross tabular result sets. . Produces all possible combinations of subtotals specified in +R "P .& clause and a +rand Total. R ))"P It5s an extension to +R "P .& clause. It5s used to extract statistical and summari2ed information from result sets. It creates groupings and then applies aggregation functions on them. Produces only some possible subtotal combinations.

What are the *uidelines to use )ulk %opy utility of SQL Server& .ul- copy is an API that allows interacting with ',) 'erver to exportDimport data in one of the two data formats. .ul- copy needs sufficient system credentials. • %eed I%'ERT permissions on destination table while importing. • %eed 'E)ECT permissions on source table while exporting. • %eed 'E)ECT permissions on sysindexes0 sysob4ects and syscolumns tables. bcp.exe northwind..cust out @c1Lcust.txt@ Mc 7T Export all rows in %orthwind.Cust table to an A'CII7character formatted text file.

What are the %apa)ilities of Cursors& Capabilities of cursors1 • Cursor reads every row one by one. • Cursors can be used to update a set of rows or a single specific row in a resultset • Cursors can be positioned to specific rows. • Cursors can be parameteri2ed and hence are flexible. • Cursors loc- row:s; while updating them. What are the ways to %ontrollin* Cursor 5ehavior& There are C ways to control Cursor behavior1 • Cursor Types1 !ata access behavior depends on the type of cursorJ forward only0 static0 -eyset7drive and dynamic.



Cursor behaviors1 >eywords such as 'CR )) and I%'E%'ITI?E along with the Cursor declaration define scrollability and sensitivity of the cursor.

What are the advanta*es of usin* Stored "ro%edures& Advantages of using stored procedures are1 • They are easier to maintain and troubleshoot as they are modular. • 'tored procedures enable better tuning for performance. • "sing stored procedures is much easier from a +"I end than buildingDusing complex /ueries. • They can be part of a separate layer which allows separating the concerns. $ence !atabase layer can be handled by separate developers proficient in database /ueries. • $elp in reducing networ- usage. • Provides more scalability to an application. • Reusable and hence reduce code. What are the ways to %ode effi%ient transa%tions& 'ome ways and guidelines to code efficient transactions1 • !o not as- for an input from a user during a transaction. • +et all input needed for a transaction before starting the transaction. • Transaction should be atomic • Transactions should be as short and small as possible. • Rollbac- a transaction if a user intervenes and re7starts the transaction. • Transaction should involve a small amount of data as it needs to loc- the number of rows involved. • Avoid transactions while browsing through data.

What are the differen%es a+on* )at%hes2 stored pro%edures2 and tri**ers& 5at%h Collection or group of ',) statements. All statements of a batch are compiled into one executional unit called execution plan. All statements are then executed statement by statement. Stored "ro%edure It5s a collection or group of ',) statements that5s compiled once but used many times. Tri**ers It5s a type of 'tored procedure that cannot be called directly. Instead it fires when a row is updated0 deleted0 or inserted.

What se%urity features are availa)le for stored pro%edures& 'ecurity features for stored procedures1

• • • •

+rants users permissions to execute a stored procedure irrespective of the related tables. +rant users users permission to wor- with a stored procedure to access a restricted set of data yet no give them permissions to update or select underlying data. 'tored procedures can be granted execute permissions rather than setting permissions on data itself. Provide more granular security control through stored procedures rather than complete control on underlying data in tables.

What are the instan%es when tri**ers are appropriate& 'cenarios for using triggers1 • To create a audit log of database activity. • To apply business rules. • To apply some calculation on data from tables which is not stored in them. • To enforce referential integrity. • Alter data in a third party application • To execute ',) statements as a result of an eventDcondition automatically. What are the restri%tions appli%a)le while %reatin* views& Restrictions applicable while creating views1 • A view cannot be indexed. • A view cannot be Altered or renamed. Its columns cannot be renamed. • To alter a view0 it must be dropped and re7created. • A%'IB%"))' and ," TE!BI!E%TI3IER options should be turned on to create a view. • All tables referenced in a view must be part of the same database. • Any user defined functions referenced in a view must be created with 'C$E6A.I%!I%+ option. • Cannot use R #'ET0 "%I %0 T P0 R!ER .&0 !I'TI%CT0 C "%T:K;0 C 6P"TE0 C 6P"TE .& in views. What are the events re%orded in a transa%tion lo*& Events recorded in a transaction log1 • .ro-er event category includes events produced by 'ervice .ro-er. • Cursors event category includes cursor operations events. • C)R event category includes events fired by .%et C)R ob4ects. • !atabase event category includes events of data.log files shrin-ing or growing on their own. • Errors and #arning event category includes ',) 'erver warnings and errors. • 3ull text event category include events occurred when text searches are started0 interrupted0 or stopped. • )oc-s event category includes events caused when a loc- is ac/uired0 released0 or cancelled.

• • • • • • • • • • • •

b4ect event category includes events of database ob4ects being created0 updated or deleted. )E!. event category includes events caused by )E!. calls. Performance event category includes events caused by !6) operators. Progress report event category includes nline index operation events. 'cans event category includes events notifying tableDindex scanning. 'ecurity audit event category includes audit server activities. 'erver event category includes server events. 'essions event category includes connecting and disconnecting events of clients to ',) 'erver. 'tored procedures event category includes events of execution of 'tored procedures. Transactions event category includes events related to transactions. T',) event category includes events generated while executing T',) statements. "ser configurable event category includes user defined events.

-es%ri)e when %he%kpoints are %reated in a transa%tion lo*$ Activities causing chec-points are1 • #hen a chec-point is explicitly executed. • A logged operation is performed on the database. • !atabase files have been altered using Alter !atabase command. • ',) 'erver has been stopped explicitly or on its own. • ',) 'erver periodically generates chec-points. • .ac-up of a database is ta-en.

-efine Trun%ate and -elete %o++ands$ T 4NC(TE This is also a logged operation but in terms of deallocation of data pages. Cannot TR"%CATE a table that has foreign -ey constraints. Resets identity column to the default starting value. Removes all rows from a table. Cannot be Rolled bac-. !!) command -ELETE This is a logged operation for every row. Any row not violating a constraint can be !eleted. !oes not reset the identity column. 'tarts where it left from last. "sed delete all or selected rows from a table based on #$ERE clause. %eed to Commit or Rollbac!6) command

For more questions with answers, follow the link below: http://www.careerride.com/SQLServer-Interview-Questions.aspx

We do not warrant the correctness of content. The risk from using it ies entire ! with the user. Whi e using this document" !ou agree to have read and accepted the terms of use and privac! po ic!.

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close