SQL coding guidelines
The purpose of these guidelines is to provide Thinkwise Platform developer with best practices for programming control procedure templates in T-SQL.
General​
- Use a domain with domain elements if you need to program on values.
- Avoid the use of the
distinctkeyword. - Avoid the use of
unionwithoutall. - Use
local static read_only forward_onlycursors. - Use
beginandendin IF and WHILE statements. - Use
tsf_send_messageto send messages instead ofraiserror. - Only use
applywhen joining a table valued function or a subquery. - Make sure every task and procedure containing a
begin tranhas correspondingrollback tranandcommit transtatements.
Triggers​
- Avoid using triggers for complex data mutations. Do use triggers for checking functional integrity of data.
- Every statement should make use of the
insertedordeletedtable. - Avoid the use of cursors.
- Avoid the use of explicit transactions (
begin tran). - Avoid the use of variables.
- Avoid the use of temporary tables.
- Don't update the
insertedordeletedtables.
Defaults​
- Templates should contain an IF statement.
- Don't reset input parameter values.
- Avoid the use of cursors.
- Avoid the use of explicit transactions (
begin tran). - Don't do inserts, updates or deletes on tables.
- Avoid the use of temporary tables.
Layouts, Contexts, Processes​
- Templates should contain an IF statement.
- Don't reset input parameter values.
- Avoid the use of cursors.
- Avoid the use of explicit transactions (
begin tran). - Don't do inserts, updates or deletes on tables.
- Avoid the use of temporary tables.
- Don't send messages (using
tsf_send_messageorraiserror).
Tasks and Subroutines (stored procedures)​
- Avoid the use of cursors.
- Always use explicit transactions (
begin tran,commit tran,rollback tran). - When using cursors, every iteration should be a new transaction.
Subroutines (functions)​
- Avoid the use of cursors.
- Avoid the use of explicit transactions (
begin tran). - Don't do inserts, updates or deletes on tables.
- Don't send messages (using
tsf_send_messageorraiserror).