22,209
社区成员
发帖
与我相关
我的任务
分享
USE [Test]
GO
/****** Object: Table [dbo].[Test] Script Date: 08/12/2011 09:28:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Test](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[subject] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[Source] [numeric](18, 0) NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
USE [Test]
GO
/****** Object: Table [dbo].[TestA] Script Date: 08/12/2011 09:28:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TestA](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[subject] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[Source] [numeric](18, 0) NULL,
CONSTRAINT [PK_TestA] PRIMARY KEY CLUSTERED
(
[id] ASC
) ON [PRIMARY]
) ON [PRIMARY]
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER TRIGGER [TriggerName]
ON [dbo].[TestA]
AFTER INSERT,DELETE,UPDATE
AS
if update(Name)
BEGIN
insert into test (name) select name from inserted i
where not exists (select 1 from Test where name=i.name )
END
where not exists (
select 1 from [tabB]
where incm = i.StudID
)
group by i.StudID
不明白这个条件 是什么意思 select 1 from [tabB] where incm = i.StudID
ALTER TRIGGER [updatetabA]
ON tabA
for update,insert
AS
if update(StudID)
BEGIN
insert into
[tabB] (incm)
select
i.StudID from inserted i
where
not exists (select 1 from [tabB] where incm = i.StudID)
group by
i.StudID
end
ALTER TRIGGER [updatetabA]
ON tabA
for update,insert
AS
if update(StudID)
BEGIN
insert into [tabB] (incm) select i.StudID from inserted i
where not exists (
select 1 from [tabB]
where incm = i.StudID
)
group by i.StudID
end
ALTER TRIGGER [updatetabA]
ON tabA
for update,insert
AS
if update(StudID)
BEGIN
insert into [tabB] (incm)
select i.StudID from inserted i
where not exists(select 1 from tabB where incm=i.StudID)
end