SQL Server 中Select into复制数据到新表

 在SQL Server中使用 select into 可以创建一张新表的复制同时将原有表数据追加到新表中,现在创建一张测试表,里面存放各城市大学名称:

create table [dbo].[school]( [id] [bigint] identity(1,数据1) not null, [name] [varchar](50) not null, [cityid] [bigint] not null, constraint [school_primary] primary key clustered  [id] asc  ) 

 为测试表创建以cityid为索引列的非聚集索引:

create nonclustered index [index_school_cityid] on [dbo].[school] ([cityid] asc)

追加数据后,查看该表的到新数据:

select * from school 

 

现在使用 select into 复制一张新表school_test:

select * into school_test from school 

查看新表school_test的数据,源码下载和原有表schoo相同:

select * from school_test 

再来看看新表的复制结构,发现id的数据自增属性被复制了:

而其他的属性,如原表的亿华云到新主键和索引却没有被复制到新表:

说明使用select into 可以复制原表的数据、字段和自增属性,复制而主键和索引等却无法被复制。数据

到新
IT科技
上一篇:Graphcore携手百度飞桨 共建全球软硬AI生态
下一篇:让AI走进初创企业,NVIDIA Inception赋能科技创新