Do I need to discard table variables declared in stored procedures?

In a stored procedure if I

DECLARE @tmpClientTable TABLE

Should I give it up again? Or it will just be overwritten the next time the procedure starts are saved.

What happens if someone else starts the stored process too ... will it be a separate table?

+5
source share
4 answers

You don't need (and really can't) explicitly drop it.

Creating and deleting table variables is handled automatically for you.

, . .

.

+4

. / .

, PROC eachother.

+2

:

DECLARE @Table TABLE( 
name varchar(30) NOT NULL, 
location varchar(30) NOT NULL 
);

INSERT INTO @Table VALUES( 'John', 'Neveda')

SELECT * FROM @Table
go     

:

DECLARE @Table TABLE( 
name varchar(30) NOT NULL, 
location varchar(30) NOT NULL ,
locationB varchar(30) NOT NULL 
);

INSERT INTO @Table VALUES( 'John', 'Neveda', 'LasVegas')

SELECT * FROM @Table

, Temp . LocalTempTables Vs GlobalTempTables

+2

( ) #TEMP.

IF OBJECT_ID('tempdb..#TempCustomer') IS NOT NULL
begin
        drop table #TempCustomer
end


CREATE TABLE #TempCustomer
( 
  [CustomerID] nchar(5)
, [CompanyName] nvarchar(40)
)


IF OBJECT_ID('tempdb..#TempCustomer') IS NOT NULL
begin
        drop table #TempCustomer
end

@variable.

0
source

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


All Articles