---
title: "What is the difference between a local and a global variable?"  
description: "What is the difference between a local and a global variable?"  
author: "Sumit Kesarwani"  
published: 2013-12-23  
updated: 2020-09-24  
canonical: https://www.mindstick.com/interview/1856/what-is-the-difference-between-a-local-and-a-global-variable  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# What is the difference between a local and a global variable?

A Local temporary table exists only for the duration of a connection or, if defined inside a compound statement, for the duration of the compound statement.

A Global temporary table remains in the database permanently, but the rows exist only within a given connection. When connection is closed, the data in the global temporary table disappears. However, the table definition remains with the database for access when database is opened next time.

## Answers

### Answer by Sumit Kesarwani

A Local temporary table exists only for the duration of a connection or, if defined inside a compound statement, for the duration of the compound statement.

A Global temporary table remains in the database permanently, but the rows exist only within a given connection. When connection is closed, the data in the global temporary table disappears. However, the table definition remains with the database for access when database is opened next time.


---

Original Source: https://www.mindstick.com/interview/1856/what-is-the-difference-between-a-local-and-a-global-variable

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
