Solved

trigger DDL - create sp_

Posted on 2014-12-10
5
146 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 100 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 65

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 69

Accepted Solution

by:
Scott Pletcher earned 400 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

735 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