INSERT INTO t2(t2.f1,t2.f2, ...)SELECT (t1.f1, t1.f2,...)FROM t1
if exists (select name from sysobjects where name = 'T1')
drop table T1
if exists (select name from sysobjects where name = 'T2')
drop table T2
create table T1
(
XID int not null primary key,
XName nvarchar(100) not null,
XValue int not null
)
create table T2
(
HID int not null primary key,
XID int not null,
XName nvarchar(100) not null,
XValue int not null,
Method smallint not null
)
GO
insert into T1 (XID, XName, XValue) values (1, 'sdkfjs', 2)
GO
insert into T1 (XID, XName, XValue) values (2, 'dlsjdf sdfas dlfas', 100)
GO
insert into T2 (HID, XID, XName, XValue, Method)
select 1, T1.*, 2000 from T1 where XID =1
GO
insert into T2 (HID, XID, XName, XValue, Method)
select 2, T1.*, 2000 from T1 where XID =2
GO
本文介绍了一个SQL脚本示例,展示了如何创建表、插入数据,并从一个表复制数据到另一个表的过程。该脚本包括了创建表T1和T2,向T1中插入数据,以及通过SELECT...INSERT语句将数据从T1迁移到T2的方法。
3万+

被折叠的 条评论
为什么被折叠?



