2009/10/07

SQL- clone table instantly (SQL)

Sometimes we want to clone a table. How to do it quick? Look at the code below:

select t.* into [#temp]
from TABLENAME t
where 1 = 0

The above code will create a temp table [#temp] with the same properties of table TABLENAME. Some of you might get confused why there is a line "where 1 = 0" what is that means? Actually this means that we do not want to clone the data, we just want to clone the table. So in here 1 = 0 will always false and so there will be no data insert into the temp table.

Enjoy

No comments:

Post a Comment