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.
CREATE TABLE #myTempData ( PersonalDetailId int, FullName varchar(50) ) INSERT INTO #myTempData 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: 6189 | Post Order: 111