What are the main differences between #temp tables and @table variables and which one is preferred?



What are the main differences between #temp tables and @table variables and which one is preferred?..

Answer / Avni Gupta

{"differences":["Temp tables are created using the # symbol before the table name and persist until they are dropped explicitly or the session ends, while table variables are created using the @ symbol and exist only for the scope of the batch or stored procedure in which they were defined.", "Temp tables can be indexed, sorted and joined with other tables, while table variables cannot have indexes or constraints.", "Data in temp tables is stored in a disk space, whereas data in table variables resides in memory.", "Table variables are faster than temp tables as they reside in the memory, but their size is limited to 784MB by default. Temp tables can handle larger amounts of data but are slower due to disk I/O operations."],"preference":"The preference between temp tables and table variables depends on the specific scenario. If you need a temporary table with indexes or joins, use a temp table. If performance is critical and you're working with small sets of data, use a table variable."}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SQL Server Interview Questions

How to get nth highest salary from employee table.

1 Answers  


What is constraints and its types?

1 Answers  


Tell me what is sql profiler?

1 Answers  


What is reference section?

1 Answers  


What are sql dirty pages?

1 Answers  


What kind of problems occurs if we do not implement proper locking strategy?

0 Answers  


Simple example for difference between select and cursor in sql

1 Answers  


What is the maximum size of a dimension? : sql server analysis services, ssas

1 Answers  


Is mysql better than sql server?

1 Answers  


explain the difference between oracle- sql and sql server sql ? if both are same y we r using 2 sw.s?

1 Answers   ADP, iSoft,


If a table does not have a unique index, can a cursor be opened on it?

1 Answers  


What is a rownum?

1 Answers  


Categories