Professional Documents
Culture Documents
TSSQL Interview Questions
TSSQL Interview Questions
FROM HumanResources.Department
WHERE (GroupName = 'Executive General and Administration')
Name
HR
Finance
Executive
Can We Create Trigger on Temp Tables and System Tables in SQL Server
NOT on temp but we can on system
Question 10. Difference Between Delete & Truncate Statement? Which Statement Can Be
Rollbacked?
Answer :
With DELETE we can provide conditional WHERE clause to remove/delete specific rows,
which is not possible with TRUNCATE.
TRUNCATE is faster than DELETE as Delete keeps log of each row it deletes in
transaction logs, but truncate keeps log of only de-allocated pages in transaction
logs.
Both statements can be rolled backed if provided in a transaction (BEGIN TRANS). If
not then none of them can be rollbacked.
DELETE is DML just like INSERT, UPDATE, but TRANCATE is DDL, just like CREATE,
ALTER, DROP.
Question 24. What Is A Table Called That Has ## Before Its Name, What Is Its Scope?
Answer :
Table with ## (double pound signs) is called Global Temp table. Scope is outside
the session but only till the original session lasts.
Answer :
Question 44. How Many Types Of Recovery Models Are Available For A Database?
Answer :
Simple
Bulk logged
Full.
Question 45. How Many Types Of Temporary Tables Are There In Sql Server?
Answer :
http://www.sql-server-performance.com/articles/dba/isolation_levels_2005_p1.aspx
101. What are the required/mandatory parameters that have to be passed with
RAISEERROR statement?
Newly introduced THROW keyword in SQL server 2012 is an improvement over the
existing RAISERROR() statement. Yes, it’s single ‘E’ in RAISERROR.
Both RAISERROR & THROW can be used in T-SQL code/script to raise and throw error
within a TRY-CATCH block. Check my previous post for TRY-CATCH block, [link].
–> With RAISERROR developers had to use different ERROR_xxxx() system functions to
get the error details to pass through the RAISERROR() statement, like:
– ERROR_NUMBER()
– ERROR_MESSAGE()
– ERROR_SEVERITY()
– ERROR_STATE()
Answer :
VARCHAR2 is specific to Oracle. MS SQL Server has VARCHAR & VARCHAR(MAX) data
types.
What are Cursors and their types? What type do you use most and which one is fast?
FORWARD-ONLY, FAST-FORWARD or READ-ONLY cursors.
Fastest to slowest: Dynamic, Static, and Keyset.
21. What new indexes are introduced in SQL Server 2005 in comparison to 2000?
– Spatial
– XML
84. How will you check if a stored procedure with 500 line of code is running very
slow? What steps will you take to optimize it?
DIRTY READS: Reading uncommitted modifications are call Dirty Reads. Values in the
data can be changed and rows can appear or disappear in the data set before the end
of the transaction, thus getting you incorrect or wrong data.
This happens at READ UNCOMMITTED transaction isolation level, the lowest level.
Here transactions running do not issue SHARED locks to prevent other transactions
from modifying data read by the current transaction. This also do not prevent from
reading rows that have been modified but not yet committed by other transactions.
To prevent Dirty Reads, READ COMMITTED or SNAPSHOT isolation level should be used.
–> PHANTOM READS: Data getting changed in current transaction by other transactions
is called Phantom Reads. New rows can be added by other transactions, so you get
different number of rows by firing same query in current transaction.
In REPEATABLE READ isolation levels Shared locks are acquired. This prevents data
modification when other transaction is reading the rows and also prevents data read
when other transaction are modifying the rows. But this does not stop INSERT
operation which can add records to a table getting modified or read on another
transaction. This leads to PHANTOM reads.
PHANTOM reads can be prevented by using SERIALIZABLE isolation level, the highest
level. This level acquires RANGE locks thus preventing READ, Modification and
INSERT operation on other transaction until the first transaction gets completed.
declare
@date1 datetime,
@date2 datetime,
@diff int
begin