How to copy table structures and data using SQL statements

Source: Internet
Author: User

Use SELECT... in SQL SERVER... INTO statement

The following types can be used:

1. Full table backup: for example, SELECT * INOT t1 FROM titles

2. Back up some columns of the table (write the column list without writing *) or some rows (with the WHERE condition)

Example: SELECT title_id, title, price INTO t2 FROM titles-partial Columns

SELECT * INTO t2 FROM titles WHREE price> 10-partial rows

SELECT title_id, title, price INTO t2 FROM titles WHREE price> 10-partial rows and partial Columns

3. Only copy the table structure: for example, SELECT * INOT t1 FROM titles WHERE 1 = 2

4. the query result is from multiple tables, for example:

SELECT title_id, title, pub_name INTO t3

FROM titles t inner join publishers p

ON t. pub_id = p. pub_id

5. select * into: name of the database to be copied. DBO. Table name from original database name. DBO. Table Name

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.