--建立测试数据
create table table11(
xh int identity,
xm varchar(10),
kc varchar(10),
cj int
)
gocreate table newtable(
xh int identity(1000,1),
xm varchar(10),
kc varchar(10),
cj int,
kscs varchar null
)
go--插入数据
insert into table11 select '张三','物理',82
union all select '张三','化学',74
union all select '李四','英语',55
union all select '王五','物理',66
union all select '孙六','语文',72
union all select '孙六','化学',48insert into newtable select '何大','英语',82,null
union select '李小','化学',74,null--插入语句,得到newtable新的记录
insert newtable(xm,kc,cj)
select table11.xm,table11.kc,table11.cj from table11
create table table11(
xh int identity,
xm varchar(10),
kc varchar(10),
cj int
)
gocreate table newtable(
xh int identity(1000,1),
xm varchar(10),
kc varchar(10),
cj int,
kscs varchar null
)
go--插入数据
insert into table11 select '张三','物理',82
union all select '张三','化学',74
union all select '李四','英语',55
union all select '王五','物理',66
union all select '孙六','语文',72
union all select '孙六','化学',48insert into newtable select '何大','英语',82,null
union select '李小','化学',74,null--插入语句,得到newtable新的记录
insert newtable(xm,kc,cj)
select table11.xm,table11.kc,table11.cj from table11
--建立测试数据
create table table11(
xh int identity,
xm varchar(10),
kc varchar(10),
cj int
)
gocreate table newtable(
xh int identity(1,1),
xm varchar(10),
kc varchar(10),
cj int,
kscs varchar null
)
go--插入数据
insert into table11 select '张三','物理',82
union all select '张三','化学',74
union all select '李四','英语',55
union all select '王五','物理',66
union all select '孙六','语文',72
union all select '孙六','化学',48insert into newtable select '何大','英语',82,null
union select '李小','化学',74,null
--插入语句,得到newtable新的记录
set identity_insert newtable on
insert newtable(xh,xm,kc,cj)
select xh+1000,xm,kc,cj from table11
而且你学号没有规律,但是它总代表一定的含义把,也就是你可以把它直接复制到新表就可以;
set identity_insert newtable on
insert newtable(xh,xm,kc,cj)
select xh,xm,kc,cj from table11