日期:2014-05-17 浏览次数:20535 次
CREATE TABLE [a]( [id] [int] IDENTITY(1,1) NOT NULL, [name] [varchar](50) NULL, [age] [varchar](50) NULL, CONSTRAINT [PK_a] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
CREATE TABLE [dbo].[b]( [id] [int] IDENTITY(1,1) NOT NULL, [aid] [int] NULL, [price] [numeric](18, 0) NULL, [count] [numeric](18, 0) NULL, CONSTRAINT [PK_b] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[b] WITH CHECK ADD CONSTRAINT [FK_b_a] FOREIGN KEY([id]) REFERENCES [dbo].[a] ([id]) GO ALTER TABLE [dbo].[b] CHECK CONSTRAINT [FK_b_a] GO
CREATE TABLE [dbo].[c]( [id] [int] IDENTITY(1,1) NOT NULL, [aid] [int] NULL, [bid] [int] NULL, [oldname] [varchar](50) NULL, [name] [varchar](50) NULL, [oldage] [varchar](50) NULL, [age] [varchar](50) NULL, [oldprice] [numeric](18, 0) NULL, [price] [numeric](18, 0) NULL, [oldcount] [numeric](18, 0) NULL, [count] [numeric](18, 0) NULL, CONSTRAINT [PK_c] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
update a set name = '测试',age='10' where id = 1 update b set price = 500,[count] = 300 where id = 1 and aid = 1
id aid bid oldname name oldage age oldprice price oldcount count 1 1 1 名称 测试 20 10 100 500 50 300
Create Trigger upd_adTOc on a for update as if exists (select 1 from inserted,a where inserted.colname=a.colname) begin insert into c select col1,col2... from a end
------解决方案--------------------
楼主如果只有一个表更新呢,那怎么办?
还是说一定是2个表一定是一起更新
如果是第二种情况的话,楼主为何要写出发器,直接在写一条插入语句即可,触发器真是多此一举
------解决方案--------------------