SQL Server copies data from a table to another table

Source: Internet
Author: User

Insert into Phone2 (ph,attr,type,carrier) Select Top + ph,attr,type,carrier from phone

Copy the field of the table phone and the first 1000 data to the Phone2 table

A table in the database deletes duplicate data (the Phone2 table cannot exist)

SELECT DISTINCT * to Phone2 from phone

Table phone data is put into phone2 (phone2 table can exist)
Insert into Phone2 (ph,attr,type,carrier) SELECT DISTINCT (ph), attr,type,carrier Fromphone

Delete Phone table
TRUNCATE TABLE Phone

Table Phone2 data back into the phone table to ensure that the name of the table is the same
INSERT into Phone (ph,attr,type,carrier) Selectph,attr,type,carrier from Phone2

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.