Statistics

Total Posts: 34
This Year: 0
This Month: 0
This Week: 0
Comments: 174


RSS 2.0   SocialTwist Tell-a-Friend


Admin

Sign In

Navigation


Recent Posts


On this page....

Smarter the Better – SQL Server Tips – Part 01

Archives

 Full Archives By Category
 2007 Calendar View
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

Categories

CDOSYS (1) Classic ASP (10) Command Line (2) Databases (16) Excel (1) HTML (1) IIS (10) Indexing Service (1) Internet Explorer (7) Media Streaming (1) MS.Net (2) SQA (7) SQL Server (16) Windows OS (2)

Blogroll - Fav Blogs


Acknowledgments

DasBlog Theme Design by: Tom Watts
E-mail: Send mail to the author(s)
Theme Image by: dreamLogic

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Technology Blog

There are many occasions where a SQL Server Developer uses scripts which take longer to execute. I would rather say a wrong choice or approach in writing scripts caused the execution of the script longer. There are smarter ways to achieve results. In this post I will try to consolidate few tips on smarter SQL Server programming.

Do you want to delete all rows from a table?
Use Truncate instead of Delete statement. Truncate is faster and does a reseed of identity column.

Use Owner Name prefix while writing Select statement:
Select thColumnName from dbo.theTableName
If the Owner Name is specified, the SQL Query Optimizer does not have to decide whether to retrieve from dbo.theTableName or some other owner’s table and avoids recompilation.

Do not use “Select Count(*)…”
The better way to fetch the count of rows:
Select rows from sysindexes where id = Object_ID(‘theTableName’) and IndID < 2

Do not use “sp_” prefix in your Stored Procedures:
The prefix “sp_” for Stored Procedures is a reserved prefix in MS SQL Server. When a stored procedure is given a call, the SQL Server first looks for the procedure in System Procedure List and then in User Defined Procedure List; hence delaying the execution of the procedure.

I will try to add more tips like these in future.