Discussion on concurrency test method of SQL Server database

Source: Internet
Author: User
Tags sql server query

1. The use of testing tools to simulate multiple end users concurrent testing;

The disadvantage of this test approach is that end users are often not directly connected to the database, but rather pass through one or more intermediary services, so it is not guaranteed to access the database or concurrency. Second, this test method needs to wait until the client program, the server-side program is complete to do;

2. Using test tools to write scripts, directly connected to the database for concurrent testing;

This method can guarantee the concurrent operation effectively, and can be tested by the database access program, and the test time is shortened greatly, and the test result is better.

The following is a demo program that uses robot to use the second test method for concurrent testing of the database.

First step: Create a demo program

Open SQL Server Query Analyzer and execute the following script in the SQL Server test database (script execution: CREATE table testtable and insert a record; Create stored procedure test):

if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Test] ') and OBJECTPROPERTY (ID, N ' isprocedure ') = 1)
drop procedure [dbo]. [Test]

Go

if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ TestTable] and OBJECTPROPERTY (ID, N ' isusertable ') = 1)

drop table [dbo]. [TestTable]

Go

CREATE TABLE [dbo]. [TestTable] (

[TestID] [INT] Null

[Counts] [INT] Null

) on [PRIMARY]

Go

Insert into TestTable (testid,counts) VALUES (1,0)

Go

SET QUOTED_IDENTIFIER ON

Go

SET ANSI_NULLS on

Go

CREATE Procedure dbo. Test

As

DECLARE @count int

BEGIN Tran TEST

Select @count =countsfrom testtable where testid=1

Update TestTable setcounts= @count +1

if (@ @error >0) begin

Rollback Tran TEST

End ELSE begin

Commit Tran TEST

End

Go

SET QUOTED_IDENTIFIER OFF

Go

SET ANSI_NULLS on

Go

Related Article

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.