declare @Customer table
(
CustomerID int identity(1,1),
CustomerName varchar(100),
CompanyName varchar(100),
Address varchar(250)
)
You can notice the syntax to define a table variable is similar to the syntax to normal table definition. declare keyword is used in place of create keyword. And table name is prefixed with '@' as all tsql variables do.
- Table variables are stored in memory rather than in database.
- Querying table variables is very fast as there are no disk reads needed.
- The scope the table variables is same as other tsql variables. i.e, within statements batch or sproc
- Table variables cannot be dropped as they are automatically disappeared when they reach out scope
- As explained above all the data in table variables is stored in server's memory. So if there is huge data then it is not recommended to use table variables to avoid memory overhead.
- If the number of records is more than 100 then it is recommended to use temporary tables. To learn more about temporary tables please readi this blog post http://cherupally.blogspot.com/2009/05/how-to-create-temporary-table-in-sql.html
3 comments:
Table variables are not stored exclusively in memory.
http://technet.microsoft.com/en-us/library/cc966545.aspx
updated with this comment
Thanks...
Post a Comment