Script rules


Issues to do with the SQL script and not the SQL itself.


SC001 – Script should end with GO

GO has nothing to do with SQL and is not interpreted by SQL Server. It signals the end of a batch on the client (e.g. SSMS) in order to ensure that several batches can be sent from one file or script.

SC002 – Script should end with empty line

Many editing tools will get confused  if the last line  in a text file is not terminated with a newline or carriage return / new line combination.

SC003 – There should be no USE statement in batch

It is unusual to need to jump between database contexts in the middle of a batch, though it is allowed.

SC004 – Found TODO comment

There is a -- TODO Task...  comment left in the code.

This rule also matches bug, fix and warning comments left in code.

SC005 – The procedure grants itself permissions.

The procedure grants itself permissions. This may indicate that a GO is missing.

Consider the following:

CREATE PROCEDURE MyProc
AS
    BEGIN
        SET NOCOUNT ON;
    END;
 
GRANT EXECUTE ON MyProc TO PUBLIC;
GO

In the above example, if GO is omitted before the GRANT statement, the procedure will be created with the GRANT statement included as part of the body of the procedure, and no rights will be granted during script execution. It is very unusual for a stored procedure to legitimately grant rights to itself, which is why this pattern should be flagged.

SC006 – The EOL marker sequence is not expected CR/LF

The EOL marker sequence is not the expected CR/LF.



Didn't find what you were looking for?