Skip to content

Instantly share code, notes, and snippets.

@Cyberloki
Created September 22, 2013 21:53
Show Gist options
  • Select an option

  • Save Cyberloki/6664244 to your computer and use it in GitHub Desktop.

Select an option

Save Cyberloki/6664244 to your computer and use it in GitHub Desktop.
Create a new table dynamically and insert records (Select Into) Copy records into existing table (Insert Into)
-- create a new table and insert records
-- =====================================
select * into newtablename from MyFirstTable
-- copy records into existing table
-- =====================================
insert into ReprocessTable(event_time, [msg]) select event_time, [msg] from FailedTable order by [id]
-- create a new table with records from another database
-- =====================================
use MyDB
GO
select * into newtablename from MyOtherDB..MyFirstTable
GO
-- copy records from another database into existing table
-- =====================================
use MyDB
GO
insert into MyTable(event_time, [msg]) select t.event_time, t.[msg] from MyOtherDB..TheirTable t order by t.[id]
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment