Try to always use the smallest data type and index all the fields most used in queries.
If possible, try to avoid server-side cursors. Always follow a “set-based approach” instead of a “procedural approach” for accessing and managing data. Cursors can often be avoided by using SELECT statements instead.
Always use the graphical execution plan in the Query Analyzer or SHOWPLAN_TEXT or SHOWPLAN_ALL commands to analyze your queries. Make sure your queries perform an “index scan” and not an “index scan” or “table scan”. Crawling a table or crawling an index is a very bad thing and should be avoided whenever possible. Select the correct indexes in the right column. Use more readable ANSI-Standard join conditions rather than old-style joins. When connecting ANSI, the WHERE clause is used only to filter data. Where, as in the case of the old style, the WHERE clause processes both the join condition and the filtering data.
Do not allow your external applications to directly query / manipulate data using SELECT or INSERT / UPDATE / DELETE statements. Instead, create stored procedures and let your applications access these stored procedures. This ensures the purity and consistency of data access in all modules of your application and at the same time centralizes the business logic in the database.
Speaking of stored procedures, do not name the stored procedures "sp_". The sp_ prefix is reserved for the system stored procedure that ships with SQL Server. Whenever SQL Server comes across a procedure name starting with sp_, it first tries to find the procedure in the main database, then it searches for the provided qualifiers (database, owner), then tries dbo as the owner. This way you can save time when searching for a stored procedure by avoiding the "sp_" prefix.
Avoid dynamic SQL statements as much as possible. Dynamic SQL tends to be slower than static SQL because SQL Server must generate an execution plan every time it runs.
Whenever possible, try using integrated authentication. This means that you forget about sa and other SQL users, use the infrastructure to provide microsoft users, and always keep your SQL server up to date with all the necessary fixes. Microsoft is doing a good job of developing, testing, and releasing patches, but it's your job of applying it.
Find good reviews about it at amazon.com and buy it!
VP. Sep 19 '08 at 11:47 2008-09-19 11:47
source share