Hello,
I have a general trigger program used for many tables, but how do I refer to
the tablename currently been modified in my script?
Thanks!
PerCREATE TABLE TT
(
COL INT
)
CREATE TRIGGER MY_TR ON TT
FOR INSERT
AS
DECLARE @.ObjID int
SET @.ObjID = (SELECT parent_obj FROM sysobjects WHERE id = @.@.PROCID)
SELECT OBJECT_NAME(@.ObjID) AS 'Parent Table'
INSERT INTO TT VALUES (1)
SELECT * FROM TT
DROP TABLE TT
"Per Buus S?rensen" <PerBuusSrensen@.discussions.microsoft.com> wrote in
message news:99BA6A44-27DC-4D58-8794-7A90F24A2B8F@.microsoft.com...
> Hello,
> I have a general trigger program used for many tables, but how do I refer
> to
> the tablename currently been modified in my script?
> Thanks!
> Per
>|||Working perfect :-)
Thanks!
"Uri Dimant" wrote:
> CREATE TABLE TT
> (
> COL INT
> )
> CREATE TRIGGER MY_TR ON TT
> FOR INSERT
> AS
> DECLARE @.ObjID int
> SET @.ObjID = (SELECT parent_obj FROM sysobjects WHERE id = @.@.PROCID)
> SELECT OBJECT_NAME(@.ObjID) AS 'Parent Table'
> INSERT INTO TT VALUES (1)
> SELECT * FROM TT
> DROP TABLE TT
>
>
> "Per Buus S?rensen" <PerBuusSrensen@.discussions.microsoft.com> wrote in
> message news:99BA6A44-27DC-4D58-8794-7A90F24A2B8F@.microsoft.com...
>
>|||I'm not certain what you mean by a "general trigger program". If you
mean you are generating and re-using the same code for each table then
surely you would put the table name in there when you generate the
code, in which case there would be no need to do it dynamically at
runtime. That's the method I would recommend anyway.
If you mean you are calling the same proc from each trigger then Uri's
code won't help you. In that case I think you will have to pass the
table name as a parameter.
David Portas
SQL Server MVP
--|||The code was OK, I am writting one procedure which can apply to many tables,
however I have a issue with dynamic SQL, which I have put in a new post.
Per
"David Portas" wrote:
> I'm not certain what you mean by a "general trigger program". If you
> mean you are generating and re-using the same code for each table then
> surely you would put the table name in there when you generate the
> code, in which case there would be no need to do it dynamically at
> runtime. That's the method I would recommend anyway.
> If you mean you are calling the same proc from each trigger then Uri's
> code won't help you. In that case I think you will have to pass the
> table name as a parameter.
> --
> David Portas
> SQL Server MVP
> --
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment