Вы находитесь на странице: 1из 8

1.

Difference between SQL Server 2000 & SQL Server 2005 features, or new features of
2005 vs 2000.
- Ranking functions (ROW_NUMBER, RANK, DENSE_RANK, NTILE)
- Exception handling (TRY-CATCH block)
- CTE (Common Table Expressions)
- PIVOT, UNPOVIT
- CUBE, ROLUP & GROUPING SET
- SYNOMYMS
More Info: http://www.sqlservercentral.com/articles/Administration/2988/

2. What tools do you use for performance tuning?


Query Analyzer, Profiler, Index Wizard, Performance Monitor
Link: http://www.sqlteam.com/article/sql-server-2000-performance-tuning-tools

3. What is SQL Profiler? What it does? What template do you use?


More Info: http://www.extremeexperts.com/SQL/Articles/TraceTemplate.aspx
http://msdn.microsoft.com/en-us/library/ms190176.aspx

4. How can you execute an SQL query from command prompt?


OSQL & SQLCMD
More Info: http://msdn.microsoft.com/en-us/library/ms162773.aspx
http://blog.sqlauthority.com/2009/01/05/sql-server-sqlcmd-vs-osql-basic-comparison/
http://www.databasejournal.com/features/mssql/article.php/3654176/SQL-Server-2005-
Command-Line-Tool-SQLCMD–Part-I.htm

5. Difference between DELETE & TRUNCATE statement? Which statement can be


Rollbacked?
- 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

6. What are extended stored procedures? Can you create your own extended stored-proc?
More Info: http://msdn.microsoft.com/en-us/library/ms175200.aspx
http://msdn.microsoft.com/en-us/library/ms164627.aspx

7. How can you execute a DOS command from SQL or through SQL query by using
xp_cmdshell?

1 exec xp_cmdshell 'dir c:\*.exe'


More Info: http://msdn.microsoft.com/en-us/library/aa260689%28SQL.80%29.aspx
http://msdn.microsoft.com/en-us/library/ms175046.aspx

8. How will you insert result set of the above proc in a table?

1 insert into
2 exec xp_cmdshell 'dir c:\*.exe'

9. 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.
More Info: http://msdn.microsoft.com/en-us/library/ms180169.aspx
http://www.sql-server-performance.com/tips/cursors_p1.aspx

10. Why you should not use a cursor? What are its alternatives?
Alternatives: while loops with temp tables, derived tables, correlated sub-queries, CASE stmt
More Info: http://www.sql-server-performance.com/tips/cursors_p1.aspx
http://sqlserverpedia.com/wiki/Cursor_Performance_Issues
http://searchsqlserver.techtarget.com/feature/Part-3-Cursor-disadvantages

11. Difference between LEFT JOIN with WHERE clause & LEFT JOIN with no WHERE
clause.
OUTER LEFT/RIGHT JOIN with WHERE clause can act like an INNER JOIN if not used
wisely or logically.

12. How will you migrate an SSIS package from Development to Production environment?
Do not include db connections and file paths in your workflow, instead create configuration files.
This will help in deploying the pkg created in DEV server to Testing and finally to the PROD
environment.
More Info: http://msdn.microsoft.com/en-us/library/cc966389.aspx
http://www.wpconfig.com/2010/03/26/ssis-package-configurations/

13. Multiple ways to execute a dynamic query.


EXEC sp_executesql, EXECUTE()
More Info: http://www.mssqltips.com/tip.asp?tip=1160

14. Difference between COALESCE() & ISNULL()


More Info: http://sqlwithmanoj.wordpress.com/2010/12/23/isnull-vs-coalesce/

15. Which of the following has higher performance:


a. OR, AND
b. =, <>, >
c. IN, NOT IN, EXISTS
d. UNION, UNION ALL
16. What should be the ideal combination with IN & UNION (ALL) in terms of
performance?
a. SELECT *FROM
WHERE

IN (SELECT… UNION SELECT…)


OR
b. SELECT * FROM

WHERE

IN (SELECT… UNION ALL SELECT…)

17. What is an IDENTITY column and its usage in INSERT statements?


IDENTITY column can be used with a tables column to make it auto incremental, or a surrogate
key.
MS BOL link: http://msdn.microsoft.com/en-us/library/ms174639(v=SQL.90).aspx

18. Can you create a Primary key without clustered index?


Creation of PK automatically creates a clustered index upon the column(s).
More Info: http://vadivel.blogspot.com/2006/03/primary-keys-without-clustered-index.html

