SQL Server Performance Improvement Method)

Source: Internet
Author: User

1: Do not use functions on columns. You can use functions on scalar.

For example, if where dateadd (Day, 15, orderdate) = '2014/1/80', change it to orderdate = dateadd (day,-15, '2014/1/123 ');

2: do not declare a char variable to be compared with the nchar column. On the contrary, nvarcha and varchar are the same. During the comparison, the convert function is implicitly used, and thus the index may not be used.

3: do not join unnecessary tables. Avoid using distinct clauses whenever possible.

4: Select * not only increases network traffic, but also easily causes table scanning. Use the where statement to limit the rows you return and return large result sets by page, returns only the rows and columns you need.

5: Do not use any predicate such as <> and not like as few as possible. replace them with if exists and if not exists, so that you can use indexes.

6: Advantages of stored procedures: logical separation, separation of business logic and data processing logic; adjustment of SQL statements does not require redeploymentProgramReduces network bandwidth, improves security and integration, and assigns access permissions to stored procedures.[Not sure whether it is possible];Parameterized query prevents SQL injection and re-Compilation of query plans

7: The use of cursors will repeatedly extract rows, lock, manage locks, return rows, and other operations. To use them, try to use read-only forward cursors instead of FireWire cursors, which will increase the pressure on tempdb.[Not Sure].Usually, the cursor is used to process consecutive rows. If the table has a primary key, a while statement can be used to replace the use of the cursor.

8: after the transaction starts, the resource will be locked to prevent other transactions from being executed. Therefore, keep the transaction as short as possible. You can start a transaction in the application. A common practice is to verify the data validity before starting the transaction. Of course, you also need to verify the data in the transaction, however, this avoids many chances of rollback in the transaction.

9:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.