Stored Procedures - Do you know SQL stored procedure names should be prefixed with the owner?

Updated by Brook Jeynes [SSW] 2 years ago. See history

123
<introEmbed body={<> Always specify the schema prefix when creating stored procedures. This way you know that it will always be dbo.procedure_name no matter who is logged in when it is created. There are 2 other benefits to including the schema prefix on all object references: 1. This prevents the database engine from checking for an object under the users schema first 2. Also avoids the issue where multiple plans are cached for the exact same statement/batch just because they were executed by users with different default schemas. </>} />

Aaron Bertrand agrees with this rule - My stored procedure "best practices" checklist.

CREATE PROCEDURE procCustomer_Update @CustomerID INT,.. BEGIN

❌ Figure: Figure: Bad example

CREATE PROCEDURE dbo.procCustomer_Update @CustomerID INT,.. BEGIN

✅ Figure: Figure: Good example

Acknowledgements

Adam Cogan
Related rules

Need help?

SSW Consulting has over 30 years of experience developing awesome software solutions.

We open source.Loving SSW Rules? Star us on GitHub. Star