Top 10 SQL Server Temporary Table Related Interview Questions Answers

1). What are the 2 types of Temporary Tables in SQL Server?  1. Local Temporary Tables 2. Global Temporary Tables 2 ).  What is the dif...

1). What are the 2 types of Temporary Tables in SQL Server? 
1. Local Temporary Tables
2. Global Temporary Tables

2). What is the difference between Local and Global Temporary Tables? 

  • Local Temporary Tables:

  1. Prefixed with a single pound sign (#). 
  2. Local temporary tables are visible to that session of SQL Server which has created it/Exists only for duration of the connection/compound statement. 
  3. Local temporary tables are automatically dropped, when the session that created the temporary tables is closed.

  •  Global Temporary Tables:

  1. Prefixed with two pound signs (##). 
  2. Global temporary tables are visible to any user and any connection after being created. 
  3. Global temporary tables are also automatically dropped, when the session that created the temporary tables is closed.
4). In which database, the temporary tables get created? 
TEMPDB database.

5). How can I check for the existence of a temporary table? 
IF object_id('tempdb..##TEMPTABLE') IS NOT NULL

6). Table Variables vs. Temp Tables? 
  • Table var doesn't have to be memory-resident. Its pages can be moved to tempdb if memory is low
  • Rollback doesn't affect table vars
  • Table vars don't participate in transactions or locking
  • Any DML operations done on table variables are not logged
  • No statistics are maintained on table variables

7). Can you create foreign key constraints on temporary tables? 
No

8). Do you have to manually delete temporary tables? 
No, temporary tables are automatically dropped, when the session that created the temporary tables is closed. But if you maintain a persistent connection or if connection pooling is enabled, then it is better to explicitly drop the temporary tables you have created.
However, It is generally considered a good coding practice to explicitly drop every temporary table you create.

Related

TEMP TABLE INTERVIEW QUESTIONS 3625194300475374208

Post a comment

  1. Wow! I’m from Malaysia, an English teacher gonna be. Now, I know that my goal readers are my students in the past. custom essay writing online I’d like to mark like this too attractive event and real hard work to make an enormous article. Thank you for the suggestions, I really enjoyed reading this. It is so much inspiring.

    ReplyDelete

emo-but-icon

Follow Us

Recent

Comments

Donate

Side Ads

Text Widget

Connect Us

Sql Server 2017 Interview Questions
Sql Server Basic Interview Query Set-1
Sql Server Basic Interview Query Set-2
Sql Server Date-Time Interview Query SET-3
Sql Server Salary Interview Query SET-4
Sql Server Group By Interview Query SET-5
Sql Server Join Interview Query SET-6
Sql Server Tricky Join Interview Query SET-7
Sql Server DDL Interview Query SET-8
Small but very Tricky Sql Server Query SET-9
Very Much Tricky Query (not 4 fresher)SET-10
Sql Server Complex Interview Query SET-11
Sql Server Datatype Interview Questions
Sql Server View Interview Questions
Sql Server Index Interview Questions
TCS Tricky Sql Interview Queries
HCL Sql Interview Queries
Sql Server SP Interview Questions
Sql Server Trigger Interview Questions
Sql Server Temp Table Interview Questions
Sql Server 2016 Interview Questions
Sql Server Performance Tuning Interview Q.
Sql Server Constraints Interview Questions
Sql Server Storage/Size Interview Questions
Sql Server Very Basic Interview Questions
Sql Server Quiz for Fresher
Sql Server Icon Quiz for All
Sql Server 300+ Theoretical Interview Questions
Sql Server Complete Set

ASP.NET AND JQUERY INTERVIEW QUESTION
ASP.NET: Web Config Interview Question
ASP.NET: View State Interview Question
ASP.NET: Session Interview Question
ASP.NET: Session Interview Question 
ASP.NET: Security Interview Question
ASP.NET: Catching Interview Question
C# OOPS Interview Question
MORE Interview Question
JQUERY: Interview Question Set-1
JQUERY: Interview Question Set-2
JAVA-SCRIPT: Interview Question Set-1
JAVA-SCRIPT: Interview Question Set-2
ASP.NET MVC: Interview Question Set-1

POPULAR POSTS
10 MOST DIFFICULT INTERVIEW QUESTIONS
5 BEST INTERVIEW TIPS
YOUR 10 MISTAKE DURING INTERVIEW
2016 TOP 20 GROUP DISCUSSION TOPICS
HOW SQL PERFORMANCE AFFECTED BY DATATYPE
item