当想要从主机数据库同步到多个服务器数据库时,我遇到了一个很大的性能问题。
详情: 主机(microsoft sql server)有7个表(microsoft sql server)和总计100万条记录。这些记录需要同步到300个服务器的数据库。它不是检查或比较的要求。所以我可以清除表的数据并从Host Server插入任何数据。但是性能速度很慢。
我的主机的数据库有30个表,所以在另外300个客户端的服务器数据库中。但我只需要将7个表从主机的数据库同步到其他数据库。
客户端的服务器是主机的链接服务器。他们在不同的地方和不同的服务器。
我找到了一些样品,但这并不是很有帮助。我还没有决定采用哪种方法。所以我对任何合适的方法持开放态度。你对我有什么想法和样品吗?万分感谢!
频率:可能是1周1次,但我的客户只在晚上10点到早上8点之间。
我的示例代码是:
set @scriptTruncate = N'
EXEC ['+@IPAddress+'].[POM].sys.sp_executesql N''
--ALTER TABLE [Module_Function] DROP CONSTRAINT [FK_Module_Function_Module1]
Delete from [dbo].[USER_STORE];
Delete from [dbo].[USER_ROLE_DEPT];
Delete from [dbo].[ROLE_FUNCTION];
Delete from [dbo].[ROLE_MODULE];
Delete from [dbo].[POMADUSER];
Delete from [dbo].[HHTUSER];
Delete from [dbo].[ROLE];
Delete from [dbo].[Store];
'';';
set @scriptTInsert1 = N'
Select Getdate(),''Start @Store'';
INSERT INTO ['+@IPAddress+'].[POM].[dbo].[Store]([STORE_Code],[STORE_LongDesc],[STORE_ShortDesc],[CURR_CODE],[IS_STORE],[CNTRY_CODE],[ADDR_1],[ADDR_2],[ADDR_3],[CITY],[STATE],[ZIP],[ISD],[AREA],[Phone_number],[ISD_FAX],[AREA_FAX],[FAX_NUMBER],[MANAGER_NAME],[TYPE_CODE],[AR_NUM],[PRC_BOOK_NUMBER],[FNC_CODE],[GL_CO],[CREATE_DATE],[Modified_On],[Deleted_On],[StockTakeDate],[IPAddress],[Check_SalesHistory],[Print_DeletedSKU],[Print_InactiveSKU],[Product_ShelfCapacity],[Org_Lvl_Child],[Fin_Banner],[Fin_Accd],[TradeStoreCode],[NonTradeStoreCode])
SELECT [STORE_Code],[STORE_LongDesc],[STORE_ShortDesc],[CURR_CODE],[IS_STORE],[CNTRY_CODE],[ADDR_1],[ADDR_2],[ADDR_3],[CITY],[STATE],[ZIP],[ISD],[AREA],[Phone_number],[ISD_FAX],[AREA_FAX],[FAX_NUMBER],[MANAGER_NAME],[TYPE_CODE],[AR_NUM],[PRC_BOOK_NUMBER],[FNC_CODE],[GL_CO],[CREATE_DATE],[Modified_On],[Deleted_On],[StockTakeDate],[IPAddress],[Check_SalesHistory],[Print_DeletedSKU],[Print_InactiveSKU],[Product_ShelfCapacity],[Org_Lvl_Child],[Fin_Banner],[Fin_Accd],[TradeStoreCode],[NonTradeStoreCode]
FROM [CAS].[dbo].[Store];'
set @scriptTInsert2 = N'
Select Getdate(),''Start @HHTUSER'';
INSERT INTO ['+@IPAddress+'].[POM].[dbo].[HHTUSER]
SELECT * FROM [CAS].[dbo].[HHTUSER];'
set @scriptTInsert3 = N'
Select Getdate(),''Start @ROLE'';
INSERT INTO ['+@IPAddress+'].[POM].[dbo].[ROLE]
SELECT * FROM [CAS].[dbo].[ROLE];'
set @scriptTInsert4 = N'
Select Getdate(),''Start @USER_STORE'';
INSERT INTO ['+@IPAddress+'].[POM].[dbo].[USER_STORE]
SELECT * FROM [CAS].[dbo].[USER_STORE];'
set @scriptTInsert5 = N'
Select Getdate(),''Start @POMADUSER'';
INSERT INTO ['+@IPAddress+'].[POM].[dbo].[POMADUSER]
SELECT * FROM [CAS].[dbo].[POMADUSER];'
set @scriptTInsert6 = N'
Select Getdate(),''Start @ROLE_MODULE'';
INSERT INTO ['+@IPAddress+'].[POM].[dbo].[ROLE_MODULE]
SELECT * FROM [CAS].[dbo].[ROLE_MODULE];'
set @scriptTInsert7 = N'
Select Getdate(),''Start @ROLE_FUNCTION'';
INSERT INTO ['+@IPAddress+'].[POM].[dbo].[ROLE_FUNCTION]
SELECT * FROM [CAS].[dbo].[ROLE_FUNCTION];'
set @scriptTInsert8 = N'
Select Getdate(),''Start @USER_ROLE_DEPT'';
INSERT INTO ['+@IPAddress+'].[POM].[dbo].[USER_ROLE_DEPT]
SELECT * FROM [CAS].[dbo].[USER_ROLE_DEPT];
--ALTER TABLE [dbo].[Module_Function] WITH CHECK ADD CONSTRAINT [FK_Module_Function_Module1] FOREIGN KEY([Module_Code])
--REFERENCES [dbo].[Module] ([Module_Code])
';
BEGIN TRY
Select Getdate(),'Start @scriptTruncate'
EXEC sp_executesql @scriptTruncate
Select Getdate(),'Start @scriptTInsert'
EXEC sp_executesql @scriptTInsert1
EXEC sp_executesql @scriptTInsert2
EXEC sp_executesql @scriptTInsert3
EXEC sp_executesql @scriptTInsert4
EXEC sp_executesql @scriptTInsert5
EXEC sp_executesql @scriptTInsert6
EXEC sp_executesql @scriptTInsert7
EXEC sp_executesql @scriptTInsert8