Solved

trigger DDL - create sp_

Posted on 2014-12-10
5
138 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 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:
ScottPletcher 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Inner Join Vs SubQueries 9 26
Mssql SQL query 14 29
Access Migration to Sql Server 2 22
SQL JOIN + SUBQUERY? 3 15
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now