19. There are two tables one Master and another Feed table, both with 2 columns: ID &
Price. Feed table gets truncated and re-populated every day.

Master Table Feed Table


ID, Price ID, Price
1 100 1 200
3 200 2 250
5 300 4 500
6 400 6 750
7 500 7 800

Create a job with an optimal script that will update the Master table by the Feed table.

20. What are CUBE & ROLLUP sets?


CUBE & ROLLUP are the grouping sets used with GROUP BY clause and are very helpful in
creating reports.
More Info: http://msdn.microsoft.com/en-us/library/ms177673.aspx

21. What new indexes are introduced in SQL Server 2005 in comparison to 2000?
- Spatial
- XML
More Info: http://msdn.microsoft.com/en-us/library/ms175049.aspx

22. What are XML indexes, what is their use?


More Info: http://msdn.microsoft.com/en-us/library/ms345121%28SQL.90%29.aspx
23. How many types of functions (UDF) are there in SQL Server? What are inline
functions?
- Scalar functions
- Inline Table-valued functions
- Multi-statement Table-valued functions
More Info: http://sqlwithmanoj.wordpress.com/2010/12/11/udf-user-defined-functions/
http://msdn.microsoft.com/en-us/library/ms189593.aspx

24. How will you handle exceptions in SQL Server programming?


By using TRY-CATCH constructs, putting our SQL statements/scripts inside the TRY block and
error handling in the CATCH block.
More Info: http://msdn.microsoft.com/en-us/library/ms179296%28v=SQL.90%29.aspx

25. How would you send an e-mail form SQL Server?


More Info: http://msdn.microsoft.com/en-us/library/ms175887%28v=SQL.90%29.aspx

26. What are the virtual tables in Triggers?


Inserted & Deleted

27. What is benefit of a having stored-procedure?

28. Can stored-procedures be recursive? And upto how much level?


Yes, 32 levels.

29. How you can load large data in SQL Server?


BulkCopy is a tool used to copy huge amount of data from tables. BULK INSERT command
helps to Imports a data file into a database table or view in a user-specified format.

30. What is the trade-offs of a BCP command, when various users are loading data in a
particular table at same time?

31. How can you copy schema from one SQL Server to another?
DTS, import/export wizard.
Scripting out Database objects.

32. What is the benefit of a Temporary Table, how would you define it?

33. What is a table called that has ## before its name, what is its scope?
Table with ## (double pound signs) is called Global Temp table. Scope is outside the session but
only till the original session lasts.

34. What is the scope of a temporary table?


Scope is limited to its session only.
35. What is Mutex error in Triggers?
MSDN link: http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/c86c97a7-73ea-
482e-9529-e2407bd7018c

36. What is the use of WITH (nolock)?


Table Hints, MS BOL: http://msdn.microsoft.com/en-us/library/ms187373(v=SQL.90).aspx
http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-
ideas.aspx?wa=wsignin1.0

37. What are the various Isolation levels?


a) Read Uncommitted Isolation Level
b) Read Committed Isolation Level
c) Repeatable Read Isolation Level
d) Serializable Isolation Level
e) Snapshot Isolation Level
f) Read Committed Snapshot Isolation Level
http://www.sql-server-performance.com/articles/dba/isolation_levels_2005_p1.aspx

38. What are implicit & explicit cursors?


http://geekexplains.blogspot.com/2008/11/implicit-vs-explicit-cursors-static-vs.html

39. Define the life cycle of a Cursor.


http://sqlserverpedia.com/wiki/Built-in_Functions_-_Cursor_Functions

40. How would you know that if a cursor is open or closed?

declare @mycursor cursor


declare @FirstName varchar(12)
 
select CURSOR_STATUS('variable','@mycursor') --// -2 (Not applicable)
 
set @mycursor = cursor for
select FirstName from Person.Contact
select CURSOR_STATUS('variable','@mycursor') --// -1 (The cursor is closed)

 
open @mycursor

 
select CURSOR_STATUS('variable','@mycursor') --// 1 (The result set of the
cursor has at least one row)
 
fetch next from @mycursor into @FirstName
select CURSOR_STATUS('variable','@mycursor') --// 1 (The result set of the
cursor has at least one row)
 
close @mycursor

 
select CURSOR_STATUS('variable','@mycursor') --// -1 (The cursor is closed)

 
deallocate @mycursor

 
select CURSOR_STATUS('variable','@mycursor') --// -2 (Not applicable)

 
select CURSOR_STATUS('variable','@nocursor') --// -3 (A cursor with the
specified name does not exist)

41. How many non-clustered indexes can you have in a table?


