How to copy a table from one database to a table in another database

Source: Internet
Author: User

In the first case, append the data from the a database. dbo.a table to the B database. DBO.B table (condition: B table is already created in the B database )
Inert into B database. dbo.b table
SELECT * from a database. dbo.a table [WHERE condition]

This T-SQL statement will have an exception if you use a column list and Identity_insert is on, you can specify an explicit value for the Identity column in table ' B database. dbo.b table '.

Cause: B database. A column in the DBO.B table is set to autogrow (typically the primary key ID).

Solution: Turn the * into a specified [column name] and remove the column that automatically grows.

Second case: Copy the data from the a database. dbo.a table to the B database. DBO.B table (condition: B table is not created in the B database or table with the same name )

SELECT * into B database. dbo.b table from a database. dbo.a table [WHERE condition]

After executing this statement, the B database will be created with a database. DBO.A table-like structure B. Table B created from this statement does not have a primary key.

How to copy a table from one database to a table in another database

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.