Skip to main content

Posts

Showing posts with the label SQL temp table vs table variable

SQL temp table vs table variable

There are some differences between “ Temporary Tables ” (#tempTable) and “ Table Variables ” (@tempTable). Point 1: A Temp table (#tmp) can do all the DDL operations and it allows creating the indexes, altering and dropping. A Table variable (@tmp) is not allowed doing the DDL operations but can create the clustered index only. Point 2: A Temp table (#tmp) is easy to create and back up your data. A Variable table (@tmp) is easy to create but involves the extra effort for create the normal tables and then back up your data. Point 3: A Temp table (#tmp) result can be used by multiple users. A Variable table (@tmp) result can be used by the current user only. Point 4: A Temp table (#tmp) will be stored in the tempdb and create network traffic. If we have large amount of data in the temp table and it will create performance issue. A Table variable (@tmp) will be store in the physical memory for some of the data, and then later when the size increases it w...