Skip to main content

SQL Server query to copy all data and schema to a new table.

-- Delete the old table if already exists:
if exists (select * from sys.objects where object_id = OBJECT_ID(N'[dbo].[new_table_name]') and type in (N'U') )
    begin
        drop table dbo.new_table_name
    end;
go

-- Copy schema and data from "old_table_name" to "new_table_name"
select * into new_table_name from dbo.old_table_name;
go