Notes for copying between databases in SqlServer programs

Source: Internet
Author: User
Step: 1. back up the source database and restore the backup file to the target database on the other server. 2. export all the foreign keys in the source database and views (starting with dta_mv _) generated by the optimization consultant as before. SQL statement. SQL; 3. run before on the target database. SQL; 4. perform the copy operation. 5.

Step: 1. back up the source database and restore the backup file to the target database on the other server. 2. export all the foreign keys in the source database and views (starting with 'dta_mv _ ') generated by the optimization consultant as before. SQL statement. SQL; 3. run before on the target database. SQL; 4. perform the copy operation. 5.

Steps:

1. First back up the source database, and restore the backup file to the target database on another machine;

2. export all the foreign keys in the source database and views (starting with 'dta _ mv _ ') generated by the optimization consultant as before. SQL statement. SQL;

3. Execute before. SQL on the target database;

4. Perform the copy operation;

5. Execute after. SQL on the target database;


Note:

1. All Tables in the two databases must have the same structure, and even the column sequence cannot be changed. Otherwise, SqlBulkCopy does not recognize it!

2. SqlBulkCopy should be created as follows: SqlBulkCopy bulkCopy = new SqlBulkCopy (outerConn, SqlBulkCopyOptions. KeepIdentity | SqlBulkCopyOptions. KeepNulls, null). AddTimeout ();

If you do not press this button, the ID column cannot be inserted as the original one. For more information, see sqlbulkcopy batch insert data.

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.