新建触发器判断问题
在表TABLE 里建触发器,只要table里面有增 删 该,就触发。
触发器的内容是,
先判断数据库里面 有没有表TB1和TB2,如果有就删除,如果没有就新建这2张表,
大概要怎么写,
------解决方案--------------------CREATE Trigger [dbo].[Trigger]
On [dbo].[Table]
For insert, update, delete
As
begin
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB1]') AND type in (N'U'))
DROP TABLE [dbo].[TB1]
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB2]') AND type in (N'U'))
DROP TABLE [dbo].[TB2]
CREATE TABLE [dbo].[TB1](
[ID] [int]
)
CREATE TABLE [dbo].[TB2](
[ID] [int]
)
end