Created
July 25, 2012 03:13
-
-
Save sinairv/3174161 to your computer and use it in GitHub Desktop.
Table Variables vs Temp Tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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