Temporary Tables in Azure Data Studio

Temporary tables  are stored in the tempDB database. When you create a temporary table, Azure Data Studio Sever adds some additional characters on its name in order to provide a unique system name for it and then it stores it in tempDB in the sysobjects table. Temporary Table Works When Session Running. It Automatically Delete When Session Stops.

Syntax:- 
-- Drop a temporary table called '#TableName'
-- Drop the table if it already exists
IF OBJECT_ID('tempDB..#TableName', 'U') IS NOT NULL
DROP TABLE #TableName
GO
-- Create the temporary table from a physical table called 'TableName' in schema 'dbo' in database 'DatabaseName'
SELECT *
INTO #TableName
FROM [DatabaseName].[dbo].[TableName]
WHERE /* add search conditions here */

Example : –

-- Drop a temporary table called '#tblSchool'
-- Drop the table if it already exists , Table Name tblSchool
IF OBJECT_ID('tempDB..#tblSchool', 'U') IS NOT NULL
DROP TABLE #tblSchool
GO
-- Create the temporary table from a physical table called 'TableName' in schema 'dbo' in database 'DatabaseName'
SELECT *
INTO #tblSchool
FROM [DatabaseName].[dbo].[TableName]
WHERE /* add search conditions here */

Happy Coding…Comment If Any Doubt.

Post Author: adama