简体   繁体   中英

SQL Server slow in simple insert statement

Anyone have came across this problem? A simple insert statement took 7 seconds, and this table contain 300 row of records. There no trigger on this table.

Table:

CREATE TABLE [dbo].[Table]
(
    [intMsgIn] [int] IDENTITY(1,1) NOT NULL,
    [charType] [char](4) NOT NULL,
    [dtTrx] [datetime] NOT NULL,
    [varMsg] [varchar](4000) NULL,

    CONSTRAINT [PK_Tbl] PRIMARY KEY CLUSTERED ([intMsgIn] ASC)
        WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, 
              IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, 
              ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

SQL statement:

INSERT INTO Table (charType, dtTrx, varMsg)  
VALUES(@charType, getdate(), @varMsg)  

SELECT @@IDENTITY  

This SQL statement was code in the store procedure and then is call by C# application.

Any possible reason that cause this slow?

Just a simple hint. Try it again and take a look at sp_who2 N'ACTIVE' . It should show you all active running queries. You'll have a column called BlkBy .

As your query is pretty simple, I'm sure there should be any kind of lock. The column BlkBy will give you the SPID of the task which is blocking your's. In this case you can recheck if there are concurrent INSERT , UPDATE or DELETE -Statements which generate another lock.

If this would be to fast to test with sp_who2 , you can also setup a trace and check the results if there is any lock during your INSERT .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM