Backup or copy table with SQL

To backup/copy a table, in this case a table called “MyTable” in SQL you can do this:

SELECT * INTO [dbo].[MyTable_20110506] FROM [dbo].[MyTable]

If you just want an empty table, but with the same headings and data types then do this:

SELECT * INTO [dbo].[MyTable_20110506] FROM [dbo].[MyTable] WHERE 1 = -1

Note the name of the new table, this is so when the tables are sorted by name, then they will be listed in order of creation and associated with the corresponding table.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.