Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report