Skip to content

Instantly share code, notes, and snippets.

@sinairv
Created July 25, 2012 03:13
Show Gist options
  • Save sinairv/3174161 to your computer and use it in GitHub Desktop.
Save sinairv/3174161 to your computer and use it in GitHub Desktop.
Table Variables vs Temp Tables
-- Naming:
-- #TableName : local temp table
-- ##TableName: global temp table
-- @TableName: table variable
-- TableName: permanent table
CREATE TABLE #Employees
(
Name varchar(30),
Age INT
)
INSERT INTO #Employees VALUES ('Sina', 29), ('Rhys', 28), ('Scott', 50)
SELECT * FROM #Employees
-- temp tables should be dropped in the end
DROP TABLE #Employees
GO
DECLARE @people TABLE
(
Name varchar(30),
Age INT
)
INSERT INTO @people VALUES ('Sina', 29), ('Rhys', 28), ('Scott', 50)
SELECT * FROM @people
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment