In the development process of SQL server database, sometimes the development library may need to synchronize the data of the formal library or the test library, so how does the SQL server synchronize the data? Synchronization, the script method is introduced here.
Make sure that the library you are using has established a link server to link to the corresponding official library, as shown in the figure
How to access the data in the official repository? The method uses [linked server name] + point + database name + point + dbo + point + table name
SELECT * FROM [10.21.2.25].budget.dbo.tb_item_bind_info
Then if you synchronize the official database data next, it is very simple as follows
TRUNCATE TABLE budget.dbo.tb_item_bind_info go INSERT INTO budget.dbo.tb_item_bind_info ( bind_id , item_id , mflag, remark , CREATION_DATE , CREATED_BY , LAST_UPDATED_BY , LAST_UPDATE_DATE ) SELECT bind_id , item_id , mflag, remark , CREATION_DATE , CREATED_BY , LAST_UPDATED_BY , LAST_UPDATE_DATE FROM [10.21.2.25].budget.dbo.tb_item_bind_info go
The regular table in the SQL server will set a self-growing column. If it is synchronized as above, the synchronization will also be self-growing. This column may be different from the online data. If necessary, it must be the same as the online data. You need to turn on set IDENTITY_INSERT table name ON and at the same time , you need to add the auto-increment column to the insert
example
TRUNCATE TABLE budget.dbo.tb_item_bind_info go set IDENTITY_INSERT budget.dbo.tb_item_bind_info ON go INSERT INTO budget.dbo.tb_item_bind_info ( id, bind_id , item_id , mflag, remark , CREATION_DATE , CREATED_BY , LAST_UPDATED_BY , LAST_UPDATE_DATE ) SELECT id,bind_id , item_id , mflag, remark , CREATION_DATE , CREATED_BY , LAST_UPDATED_BY , LAST_UPDATE_DATE FROM [10.21.2.25].budget.dbo.tb_item_bind_info go