Re: help with DDL trigger. Moved from other newsgroup.

> Were you able to get yourtriggerworking, by the way?
>
> --
> Erland Sommarskog,SQLServerMVP, esq... [at] sommarskog.se
>
Erland,

Yes, thank you very much for you help. (I just got back from
vacation). Your last recommendation about the GO was the key.

Actually, I now want to enhance my process. If you recall from my
original postings, I have this third party utility that puts their
data from their program into SQL Server. It does this for a bunch of
tables, however, I only need 4 of them, so I would like to skip the
inserts on the other tables to save a whole lot of time. I am
wondering if I can use a DDL trigger to detect the table being
created, then have it create a DML trigger which basically has it
ignore the insert. However, what I came up with does not parse
successfully. It's almost like you are not allowed to do a trigger
within a trigger.

CREATE TRIGGER [NO_SOUP_FOR_YOU] ON DATABASE
FOR CREATE_TABLE
AS
SET NOCOUNT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET QUOTED_IDENTIFIER ON
DECLARE [at] xmlEventData XML,
[at] tableName VARCHAR(50)
SET [at] xmlEventData = eventdata()
SET [at] tableName = CONVERT(VARCHAR(25), [at] xmlEventData.query('data(/
EVENT_INSTANCE/ObjectName)'))
IF [at] tableName ='ISTD7291'
BEGIN
CREATE TRIGGER NOINSERT_ISTD7291
ON ISTD7291
INSTEAD OF INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Do nothing
END
END
RogBaker [ Mo, 07 April 2008 17:13 ] [ ID #1937128 ]

Re: help with DDL trigger. Moved from other newsgroup.

(RogBaker [at] gmail.com) writes:
> However, what I came up with does not parse
> successfully. It's almost like you are not allowed to do a trigger
> within a trigger.
>....
> BEGIN
> CREATE TRIGGER NOINSERT_ISTD7291
> ON ISTD7291
> INSTEAD OF INSERT
> AS
> BEGIN
> -- SET NOCOUNT ON added to prevent extra result sets from
> -- interfering with SELECT statements.
> SET NOCOUNT ON;
> -- Do nothing
> END
> END

You need to do that part with dynamic SQL, as you appears to have found
out.



--
Erland Sommarskog, SQL Server MVP, esquel [at] sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx
Erland Sommarskog [ Mo, 07 April 2008 23:49 ] [ ID #1937133 ]
Datenbanken » comp.databases.ms-sqlserver » Re: help with DDL trigger. Moved from other newsgroup.

Vorheriges Thema: Update including Top, Orderby and updating 2 columns in an update
Nächstes Thema: Re: help with DDL trigger. Thanks, figured it out