SQL Interview Ques 1
SQL Interview Ques 1
SQL Interview Ques 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/
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?
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/
WHERE
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.
Create a job with an optimal script that will update the Master table by the Feed table.
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
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.
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)
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
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