We had a Stored Procedure written and it had a GRANT written at the last line of the SP.. Our DBA recommended that there should be a GO before the GRANT statement, else it will be executed every time.
What does this mean? I am not sure how GO will prevent GRANT executing “every time”.
A stored procedure definition doesn’t have to end with and
END. If you define your procedurelike this:
…then SQL Server will create a procedure that returns a result set, and grant execute permissions on that stored procedure to
user1.If you do something like this, though:
…then SQL Server will create a procedure that both returns a result set, and grants execute permission every time that stored procedure is executed. In other words, the
GRANTis included in the definition of the stored procedure. Probably not what you wanted.A
GOstatement is used to mark the end of a batch in SQL Server. It unambiguously tells SQL Server “I’m done with whatever I was executing in the previous set of statements”. It’s very good practice to add this to the end of every definition in your create scripts; this exact situation has bitten me more than once in the past.