Why writing through a linked server can be slow

Source: Internet
Author: User

Why write through the linked server, the speed is very slow because when the link server is written, line-by-row write to the database, row by line INSERT, trigger trigger, and so on, write a few lines of data, triggered several triggers, inserted,deleted and other system tables each time only one row of data If the same server is plugged in, a SQL command is bulk inserted, triggering only one trigger, and inserted,deleted will have multiple rows of data test cases: Build tables: CREATE TABLE [dbo]. [Test_batinsert] ([Plucode] [varchar] () NULL, [Scancode] [varchar] (+) NULL) On [PRIMARY] build trigger:CREATE TRIGGER [dbo].Test_batinsert_insert on [dbo]. [Test_batinsert] for INSERT asBEGIN                IF UPDATE (Plucode)                BEGINIF (Select Len( LTrim(RTrim (Plucode))) from inserted ) > 2--This writing when the isnerted only one row of data, you can execute through, there are multiple rows of data, the syntax is incorrect, will error                BEGIN                               IF IsNumeric ((Select LTrim(RTrim (Plucode)) from inserted )) = 1                               BEGIN                                              SELECT 1                               END                END                ENDENDTest Statement Statement 1INSERT Test_batinsert( Plucode,Scancode )SELECT TOP 1 Plucode,Scancode fromTest_batinsert_1 test results, no problem, the inserted statement in the trigger has only one row of data statement 2INSERT Test_batinsert( Plucode,Scancode )SELECT TOP 2 Plucode,Scancode fromTest_batinsert_1 test Result: not normal. Description The inserted statement in the trigger has more than one row of data to execute on another server: statement 1INSERT [Lnkser]. LNKDB.dbo .Test_batinsert( Plucode,Scancode )SELECT TOP 1 Productno,Productno from [test_batinsert_1]Test results, no problem, the inserted statement in the trigger has only one row of data statement 2INSERT[Lnkser]. Lnkdb.dbo .Test_batinsert( Plucode,Scancode )SELECT TOP 2 Productno,Productno fromTest_batinsert_1 test results, no problem, the inserted statement in the trigger has only one row of data conclusion: If you want to exchange data across servers, try to use a linked server for read operations, to avoid write and delete operations.

Why writing through a linked server can be slow

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.