62,269
社区成员
发帖
与我相关
我的任务
分享
CREATE TRIGGER [trigger1] ON [dbo].[Table2]
FOR DELETE
AS
declare @aa int
begin
select @aa=count (*) from table2
if(@aa>10)
begin
update table1 set uid='1'
end
if(@aa<=10)
begin
update table1 set uid='0'
end
end
CREATE TRIGGER [trigger] ON dbo.Table2
FOR INSERT
AS
declare @aa int
begin
select @aa=count (*) from table2
if(@aa>10)
begin
update table1 set uid='1'
end
if(@aa<=10)
begin
update table1 set uid='0'
end
end
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Table1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Table1]
GO
CREATE TABLE [dbo].[Table1] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[uid] [int] NULL
) ON [PRIMARY]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Table2]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Table2]
GO
CREATE TABLE [dbo].[Table2] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO