HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Does LocalDB support temporary tables?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablestemporarylocaldbdoessupport

Problem

Are SQL Server temporary tables (prefixed with #) supported in LocalDB instances?

Solution

I can't answer for all versions, but for SQL Server 2012 up until SQL Server 2017 I am certain that they are supported

LocalDB has the same programmability features as SQL Server Express.


SQL Server Express LocalDB, a lightweight version of Express that has
all of its programmability features, yet runs in user mode and has a
fast, zero-configuration installation and a short list of
prerequisites.

Source

And then, building on the previous point, for the SQL Server express 2012 T-SQL Syntax


Express supports the same T-SQL language elements you find in any
edition of SQL Server. Not only can you issue data manipulation
language queries against the database, but you can also run data
definition language statements to create such objects as views,
triggers, cursors and stored procedures

Source

Testing (SQL Server 2017)

USE testdb
GO
CREATE TABLE #temp (id int , value nvarchar(255));

INSERT INTO #temp( id ,value)
SELECT 5, 'bla';

SELECT * FROM #temp;


result

id  value
5   bla


The temporary table also works when changing the db's compatibility mode to 100 (2008).

Code Snippets

USE testdb
GO
CREATE TABLE #temp (id int , value nvarchar(255));

INSERT INTO #temp( id ,value)
SELECT 5, 'bla';

SELECT * FROM #temp;
id  value
5   bla

Context

StackExchange Database Administrators Q#226792, answer score: 10

Revisions (0)

No revisions yet.