表A
id pid description
100 1 aaa
101 1 bbb
102 2 ccc
...
现在想把表A的pid=1的再copy一份到原表,其它不变,id为自增型。
要求用while 去做。因为表A有触发器要运行。
有其它简单解决办法更好。
在此先谢谢各位路过的朋友。
id pid description
100 1 aaa
101 1 bbb
102 2 ccc
...
现在想把表A的pid=1的再copy一份到原表,其它不变,id为自增型。
要求用while 去做。因为表A有触发器要运行。
有其它简单解决办法更好。
在此先谢谢各位路过的朋友。
insert into 表 select * from 表A where pid=12、用游标
declare @id int,@pid int,@desc varchar(20)
declare tc cursor for select * from 表A where pid=1open tcfetch next from tc into @id,@pid,@descwhile @@fetch_status=0
begin
insert into 表 values(@id,@pid,@desc) fetch next from tc into @id,@pid,@desc
endclose tc
deallocate tc
insert into 表A select * from 表A where pid=1
2、用游标
declare @pid int,@desc varchar(20)
declare tc cursor for select pid,description from 表A where pid=1open tcfetch next from tc into @pid,@descwhile @@fetch_status=0
begin
insert into 表A values(@pid,@desc) fetch next from tc into @pid,@desc
endclose tc
deallocate tc
能简单举个例吗?
create table A(id int identity(100,1), pid int, [description] varchar(10))
insert A(pid, [description]) select 1, 'aaa'
insert A(pid, [description]) select 1, 'bbb'
insert A(pid, [description]) select 2, 'ccc'insert A(pid, [description]) select pid, [description] from A where pid=1select * from A--result
id pid description
----------- ----------- -----------
100 1 aaa
101 1 bbb
102 2 ccc
103 1 aaa
104 1 bbb(5 row(s) affected)
create table t2(id int identity(10,1),t1_id int,code varchar(10))
gocreate trigger trg_t1 on t1
for insert
as
insert into t2 select id,'' from inserted
goinsert into t1 select 'AAAA' union select 'BBBB'select * from t1
select * from t2
godrop trigger trg_t1
drop table t1,t2
go
insert into t2 select id,'' from inserted
inserted -- 请问这个是什么东西啊?