SQL Server > Working with XML

Temporary table / temp table in SQL Server

How to temporarily hold data into temporary table in SQL Server?

Temporary table is similar to table variable however, temporary table is not created in memory but it gets created physically in the database and it remains unless the current session ends or it is dropped explicitly.

       PersonalDetailId int,
       FullName varchar(50)
SELECT PersonalDetailsId, FirstName + ' ' + LastName
       FROM PersonalDetails WHERE Active = 0

SELECT * FROM #myTempData

-- DROP this temp table now
DROP table #myTempData

Temporary table name is prefixed with ‘#’ character.

In above case, we have create a table named “#myTempData’ with PersonalDetailId and FullName fields and inserting record from PersonalDetails table then selecting its records and when we are intended to not use this temp table any more, we have dropped it.

 Views: 9507 | Post Order: 111

Write for us

Hosting Recommendations