Skip to main content

Posts

Showing posts from April, 2009

SQL data storing options

In SQL we have four different ways to "store" data in a table: local temporary tables (#table_name), global temporary tables (##table_name), permanent tables (table_name), table variables (@table_name).   Local Temporary Tables CREATE TABLE #people ( id INT, name VARCHAR(25) )   A temporary table is created and populated on disk, in the system database tempdb — with a session-specific identifier packed onto the name, to differentiate between similarly-named #temp tables created from other sessions. The data in this #temp table (in fact, the table itself) is visible only to the current scope (usually a stored procedure, or a set of nested stored procedures). The table gets cleared up automatically when the current procedure goes out of scope, but you should manually clean up the data when you're done with it:   DROP TABLE #people   This will be better on resources ("release early") than if you let the system clean up *after* the current session finishes the r