Set Noccount on
Ignore count (hide 1 rows affected)
With (NOLOCK)
Ignore transaction locks (apply nolock across domains)
Avoid using In,not in,or or having in the WHERE clause.
You can use exist and not exist instead of in and not.
Do not declare numbers in character format, declare character values in numeric format, avoid full table scans
SELECT emp.ename, emp.job from emp WHERE emp.empno = 7369;
Do not use: SELECT emp.ename, emp.job from emp WHERE emp.empno = ' 7369 '
For the rule of the SELECT statement, do the business need those fields to write which fields, do not use *. Also avoid full table scan
Use select Empno,ename,category from emp WHERE empno = ' 7369 '
Instead of using the SELECT * from emp WHERE empno = ' 7369 '
Use like '%parm1% ' carefully, this will cause full table scan, should use like ' parm1% ' to do is index scan
Using Union to implement or operations
Select Id,name,age from table where Name= ' Zhang San ' union ALL select id,name,age from table where age>=18
Do not use Select id,name,age from table where Name= ' Zhang San ' or age>=18
7. Avoid using COUNT (*) to get the number of records in the table
(1) To get the number of records in a table, we typically use the following SQL statement:
SelectCount (*) from Dbo.orders
This statement performs a full table scan to get the number of rows.
(2) But the following SQL statement does not perform a full table scan as it can get the number of rows:
SELECT rows from sysindexes WHERE ID =object_id (' dbo. Orders ') and indid <2
Avoid repeating calls to functions in stored procedures, triggers, functions, and batches, and you should store the results in a variable that you can use directly later.
Instead of using sp_xxx as a naming convention, it causes additional searches and increases I/O (because the system stored procedure name starts with sp_), and this also increases the odds of conflicting with the system stored procedure name.
Simple and Practical article
http://xsxjb.iteye.com/blog/1140036
Some small ways to improve SQL performance