Get the App
SLTechnology News&Howtos  ›  Database  › 

Can the same table structure of different databases in SQLServer database be imported into each other?

Shulou Source: shulou.com Published: 2022-05-31 11:32:47 09月28日 Update

Editor to share with you about the SQLServer database of different databases with the same table structure can be imported into each other, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Under the SQLServer database, create two different database names, and then create two tables with the same structure under the database (it is recommended to use SQL statements), such as:

Write the following statement under the soutest database:

CreatetableEmployee1 (EmployeeIDintprimarykey,EmployeeNamevarchar (20) notnull,EmployeeAgesmallintnotnull,EmployeeSexchar (2) default'', EmployeeCellPhoneintnotnull,EmployeeAddressnvarchar (50), EmployeeCommentsnvarchar (1000))

Then insert data into the table (note: if the identifier is set in the source table, add setidentity_inserton before the following statement, and finally add setidentity_insertoff):

Can the same table structure of different databases in SQLServer database be imported into each other?

InsertintoEmployee (EmployeeID,EmployeeName,EmployeeAge,EmployeeCellPhone,EmployeeAddress,EmployeeComments) values (123455) insertintoEmployee (EmployeeID,EmployeeName,EmployeeAge,EmployeeCellPhone,EmployeeAddress,EmployeeComments) values (123455) insertintoEmployee (EmployeeID,EmployeeName,EmployeeAge,EmployeeCellPhone,EmployeeAddress,EmployeeComments)

We execute the statement to create the table under test under another database, destest, when we create a table. Then execute the following statement under this database:

Insertdestest.dbo.Employee (EmployeeID,EmployeeName,EmployeeAge,EmployeeSex,EmployeeCellPhone,EmployeeAddress,EmployeeComments) selectEmployeeID,EmployeeName,EmployeeAge,EmployeeSex,EmployeeCellPhone,EmployeeAddress,EmployeeCommentsfromsoutest.dbo.Employee

At this point, all the work is over.

The above is all the contents of the article "can the same table structure of different databases in SQLServer database be imported into each other?" 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!

Tags: Data database statement different same structure article two content not much name most suggestion more identity identifier knowledge so far industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MySQL Linux Docker Xiaomi