| |

VerySource

 Forgot password?
 Register
Search
View: 1077|Reply: 5

Super simple question for database novices

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-23 10:30:01
| Show all posts |Read mode
Statements in stored procedures:
declare @t table
(
fid int,
child_id int
)
The table is defined. Do I need to delete it after using it? How can I delete it?
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-5-5 00:45:01
| Show all posts
Do not delete, it is a table variable
Reply

Use magic Report

0

Threads

114

Posts

69.00

Credits

Newbie

Rank: 1

Credits
69.00

 China

Post time: 2020-5-5 09:30:01
| Show all posts
NO delete ~~ Auto over
Reply

Use magic Report

0

Threads

211

Posts

108.00

Credits

Newbie

Rank: 1

Credits
108.00

 China

Post time: 2020-5-5 09:45:02
| Show all posts
Outside the scope of action, the table variable no longer exists
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-5-5 12:15:02
| Show all posts
This is a table variable is not saved
Same meaning as variable
Reply

Use magic Report

2

Threads

18

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-5-5 13:45:01
| Show all posts
Use table variables instead of temporary tables whenever possible. The table variable has the following advantages:

Table variables behave like local variables, with well-defined scope. The scope is the function, stored procedure, or batch that declares the variable.
Within its scope, table variables can be used like regular tables. This variable can be used in SELECT, INSERT, UPDATE, and DELETE statements where a table or table expression is used. However, table cannot be used in the following statements:

INSERT INTO table_variable EXEC stored procedure.

SELECT select_list INTO table_variable statement.

At the end of the function, stored procedure, or batch that defines the table variable, the table variable is automatically cleared.

The use of table variables in stored procedures reduces the amount of recompilation of stored procedures compared to the use of temporary tables.


Transactions involving table variables only exist during table variable updates. This reduces the need for table variables to lock and record resources.
Assignment operations between table variables are not supported. In addition, because table variables have limited scope and are not part of a persistent database, they are not affected by transaction rollbacks.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list