---
title: "What is the differences between local and global temporary tables in sql server?"  
description: "What is the differences between local and global temporary tables in sql server?"  
author: "Anupam Mishra"  
published: 2016-02-26  
updated: 2020-09-24  
canonical: https://www.mindstick.com/interview/22989/what-is-the-differences-between-local-and-global-temporary-tables-in-sql-server  
category: "mssql server"  
tags: ["database", "sql", "sql server 2008", "sql server 2012", "database design", "database table"]  
reading_time: 2 minutes  

---

# What is the differences between local and global temporary tables in sql server?

**Global Temp Variable:**Global temp tables name starts with double hash (##) in sql server. Once this table is created in database, it is like a permanent table in tempdb->temporary tables. It is always ready for all users and not deleted until the total connection is withdrawn.\
\

```
CREATE TABLE ##StudentTemp (  Username varchar(50),  User_address varchar(150)) 
```

**Local Temp Variable:**\
Local temp tables are only available at current connection time in sql server database. It is automatically deleted when user disconnects from instances. It is started with hash (#) sign.\
\

```
CREATE TABLE #localTemp (  Username varchar(50),  User_address varchar(150)) 
```

## Answers

### Answer by Anupam Mishra

**Global Temp Variable:**Global temp tables name starts with double hash (##) in sql server. Once this table is created in database, it is like a permanent table in tempdb->temporary tables. It is always ready for all users and not deleted until the total connection is withdrawn.\
\

```
CREATE TABLE ##StudentTemp (  Username varchar(50),  User_address varchar(150)) 
```

**Local Temp Variable:**\
Local temp tables are only available at current connection time in sql server database. It is automatically deleted when user disconnects from instances. It is started with hash (#) sign.\
\

```
CREATE TABLE #localTemp (  Username varchar(50),  User_address varchar(150)) 
```


---

Original Source: https://www.mindstick.com/interview/22989/what-is-the-differences-between-local-and-global-temporary-tables-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
