SQL MCQ Set 1
1. Syntax for using linked server stored procedure in SQL Server is :
a)
sp_linkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ] [ , [ @provider= ] 'provider_name' ] [ , [ @datasrc= ] 'data_source' ] [ , [ @location= ] 'location' ] [ , [ @provstr= ] 'provider_string' ] [ , [ @catalog= ] 'catalog' ]
b)
sp_addlinked [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ] [ , [ @provider= ] 'provider_name' ] [ , [ @datasrc= ] 'data_source' ] [ , [ @location= ] 'location' ] [ , [ @provstr= ] 'provider_string' ] [ , [ @catalog= ] 'catalog' ]
c)
sp_addlinkedserver [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ] [ , [ @provider= ] 'provider_name' ] [ , [ @datasrc= ] 'data_source' ] [ , [ @location= ] 'location' ] [ , [ @provstr= ] 'provider_string' ] [ , [ @catalog= ] 'catalog' ]
d)
sp_addlinkedser [ @server= ] 'server' [ , [ @srvproduct= ] 'product_name' ] [ , [ @provider= ] 'provider_name' ] [ , [ @datasrc= ] 'data_source' ] [ , [ @location= ] 'location' ] [ , [ @provstr= ] 'provider_string' ] [ , [ @catalog= ] 'catalog' ]
Answer
Answer: c [Reason:] After a linked server is created by using sp_addlinkedserver, distributed queries can be run against this server.
2. Point out the correct statement :
a) To access a mirrored database, a connection string must contain the database name
b) When the linked server is defined against an instance of SQL Server, catalog refers to the default database to which the linked server is mapped
c) [ @location= ] ‘location’ is the location of the database as interpreted by the OLE DB provider in sp_addlinkedserver
d) All of the mentioned
Answer
Answer: d [Reason:] Location parameter is passed as the DBPROP_INIT_LOCATION property to initialize the OLE DB provider.
3. sp_addlinkedserver command creates a distributed server entry called _________ in the following code :
sp_addlinkedserver @server = "Northwinds", @srvproduct = "Access 97", @Provider = "Microsoft.Jet.OLEDB.3.51", @datasrc = "c:brianwritingsqlservermagnov98nwind.mdb"
a) Access 97
b) Microsoft.Jet.OLEDB.3.51
c) nwind
d) Northwinds
Answer
Answer: d [Reason:] The command uses the Microsoft.Jet.OLEDB.3.51 OLE DB provider linking to an Access database located at c:brianwritingsqlservermagnov98nwind.mdb.
4. Which of the following command tells that all local users are logged in as “sa” in the following code ?
EXEC sp_addlinkedsrvlogin @rmtsrvname = "Northwinds", @useself = "false", @locallogin = "sa", @rmtuser = "Admin", @rmtpassword = NULL
a) sp_addlinkedsrv
b) sp_addlinkedserver
c) sp_addlinkedsrvlogin
d) None of the mentioned
Answer
Answer: c [Reason:] sp_addlinkedsrvlogin creates or updates a mapping between a login on the local instance of SQL Server and a security account on a remote server.
5. Point out the wrong statement :
a) SQL Server cannot use execution strategies that involve using the procedures of the Table provider to evaluate predicates
b) For a distributed query, the comparison semantics for all character data is defined by the character se
c) SQL Server can delegate comparisons and ORDER BY operations on character columns to a provide
d) None of the mentioned
Answer
Answer: a [Reason:] SQL Server can use execution strategies that involve using the indexes of the Index provider to evaluate predicates and perform sorting operations against remote tables. To enable indexed access against a provider, set the IndexAsAccessPath provider option.
6. Which of the following function mainly used for bulk load data is referenced in the following code ?
SELECT RemoteOrders.* FROM OpenRowset("Microsoft.Jet.OLEDB.3.51", "c:brianwritingsqlservermagnov98nwind.mdb"; "admin"; , "select * from orders") RemoteOrders LEFT JOIN MasterOrders ON RemoteOrders.OrderId = MasterOrders.OrderId WHERE MasterOrders.OrderID = NULL
a) OpenRowset
b) Microsoft.Jet.OLEDB
c) admin
d) All of the mentioned
Answer
Answer: a [Reason:] The OPENROWSET function can be referenced in the FROM clause of a query as if it were a table name.
7. Which of the following SQL syntax elements is dictated by the SQL dialect levels ?
a) LIKE support
b) Parameter marker support
c) Nested query support
d) None of the mentioned
Answer
Answer: d [Reason:] System administrator should set the NestedQueries provider option to indicate to SQL Server that the provider supports nested queries.
8. Which of the following function will be preferred for faster execution in following code ?
SELECT RemoteOrders.* FROM ________(Northwinds, "select * from orders") RemoteOrders LEFT JOIN MasterOrders ON RemoteOrders.OrderId = MasterOrders.OrderId WHERE MasterOrders.OrderID = NULL
a) OpenRow
b) OpenSQL
c) OpenQuery
d) All of the mentioned
Answer
Answer: c [Reason:] OpenQuery runs a little faster because you’re using the connection information that you already supplied using sp_addlinkedserver.
9. Which of the following query combines data from more than one SQL Server instance ?
a)
USE SCRATCH GO SELECT TOP 1000 * FROM REMOTE.Scratch.dbo.Table1 T1 INNER JOIN REMOTE.Scratch.dbo.Table2 T2 ON T1.ID = T2.ID
b)
USE SCRATCH GO SELECT * FROM dbo.Table1 T1 INNER JOIN REMOTE.Scratch.dbo.Table2 T2 ON T1.ID = T2.ID WHERE T1.GUIDSTR < '001'
c)
USE SCRATCH GO SELECT TOP 500 * FROM REMOTE.Scratch.dbo.Table1 T1 OUTER JOIN REMOTE.Scratch.dbo.Table2 T2 ON T1.ID = T2.ID
d) None of the mentioned
Answer
Answer: b [Reason:] Table1 from LOCAL is being joined to Table2 on REMOTE, with a restriction being placed on Table1’s GUIDSTR column by the WHERE clause.
10.The easiest way to start is to create a linked server ‘localhost’ by using :
a) sp_addlinkedserv ‘localhost’
b) sp_addlinkedsrvlogin ‘localhost’
c) sp_addlinkedserverlogin ‘localhost’
d) sp_addlinkedserver ‘localhost’
Answer
Answer: d [Reason:] “localhost” linked server is created when you reference objects using a four-part name in the form linkedserver.catalog.schema.object.
SQL MCQ Set 2
1. Trigger is special type of __________ procedure.
a) Stored
b) Function
c) View
d) Table
Answer
Answer: a [Reason:] Triggers are used to assess/evaluate data before or after data modification using DDL and DML statements.
2. Point out the correct statement :
a) Triggers are database object
b) Three types of triggers are present in SQL Server
c) A DDL trigger is an action programmed to execute when a data manipulation language (DML) event occurs in the database server
d) None of the mentioned
Answer
Answer: a [Reason:] Triggers are special type of stored procedure that automatically execute when a DDL or DML statement associated with the trigger is executed.
3. How many types of triggers are present in SQL Server ?
a) 4
b) 5
c) 8
d) 9
Answer
Answer: a [Reason:] In Sql Server we can create four types of triggers Data Definition Language (DDL) triggers, Data Manipulation Language (DML) triggers, CLR triggers and Logon triggers.
4. How many types of DML triggers are present in SQL Server ?
a) 1
b) 3
c) 5
d) None of of the mentioned
Answer
Answer: d [Reason:] We have two types of DML triggers-AFTER and INSTEAD OF.
5. Point out the wrong statement :
a) We can have an INSTEAD OF insert/update/delete trigger on a table that successfully executed
b) DML Triggers are used to evaluate data after data manipulation using DML statements
c) INSTEAD OF triggers cause their source DML operation to skip
d) AFTER triggers cause their source DML operation to skip
Answer
Answer:d [Reason:] INSTEAD OF triggers cause their source DML operation to skip and they just execute the code provided inside them.
6. AFTER trigger in SQL Server can be applied to :
a) Table
b) Views
c) Table and Views
d) function
Answer
Answer: c [Reason:] AFTER trigger fires after SQL Server completes the execution of the action successfully that fired it.
7. DML triggers in SQL Server is applicable to :
a) Insert
b) Update
c) Delete
d) All of the mentioned
Answer
Answer: d [Reason:] In SQL Server we can create triggers on DML statements (like INSERT, UPDATE, and DELETE) and stored procedures that perform DML-like operations.
8. Triggers created with FOR or AFTER keywords is :
a) AFTER
b) INSTEAD OF
c) CLR
d) All of the mentioned
Answer
Answer: a [Reason:] AFTER triggers do not work for views.
9. Which of the following is not a typical trigger action ?
a) Insert
b) Select
c) Delete
d) All of the mentioned
Answer
Answer: b [Reason:] Valid trigger actions are INSERT, UPDATE and DELETE, or a combination of several, separated by commas.
10. Triggers can be enabled or disabled with the ________ statement.
a) ALTER TABLE statement
b) DROP TABLE statement
c) DELETE TABLE statement
d) None of the mentioned
Answer
Answer: a [Reason:] You can also use the ALL keyword instead of a trigger name to enable/disable all of the triggers on a table in question.
SQL MCQ Set 3
1. Which of the following is way to build dynamic sql statements ?
a) Writing a query with parameters
b) Using sp_executesql
c) Using EXEC
d) All of the mentioned
Answer
Answer: d [Reason:] SQL Server offer three ways of running a dynamically built SQL statement.
2. Point out the correct statement :
a) ODBC has the call ExecDirect
b) Few database systems provide the facilities for running SQL code directly against the database engine
c) The SQL code is not stored in the source program, but rather it is generated based on user input
d) None of the mentioned
Answer
Answer: c [Reason:] The SQL code can include determining not only what objects are involved, but also the filter criteria and other qualifiers that define the set of data being acted on.
3. Dynamic SQL Statements in SQL Server can be easily built using :
a) Cursor
b) Stored procedure
c) Function
d) All of the mentioned
Answer
Answer: b [Reason:] Dynamic SQL is a term used to mean SQL code that is generated programatically (in part or fully) by your program before it is executed.
4. The calling syntax for sp_executesql is as follows:
a) sp_execute <@stmt> [<@param1 data_type>,<@param2 data_type>, …].
b) sp_sql <@stmt> [<@param1 data_type>,<@param2 data_type>, …].
c) sp_executesql <@stmt> [<@param1 data_type>,<@param2 data_type>, …].
d) sp_executesql [<@param1 data_type>,<@param2 data_type>, …].
Answer
Answer: c [Reason:] Using sp_executesql to run dynamic statements gives us a couple advantages over EXEC that are worth noting.
5. Point out the wrong statement :
a) The @stmt parameter in sp_executesql is a Unicode string containing valid SQL commands
b) The input type @Type is passed as the first parameter to sp_executesql
c) We can specify the parameters for both input and output in sp_executesql
d) None of the mentioned
Answer
Answer: b [Reason:] The output type @retType is passed as the second parameter to sp_executesql.
6. Below Code is procedure for dynamic SQL using ___________ parameter.
CREATE PROCEDURE GetArticle @ArticleID INT AS SELECT ArticleTitle, ArticleBody FROM Articles WHERE ArticleID = @ArticleID GO -
a) input and output
b) input
c) output
d) All of the mentioned
Answer
Answer: b [Reason:] The output of an SP could also be returned in an output parameter.
7. The Dynamic SQL Queries in a variable are __________ until they are executed.
a) Compiled
b) Parsed
c) Checked for errors
d) All of the mentioned
Answer
Answer: d [Reason:] A Dynamic SQL is needed when we need to retrieve a set of records based on different search parameters.
8. The basic syntax for using EXECUTE command:
a) SP_EXECUTE(@SQLStatement)
b) EXEC_SQL(@SQLStatement)
c) EXECUTE(@SQLStatement)
d) All of the mentioned
Answer
Answer: c [Reason:] EXECUTE command is demonstrated using :
SET @SQLQuery = 'SELECT * FROM tblEmployees WHERE EmployeeID = ' + CAST(@EmpID AS NVARCHAR(10)) EXECUTE(@SQLQuery)
.
9. Which of the following is a disadvantage of dynamic SQL ?
a) Stored procedure can not cache the execution plan for this dynamic query
b) Stored procedure can cache the execution plan for this dynamic query
c) Flexability in your code that you can not get with standard SQL
d) All of the mentioned
Answer
Answer: a [Reason:] Stored procedure can not cache the execution plan for this dynamic query. So, for complex queries you will lose a the performance boost that you usually gain with stored procedures.
10. Which of the stored procedure used for dynamic SQL is prone to attacks ?
a) xp_executesql
b) executesql
c) sp_execute
d) sp_executesql
Answer
Answer: d [Reason:] sp_executesql executes a Transact-SQL statement or batch that can be reused many times, or one that has been built dynamically.Run time-compiled Transact-SQL statements can expose applications to malicious attacks.
SQL MCQ Set 4
1. Which of the following blocks are used for error handling in SQL Server ?
a) TRY…CATCH
b) TRY…FINAL
c) TRY…END
d) CATCH…TRY
Answer
Answer: a [Reason:] SQL Server 2005 introduced TRY…CATCH statement which helps us to handle the errors effectively in the back end.
2. Point out the correct statement :
a) While executing some DML Statement like INSERT, DELETE, UPDATE we can handle the error for checking proper output
b) If transaction fails, then we need to commit – This can be done by error handling
c) If transaction succeeds, then we need to rollback – This can be done by error handling
d) None of the mentioned
Answer
Answer: a [Reason:] SQL Server also has an exception model to handle exceptions and errors that occurs in T-SQL statements.
3. Which of the following statements can be checked for Errors ?
a) CREATE
b) DROP
c) DELETE
d) INSERT
Answer
Answer: d [Reason:] DML statements can be checked for handling errors.
4. Purpose of TRY…CATCH block in SQL Server is :
a) Error handling
b) Stored Procedure handling
c) Message handling
d) None of the mentioned
Answer
Answer: a [Reason:] TRY… CATCH implements error handling for Transact-SQL that is similar to the exception handling in the Microsoft Visual C#.
5. Point out the wrong statement :
a) If an error occurs in the TRY block, control is not passed to another group of statements that is enclosed in a CATCH block
b) If an error occurs in the TRY block, control is passed to another group of statements that is enclosed in a CATCH block
c) If an error does not occur in the TRY block, control is passed to another group of statements that is enclosed in a CATCH block
d) None of the mentioned
Answer
Answer: b [Reason:] A TRY…CATCH construct catches all execution errors that have a severity higher than 10 that do not close the database connection.
6. Which of the following beenfit does Exception handling with the TRY and CATCH blocks provide ?
a) Exceptions provide a mechanism to signal errors directly rather than using some side effects
b) Exceptions can be seen by the programmer and checked during the compilation process
c) Exceptions provide a clean way to check for errors without cluttering code
d) All of the mentioned
Answer
Answer: d [Reason:] Exception handling using the TRY and CATCH statements is the common way that modern programming languages like C# and Java treat errors.
7. Exception handling is possible in SQL Server using :
a) THROW
b) FINAL
c) FINALLY
d) All of the mentioned
Answer
Answer: a [Reason:] Generates an error message and initiates error processing for the session.
8. Which of the following is a Error function used within CATCH block ?
a) ERROR_STATE()
b) ERROR_STATUS()
c) ERROR_MSG()
d) All of the mentioned
Answer
Answer: a [Reason:] ERROR_STATE() returns the state number of the error.
9. ERROR_SEVERITY() returns the ________level of the error.
a) State number
b) Full text
c) Severity
d) None of the mentioned
Answer
Answer: c [Reason:] ERROR_SEVERITY() returns the severity level of the error.
10. Which of the following is global variable for error handling ?
a) @@ERRORS
b) @@ERROR
c) @@ERR
d) None of the mentioned
Answer
Answer: b [Reason:] @@ERROR is one of the basic error handling mechanisms in SQL Server.
SQL MCQ Set 5
1. Which of the following is a extended event task ?
a) create an Extended Events session
b) alter an Extended Events session
c) find out what events are available in the registered packages
d) All of the mentioned
Answer
Answer: d [Reason:] Using Management Studio or Transact-SQL to execute Transact-SQL Data Definition Language statements, dynamic management views and functions, or catalog views, you can create simple or complex SQL Server Extended Events troubleshooting solutions for your SQL Server environment.
2. Point out the correct statement :
a) The SQL Server Extended Events engine is a collection of services and objects
b) Buffers are attached to sessions to handle buffering and dispatch, and causality tracking
c) Policy tracking provides the ability to track work across multiple tasks
d) None of the mentioned
Answer
Answer: a [Reason:] The Extended Events engine itself does not provide any events or actions to take when an event fires.
3. SQL Server Extended Events Packages consist of :
a) Events
b) Predicates
c) Types
d) All of the mentioned
Answer
Answer: d [Reason:] Packages are identified by a name, a GUID, and the binary module that contains the package.
4. Which of the DDL statement creates a session object that contains the metadata ?
a) CREATE EVENT SESSION
b) CREATE SESSION
c) CREATE EVENT SESSION METADATA
d) None of the mentioned
Answer
Answer: a [Reason:] CREATE EVENT SESSION creates an Extended Events session that identifies the source of the events, the event session targets, and the event session options.
5. Point out the wrong statement :
a) Actions and predicates are bound to events on a per-session basis
b) Extended Event sessions have implied boundaries in that the configuration of one session does change the configuration of another session
c) The mapping between package objects and sessions is many to many
d) None of the mentioned
Answer
Answer: b [Reason:] Boundaries do not prevent an event or target from being used in more than one session.
6. _________ can be applied to the metadata or to an active session and the metadata.
a) DROP EVENT SESSION
b) ALTER EVENT SESSION,STATE=STOP
c) ALTER EVENT SESSION,STATE=START
d) All of the mentioned
Answer
Answer: d [Reason:] Both ALTER EVENT SESSION and DROP EVENT SESSION can be applied to the metadata or to an active session and the metadata.
7. Which of the following catalog view is used for SQL Server Extended Events ?
a) sys.server_sessions
b) sys.server_event_sess
c) sys.server_event_session_actions
d) All of the mentioned
Answer
Answer: c [Reason:] sys.server_event_session_actions returns a row for each action on each event of an event session.
8. _________ returns a row for each customizable column that was explicitly set on events and targets.
a) sys.server_event_session_targets
b) sys.server_event_session_fields
c) Returns a row for each event in an event session
d) All of the mentioned
Answer
Answer: b [Reason:] sys.server_event_session_fields requires VIEW SERVER STATE permission on the server.
9. Which of the following pair of views has one to many relationship ?
a) sys.server_event_session_actions.event_session_id, sys.sys.server_event_sessions.event
b) sys.server_event_session_actions, sys.sys.server_event_sessions.event_session_id
c) sys.server_event_session_actions.event_session_id,sys.sys.server_event_sessions.event _session_id
d) None of the mentioned
Answer
Answer: c [Reason:] Almost all the extended event views has one to many cardinality.
10. Which of the following format output events in an Event Tracing for Windows ?
a) event_file
b) ring_buffer
c) histogram
d) etw_classic_sync_target
Answer
Answer: d [Reason:] histogram outputs events to memory in order to group and count events based on fields or actions.
Synopsis and Project Report
You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com