Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 creating trigger in server-side code..

Author  Topic 

SQLIsTheDevil
Posting Yak Master

177 Posts

Posted - 2009-10-01 : 11:13:09
Hey all,

I have a question regarding triggers. When I create a trigger, it gets permenantly attached to the table in question, is that right? In other words, it's like creating a stored procedure, no different, correct?

Thank you.

SQLIsTheDevil
Posting Yak Master

177 Posts

Posted - 2009-10-01 : 11:25:24
What I'm trying to do is insert a query into, say, Table A from server-side code and use a trigger to check if that row was actually inserted into Table A. If it wasn't, record the exact ad-hoc insert query used into, say, Table B for error-checking. Number one, don't know if this is possible. Two, it has to be for a specific insert query, not every single insert statement.

Thank you.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-01 : 13:24:54
Man, this is just like some of the specs I get....

A trigger fires when a DML Actions occurs against a table

Now with that, what do you want to check



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-10-01 : 13:34:17
quote:
Originally posted by SQLIsTheDevil

What I'm trying to do is insert a query into, say, Table A from server-side code and use a trigger to check if that row was actually inserted into Table A. If it wasn't, record the exact ad-hoc insert query used into, say, Table B for error-checking. Number one, don't know if this is possible. Two, it has to be for a specific insert query, not every single insert statement.

Thank you.



Why do you think the insert will fail in the first place?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-01 : 13:39:25
Because it was an "ad-hoc" INSERT

You shouldn't allow Dynamic SQL



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

SQLIsTheDevil
Posting Yak Master

177 Posts

Posted - 2009-10-01 : 14:19:37
Hey Brett,

What do you mean by shouldn't allow dynamic sql?

I may just use a stored procedure to execute the insert query and setup a trigger when the query is executed. Then, I can check the "inserted" table (i.e. select * from inserted...). Sounds a lot less complex than using ad-hoc queries, me thinks.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-10-01 : 14:45:52
What does this mean then?

quote:

record the exact ad-hoc insert query used






Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -