Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

trigger DDL - create sp_

Posted on 2014-12-10
5
Medium Priority
?
161 Views
Last Modified: 2014-12-24
Hi Experts, as I can avoid stored procedures with the prefix "sp_" are created
0
Comment
Question by:enrique_aeo
  • 2
  • 2
5 Comments
 
LVL 66

Assisted Solution

by:Jim Horn
Jim Horn earned 400 total points
ID: 40493090
If your question is 'Why shouldn't I create stored procedures with a prefix of 'sp_' it's because SQL Server treats them as system stored procedures (special?) which can be accessed from any database, and having a user-defined stored procedure prefixed sp_ could cause problems if there's a system stored procedure with the same name.

If your question is something else, please ask it in simple English, as it's not obvious reading this question.
0
 

Author Comment

by:enrique_aeo
ID: 40494018
When a developer trying to create a stored procedmiento that has the sp_ prefix need a DDL trigger is triggered by rollback
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 40494107
Please ask your question in the form of a question.
0
 

Author Comment

by:enrique_aeo
ID: 40494137
Please support the creation of a trigger that prevents creating a stored procedure where the name begins with prefix "sp_"
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 1600 total points
ID: 40494742
CREATE TRIGGER [ddl_trigger_create_proc]
ON DATABASE
AFTER CREATE_PROCEDURE
AS
DECLARE @name nvarchar(128)
SET @name = EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(128)')
IF @name LIKE 'sp[_]%'
BEGIN
    RAISERROR ('You cannot create a stored procedure with a name starting with "sp_".  Re-create with a different name!', 16, 1)
    ROLLBACK TRANSACTION
END --IF
GO
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question