表A position code
A1 123
A2 124
A5 125
A6 126表B code intime
123 2010-11-4 08:08:20
124 2010-11-5 04:01:11
125 2010-11-5 13:01:30
126 2010-11-7 09:11:04
要求: 当表A插入数据的时候 如 ‘A7’ ‘127’
表B中自动增加一行:‘127’ ‘当前时间’
这个怎么实现? 应该是用触发器吧? 该怎么写?先谢谢进来的各位了!
A1 123
A2 124
A5 125
A6 126表B code intime
123 2010-11-4 08:08:20
124 2010-11-5 04:01:11
125 2010-11-5 13:01:30
126 2010-11-7 09:11:04
要求: 当表A插入数据的时候 如 ‘A7’ ‘127’
表B中自动增加一行:‘127’ ‘当前时间’
这个怎么实现? 应该是用触发器吧? 该怎么写?先谢谢进来的各位了!
output inserted.code,
getdate()
into b(code,intime)
select 'A7','127'-- sql 2005
if object_id('[a]') is not null drop table [a]
go
create table [a] (code varchar(20),col varchar(20))
--> 测试数据: [b]
if object_id('[b]') is not null drop table [b]
go
create table [b] (code varchar(20),intime datetime)
insert a
output inserted.code,
getdate()
into b(code,intime)
select 'A7','127'
select * from a
select * from bcode col
-------------------- --------------------
A7 127(1 行受影响)code intime
-------------------- -----------------------
A7 2010-11-16 12:01:43.123(1 行受影响)
AFTER INSERT
AS
INSERT INTO [表B]
SELECT INSERTED.code ,GETDATE()
AFTER INSERT
AS
INSERT INTO [表B]
SELECT INSERTED.code ,GETDATE() FROM INSERTED
AFTER INSERT
AS
INSERT INTO [表B]
SELECT code ,GETDATE()
FROM INSERTED