Suggestions for writing stored procedures

xiaoxiao2021-03-05  222

•

Use SQL-92 standard connection syntax.

•

To improve performance, you should use the connection, then use subqueries or nested queries.

•

Ensure that variables and parameters are matched to table data columns.

•

Be sure to use all variables and parameters, or all delete.

•

Place the temporary object to the local whenever possible.

•

Only a temporary table created during the stored procedure.

•

Check the validity of the input parameters.

•

Prioritize Select ... INTO, then use INSERT ... SELECT to avoid a lot of dead locks.

•

The logic unit required for maintenance work; do not create a large or long running process without creating a large amount of or long run.

•

Don't use Select * in any code.

•

Use indentation, blocks, tabs, and spaces during the process (see sample scripts).

•

The T-SQL statement is capitalized.

•

Add a large number of annotations to ensure that the process can be identified. Well comments are used in places that help clarify the process.

•

Includes transaction management unless the process is called from the MTS process. (Write an independent process for the MTS process.)

•

Monitor @@ TRANCOUNT to determine the responsibility level of the transaction.

•

Avoid using GOTO, except in the error handler.

•

Avoid using a nested process.

•

Avoid implicitly parsing object names to make sure all objects are owned by DBO.

转载请注明原文地址:https://www.9cbs.com/read-33629.html

New Post(0)