Basic Logics · Real Scenario Logic's

Clone Temporary Table Structure to New Physical Table in SQL Server

Introduction

In this Article, we will see how to Clone Temporary Table Structure to New Physical Table in SQL Server.This is applicable for both Azure SQL db and on-premises.

Demo SQL Script

IF OBJECT_ID('TempDB..#TempTable') IS NOT NULL
	DROP TABLE #TempTable;

SELECT 1 AS ID,'Arul' AS Names
INTO 
#TempTable;

SELECT * FROM #TempTable;

METHOD 1 – Clone Temporary Table Structure to New Physical Table

SQL Script-

SELECT * INTO TempTable1 FROM #TempTable WHERE 1=0;

EXEC SP_HELP TempTable1;

Image Pic-

METHOD 2 – Clone Temporary Table Structure to New Physical Table

SQL Script-

SELECT TOP 0 * INTO TempTable1 FROM #TempTable;

EXEC SP_HELP TempTable1;

Image Pic-

Conclusion

Thus, we saw some of the many methods to Clone our Temporary Table Structure to New Physical Table in SQL Server.

Thanks for reading!

FOLLOW BLOG for Interesting Upcoming Posts!

Advertisement

One thought on “Clone Temporary Table Structure to New Physical Table in SQL Server

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s