Solved

trigger DDL - create sp_

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

792 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