Login
Register
All Activity
Questions
Unanswered
Tags
Users
Ask a Question
About Us
986
Questions
785
Answers
Interview Preparation mode
beta
Funny Facebook Status
Enter your email address
All categories
SQL Server Interview Questions and Answers
(197)
SSIS Interview Questions and Answers
(54)
SSRS Interview Questions and Answers
(9)
SSAS Interview Questions and Answers
(29)
.NET Interview Questions and Answers
(186)
Oracle Interview Questions and Answers
(122)
Java Interview Questions and Answers
(32)
UNIX Interview Questions and Answers
(47)
Networking Interview Questions and Answers
(17)
MySQL Interview Questions and Answers
(30)
HR Interview Questions and Answers
(237)
General Interview Questions and Answers
(9)
Other Interview Questions and Answers
(8)
Job Openings
(3)
Greenplum Database Interview Questions and Answers
(5)
What are all the best practices you follow in SQL server which will increase the performance ?
Nice?
Vote!
1. Create a primary key on each table you create and unless you are really knowledgeable enough to figure out a better plan, make it the clustered index (note that if you set the primary key in Enterprise Manager it will cluster it by default).
2. Create an index on any column that is a foreign key. If you know it will be unique, set the flag to force the index to be unique.
3. Don’t index anything else (yet).
4. Unless you need a different behaviour, always owner qualify your objects when you reference them in TSQL. Use dbo.sysdatabases instead of just sysdatabases.
5. Use set nocount on at the top of each stored procedure (and set nocount off) at the bottom.
6. Think hard about locking. If you’re not writing banking software, would it matter that you take a chance on a dirty read? You can use the NOLOCK hint, but it’s often easier to use SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED at the top of the procedure, then reset to READ COMMITTED at the bottom.
7. I know you’ve heard it a million times, but only return the columns and the rows you need.
8. Use transactions when appropriate, but allow zero user interaction while the transaction is in progress. I try to do all my transactions inside a stored procedure.
9. Avoid temp tables as much as you can, but if you need a temp table, create it explicitly using Create Table #temp.
10. Avoid NOT IN, instead use a left outer join - even though it’s often easier to visualize the NOT IN.
11. If you insist on using dynamic sql (executing a concatenated string), use named parameters and sp_executesql (rather than EXEC) so you have a chance of reusing the query plan. While it’s simplistic to say that stored procedures are always the right answer, it’s also close enough that you won’t go wrong using them.
12. Get in the habit of profiling your code before and after each change. While you should keep in mind the depth of the change, if you see more than a 10-15% increase in CPU, Reads, or Writes it probably needs to be reviewed.
13. Look for every possible way to reduce the number of round trips to the server. Returning multiple resultsets is one way to do this.
14. Avoid index and join hints.
15. When you’re done coding, set Profiler to monitor statements from your machine only, then run through the application from start to finish once. Take a look at the number of reads and writes, and the number of calls to the server. See anything that looks unusual? It’s not uncommon to see calls to procedures that are no longer used, or to see duplicate calls. Impress your DBA by asking him to review those results with you.
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
siva
(
10,720
points)
perfomance
in
sqlserver
Your answer
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or
register
.
0 Answers
Related questions
Nice?
Vote!
1
answer
What are the best practices to follow to secure connection strings in an ASP.NET web application?
asked
1 year
ago
in
.NET Interview Questions and Answers
by
KrishnaMachiraju
(
7,980
points)
asp-net
net-interview-question
Nice?
Vote!
1
answer
What are some of the Reporting Services best practices that you follow?
asked
1 year
ago
in
SSRS Interview Questions and Answers
by
R
(
19,530
points)
ssrs
ssrs-interview-question
junior-sql-server-developer-interview-questions
best-practices
Nice?
Vote!
1
answer
What are cursors and what are the situations you will use them, in MS SQL Server?
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
R
(
19,530
points)
sql-server-interview-question
t-sql
cursor
Nice?
Vote!
1
answer
What are the best practices to keep in mind when accepting user input on a web application?
asked
1 year
ago
in
.NET Interview Questions and Answers
by
KrishnaMachiraju
(
7,980
points)
asp-net
net-interview-question
Nice?
Vote!
Add
Ans!
You have an assembly, which is dependent on other assemblies; will SQL Server load the dependent assemblies?
asked
1 year
ago
in
SQL Server Interview Questions and Answers
by
Boni
(
860
points)
sql-server-interview-question
net-interview-question
assembly