| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#61
|
||||
|
||||
|
Make SQL Statements more readable
To make SQL Statements more readable, start each clause on a new line and indent when needed. Following is an example:
Code:
SELECT title_id, title
FROM titles
WHERE title LIKE '%Computer%' AND
title LIKE '%cook%'
__________________
Please give respect to those that helped solve an issue by clicking on the icon
|
|
#62
|
||||
|
||||
|
Increase timeouts
When querying a database, the default timeout is often low, like 30 seconds. Remember that report queries may run longer than this, specially when your database grows. Hence increase this value to an acceptable value
|
|
#63
|
||||
|
||||
|
In SQL Server 2000 - use SCOPE_IDENTITY not SELECT max()
Dont do SELECT max(ID) from MasterTable when inserting in a Details table. This is a common mistake, and will fail when concurrent users are inserting data at the same instance. Use one of SCOPE_IDENTITY or IDENT_CURRENT. My choice would be SCOPE_IDENTITY as this would give you the identity value from the current context in prespective.
|
|
#64
|
||||
|
||||
|
Use MS Access/SQL Server SQL analyzers
The SQL Server query analyzer is a powerful tool. And surely is your friend, and you'll learn a lot of how it works and how the query and index design can affect performance through it. Understand the execution plan that the execution plan window shows for potential bottlenecks
|
|
#65
|
||||
|
||||
|
When using Joins
Make sure that there are n-1 join criteria if there are n tables.
Make sure that ALL tables included in the statement are joined. Make sure that only tables that · Have columns in the select clause · Have columns referenced in the where clause · Allow two unrelated tables to be joined together are included. |
|
#66
|
||||
|
||||
|
Apply the latest Security Packs / Service Packs
Even though this point applies to the network and the database administrators, it is always better to keep up-to date on the software’s. With the "slammer" virus and many more still outside, it is one of the best practices to be up-to date on the same. Consider this strongly.
|
|
#67
|
||||
|
||||
|
Using Count
The only 100 percent accurate way to check the number of rows in a table is to use a COUNT(*) operation. The statement might consume significant resources if your tables are very big because scanning a large table or index can consume a lot of I/O. Avoid these type of queries to the maximum. Use short circuting methods as EXISTS etc. Here is one other way you can find the total number of rows in a table. SQL Server Books Online (BOL) documents the structure of sysindexes; the value of sysindexes.indid will always be 0 for a table and 1 for a clustered index. If a table doesn't have a clustered index, its entry in sysindexes will always have an indid value of 0. If a table does have a clustered index, its entry in sysindexes will always have an indid value of 1. Code:
SELECT object_name(id) ,rowcnt FROM sysindexes WHERE indid IN (1,0) AND OBJECTPROPERTY(id, 'IsUserTable') = 1 Last edited by bslintx : August 9th, 2005 at 09:37 AM. |
|
#68
|
||||
|
||||
|
nice work Bslintx!
Can't rep++ ATM, but good job, you working overtime? ![]()
__________________
Look! Its a ShemZilla ![]() ![]()
|
|
#69
|
||||
|
||||
|
SQL injection
Security has been a prime concern for everyone. Hence validate all the incoming parameters at all levels of the application. Limit the scope of possible damage by permitting only minimally privileged accounts to send user input to the server. Adding to it, run SQL Server itself with the least necessary privileges
|
|
#70
|
||||
|
||||
|
Quote:
thanks bud...i can't do yours either but it seems a lil slow in the forum and i took a couple weeks off and i needed to catch up on updating this thread AND i noticed you and elija are tearing it up on the rep points....fantastic...pheeeew, lots of room to make up....good job!!! keep it up |
|
#71
|
||||
|
||||
|
Tips for cleaning up query strings
Last edited by Shadow Wizard : August 18th, 2005 at 02:23 AM. Reason: added [url] and [/url] tags around links to make them clickable :) |
|
#72
|
||||
|
||||
|
Quote:
I would strongly agree with this, but used the rep++ earlier Last edited by elijathegold : August 18th, 2005 at 03:04 AM. |
|
#73
|
||||
|
||||
|
Quote:
|