Monday, 17 August 2015

Create Table from an existing table in SQL


SELECT * INTO dbo.newtable FROM dbo.oldtable WHERE 1 = 0;

Note that this creates the same column structure (including an IDENTITY column if one exists)
but it does not copy any indexes, constraints, triggers, etc.

If you want to make a copy of the table including all of the data, then leave out the WHERE clause.

SELECT * INTO dbo.newtable FROM dbo.oldtable