Best way to create a temp table with same columns and type as a permanent table 1

Best way to create a temp table with same columns and type as a permanent table

select top 0 *
into #mytemptable
from myrealtable

Here is what the above code is Doing:
1. Create a temporary table with the same structure as the real table.
2. Insert the data from the real table into the temporary table.
3. Delete the data from the real table.
4. Insert the data from the temporary table into the real table.
5. Drop the temporary table.

Similar Posts