Seems like a dangerous way to create TRIGGERs and a fast way to trash your databse, but here you go:
Code:
CREATE PROCEDURE trigger_gen
AS
DECLARE @Sql VARCHAR(255)
SET @Sql = ''
IF [i]Condition[/i] = 1
BEGIN
SET @Sql = 'CREATE TRIGGER trigger_name
AS
[i]trigger stuff[/i]'
EXECUTE (@Sql);
END
That's the basics. To my knowledge you cannot use CREATE in a StProc. You have to EXECUTE it separately as shown above. I'm sure someone else has a better way, but that will get there.
--------------------------------------------------
Bluto: What? Over? Did you say "over"? Nothing is over until we decide it is! Was it over when the Germans bombed Pearl Harbor? No!
Otter: Germans?
Boon: Forget it, he's rolling.
--------------------------------------------------
I know it looks like dangerous but it is not. Thanks for your response. Yes, we need to execute this temporary proc to create the trigger. We drop the temporary proc after creating the trigger. Thanks any way.
If I am doing this from the scratch, I do not go with this approach but we are migrating from some old systems to sql08. So I am just following their old methods to convert into the sql. Lets see how it goes.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.