Are table variables threads safe for SQL Server 2008 r2?

For example, I will use the following table variable inside one of my stored procedures;

DECLARE @MyTempTable TABLE ( someField int, someFieldMore nvarchar(50) ) 

Is this variable thread safe? if at the same time there are several requests, what do you think will be a conflict?

+4
source share
2 answers

Yes.

A "safe thread" will be "secure in terms of security" or "secure for connection" in SQL Server. With security, a secure connection is also implied.

Table variables are similar to regular variables: local to this area. Each connection is isolated from each other, and each connection is a series of areas

The best example of this is the difference between

  • SCOPE_IDENTITY = security scope
  • @@ IDENTITY = secure connection, not security scope
  • IDENT_CURRENT = unsafe anyway

See: @@ IDENTITY vs SCOPE_IDENTITY () vs IDENT_CURRENT [sql server 2005]

+10
source

A table variable is local to the area in which it is created. Two simultaneous joins do not share a table variable.

+3
source

Source: https://habr.com/ru/post/1369120/


All Articles