在SQLServer中使用selectinto创建新表,并将原表数据追加到新表中。现在创建一个测试表,其中存储城市大学的名称:createtable[dbo].[school]([id][bigint]identity(1,1)notnull,[name][varchar](50)notnull,[cityid][bigint]notnull,constraint[school_primary]primarykeyclustered[id]asc)为测试表创建以cityid为索引列的非聚集索引:createnonclusteredindex[index_school_cityid]on[dbo].[school]([cityid]asc)追加数据后,查看表的数据:select*fromschool现在使用selectinto复制一个新表school_test:select*intoschool_testfromschool查看新表school_test的数据,与原表school:select*fromschool_test我们看一下新表的结构,发现id的自增属性已经被复制了:而其他属性,比如原表的主键和索引没有复制到新表中:它表示可以使用s复制原表的数据、字段和自增属性electinto,但是不能复制主键和索引。
