sql server里如何获得被触发器触发的表名?
1个回答
展开全部
创建表dbo.triggerTest
CREATE TABLE dbo.triggerTest ( rowId INT IDENTITY PRIMARY KEY, someData VARCHAR(50) DEFAULT NEWID() )
GO
---创建触发器
CREATE TRIGGER dbo.itrg_triggerTest ON dbo.triggerTest
FOR INSERT
AS
--查询该触发器触发的表
SELECT @@PROCID, OBJECT_NAME( @@PROCID )
SELECT OBJECT_SCHEMA_NAME( parent_id ) + '.' + OBJECT_NAME( parent_id ) tableName FROM sys.triggers WHERE object_id = @@PROCID
GO
INSERT INTO dbo.triggerTest DEFAULT VALUES
GO
CREATE TABLE dbo.triggerTest ( rowId INT IDENTITY PRIMARY KEY, someData VARCHAR(50) DEFAULT NEWID() )
GO
---创建触发器
CREATE TRIGGER dbo.itrg_triggerTest ON dbo.triggerTest
FOR INSERT
AS
--查询该触发器触发的表
SELECT @@PROCID, OBJECT_NAME( @@PROCID )
SELECT OBJECT_SCHEMA_NAME( parent_id ) + '.' + OBJECT_NAME( parent_id ) tableName FROM sys.triggers WHERE object_id = @@PROCID
GO
INSERT INTO dbo.triggerTest DEFAULT VALUES
GO
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询