Get the App
SLTechnology News&Howtos  ›  Database  › 

How to copy data to a new table using Select into in SQL Server

Shulou Source: shulou.com Published: 2022-05-31 21:36:38 09月10日 Update

Editor to share with you how to use Select into to copy data to the new table in SQL Server, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.

Using select into in SQL Server, you can create a new table and append the old table data to the new table. Now create a test table in which the names of city universities are stored:

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

Create a nonclustered index with cityid as the index column for the test table:

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

After you append the data, view the data of the table:

Select * from school

Now use select into to copy a new table school_test:

Select * into school_test from school

View the data of the new table school_test, which is the same as the original table schoo:

Select * from school_test

Looking at the structure of the new table, it is found that the self-incrementing attribute of id has been copied:

Other attributes, such as the primary key and index of the original table, are not copied to the new table:

It shows that the data, fields and self-increment properties of the original table can be copied by using select into, but the primary key and index cannot be copied.

These are all the contents of the article "how to copy data to a new table using Select into in SQL Server". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Data index attribute article content Zhang Xin Jianyi test same not much at the same time name city university most fields more knowledge structure industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Information MySQL Redmi Apple