SQL Server 中Select into復(fù)制數(shù)據(jù)到新表
在SQL Server中使用 select into 可以創(chuàng)建一張新表的同時(shí)將原有表數(shù)據(jù)追加到新表中,現(xiàn)在創(chuàng)建一張測(cè)試表,里面存放各城市大學(xué)名稱:
- 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
 - )
 
為測(cè)試表創(chuàng)建以cityid為索引列的非聚集索引:
- create nonclustered index [index_school_cityid] on [dbo].[school] ([cityid] asc)
 
追加數(shù)據(jù)后,查看該表的數(shù)據(jù):
- select * from school
 
現(xiàn)在使用 select into 復(fù)制一張新表school_test:
- select * into school_test from school
 
查看新表school_test的數(shù)據(jù),和原有表schoo相同:
- select * from school_test
 
再來(lái)看看新表的結(jié)構(gòu),發(fā)現(xiàn)id的自增屬性被復(fù)制了:
而其他的屬性,如原表的主鍵和索引卻沒有被復(fù)制到新表:
說(shuō)明使用select into 可以復(fù)制原表的數(shù)據(jù)、字段和自增屬性,而主鍵和索引等卻無(wú)法被復(fù)制。


















 
 
 
 
 
 
 