SQLServer中如何使用Selectinto復(fù)制數(shù)據(jù)到新表

小編給大家分享一下SQL Server中如何使用Select into復(fù)制數(shù)據(jù)到新表,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

網(wǎng)站制作、成都網(wǎng)站設(shè)計的關(guān)注點不是能為您做些什么網(wǎng)站,而是怎么做網(wǎng)站,有沒有做好網(wǎng)站,給創(chuàng)新互聯(lián)建站一個展示的機會來證明自己,這并不會花費您太多時間,或許會給您帶來新的靈感和驚喜。面向用戶友好,注重用戶體驗,一切以用戶為中心。

在SQL Server中使用 select into 可以創(chuàng)建一張新表的同時將原有表數(shù)據(jù)追加到新表中,現(xiàn)在創(chuàng)建一張測試表,里面存放各城市大學(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  )

為測試表創(chuàng)建以cityid為索引列的非聚集索引:

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

追加數(shù)據(jù)后,查看該表的數(shù)據(jù):

select * from school

 SQL Server中如何使用Select into復(fù)制數(shù)據(jù)到新表

現(xiàn)在使用 select into 復(fù)制一張新表school_test:

select * into school_test from school

查看新表school_test的數(shù)據(jù),和原有表schoo相同:

select * from school_test

再來看看新表的結(jié)構(gòu),發(fā)現(xiàn)id的自增屬性被復(fù)制了:

SQL Server中如何使用Select into復(fù)制數(shù)據(jù)到新表

而其他的屬性,如原表的主鍵和索引卻沒有被復(fù)制到新表:

SQL Server中如何使用Select into復(fù)制數(shù)據(jù)到新表

說明使用select into 可以復(fù)制原表的數(shù)據(jù)、字段和自增屬性,而主鍵和索引等卻無法被復(fù)制。

以上是“SQL Server中如何使用Select into復(fù)制數(shù)據(jù)到新表”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)頁標(biāo)題:SQLServer中如何使用Selectinto復(fù)制數(shù)據(jù)到新表
新聞來源:http://muchs.cn/article8/gpgjop.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、網(wǎng)站設(shè)計微信公眾號、外貿(mào)網(wǎng)站建設(shè)做網(wǎng)站、ChatGPT

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

手機網(wǎng)站建設(shè)