
-- PRIMJER 2:
create proc sp_test1 
as 
go

create trigger tNamingConventionEnforcer
on database
for create_procedure, alter_procedure
as
print 'Nije uspjelo!'
rollback
go

-- fail.
create proc sp_test2
as 
go

alter trigger tNamingConventionEnforcer
on database
for create_procedure, alter_procedure
as
declare @name nvarchar(200)
set @name = (SELECT EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]','nvarchar(200)'))
if @name like 'sp_%' begin
	print 'Procedure names cannot begin with sp_'
	rollback
end
go

-- fail.
create proc sp_test2
as 
go

-- success.
create proc test2
as 
go

-- cleanup.
drop proc [dbo].[sp_test1]
drop proc [dbo].[test2]
drop trigger tNamingConventionEnforcer on database
go