Upto 249 non-clustered indexes can be created in a table.

42. What all indexes can you have in a table?


One Clustered Index, one or more than one non-clustered index, unique index, filtered, spatial,
xml, etc.
MS BOL: http://msdn.microsoft.com/en-us/library/ms175049.aspx

43. How will you know what indexes a particular table is using?

44. What is the benefit of cross joins? How would you use a where clause with Cross Joins?
The common example is when company wants to combine each product with a pricing table to
analyze each product at each price.
http://weblogs.sqlteam.com/jeffs/archive/2005/09/12/7755.aspx
http://www.dotnetspider.com/forum/44591-why-we-use-cross-join-sqlserver.aspx

45. Difference between VARCHAR & VARCHAR2?


VARCHAR2 is specific to Oracle. MS SQL Server has VARCHAR & VARCHAR(MAX) data
types.

46. What is de-normalization?


De-normalization is the process of attempting to optimize the performance of a database by
adding redundant data. It is sometimes necessary because current DBMSs implement the
relational model poorly. A true relational DBMS would allow for a fully normalized database at
the logical level, while providing physical storage of data that is tuned for high performance. De-
normalization is a technique to move from higher to lower normal forms of database modeling in
order to speed up database access. http://social.msdn.microsoft.com/Forums/en-
US/transactsql/thread/8c54d1d2-5fbd-4b62-a07f-16c34a863668
47. How would you get error & row number at the same time?
If @@Rowcount is checked after Error checking statement then it will have 0 as the value of
@@Recordcount as it would have been reset.
And if @@Recordcount is checked before the error-checking statement then @@Error would
get reset. To get @@error and @@rowcount at the same time do both in same statement and
store them in local variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR
http://blog.sqlauthority.com/2007/04/20/sql-server-interview-questions-part-6/

48. What is Collation?


MS BOL link: http://msdn.microsoft.com/en-us/library/aa174903(v=sql.80).aspx
My Blog link: http://sqlwithmanoj.wordpress.com/page/2/?s=collation

49. Types of Replication? Difference between Merge & Transactional Replication.


MS BOL link: http://msdn.microsoft.com/en-us/library/ms165713(v=sql.90).aspx

50. What can you do with COLASCE function?


MS BOL link: http://msdn.microsoft.com/en-us/library/ms190349.aspx

51. What are Integrity Constraints?


http://sqlwithmanoj.wordpress.com/2010/11/23/integrity-constraints/

52. Difference between:


- Views, Tables & Stored Procedures
- Stored Procedures & Functions
- Sub Query & Co-related sub-query
- Physical & Logical Schema
- Table variable & Temporary Tables
- UNIQUE and CLUSTERED INDEXES
- Triggers and Constraints
- Primary Key & Unique Key

53. What do you mean by Referential Integrity? How will you attain it?
By using Foreign Keys.
http://www.databasedesign-resource.com/referential-integrity.html

54. What is the sequence for logical query processing, what is the order?
FROM, [JOIN CONDITION, JOIN TABLE ...], ON, OUTER, WHERE, GROUP BY,
CUBE/ROLLUP/GROUPING SETS, HAVING, SELECT, DISTINCT, ORDER BY, TOP
http://tsql.solidq.com/books/insidetsql2008/Logical%20Query%20Processing%20Poster.pdf

55. How you debug Stored Procedures?


http://support.microsoft.com/kb/316549
http://www.sqlteam.com/article/debugging-stored-procedures-in-visual-studio-2005
http://www.15seconds.com/issue/050106.htm
56. What is ANSI_NULL?
http://sqlwithmanoj.wordpress.com/2010/12/10/set-ansi_nulls-quoted_identifier-ansi_padding/

57. How will you rename a table?


By using sp_rename stored procedure.

58. What are ACID properties, define them?


A – Atomicity (Transaction is atomic, if one part fails, then the entire transaction fails)
C – Consistency (Any transaction the database performs will take it from one consistent state to
another, only valid data will be written to the database)
I – Isolation (Other operations cannot access data that has been modified during a transaction
that has not yet completed)
D – Durability (On a transaction’s success the transaction will not be lost, the transaction’s data
changes will survive system failure, and that all integrity constraints have been satisfied)
More on: http://en.wikipedia.org/wiki/ACID

59. What is a Live Lock?


http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/478aa50f-b7dd-43fb-
bb90-813057a6a1ed
http://blog.sqlauthority.com/2008/03/21/sql-server-introduction-to-live-lock-what-is-live-lock/

Вам также может понравиться