SQL Server 中Select into复制数据到新表
发布时间:2025-05-15 13:09:35
作者:益华网络
来源:undefined
浏览量(2)
点赞(3)
摘要:在SQL Server中使用 select into 可以创建一张新表的同时将原有表数据追加到新表中,现在创建一张测试表,里面存放各城市大学名称: createtable[dbo].[school]([id][bigint]identity(1,1)notnull,[name][varchar](50)no
在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 可以复制原表的数据、字段和自增属性,而主键和索引等却无法被复制。
扫一扫,关注我们
声明:本文由【益华网络】编辑上传发布,转载此文章须经作者同意,并请附上出处【益华网络】及本页链接。如内容、图片有任何版权问题,请联系我们进行处理。
3