Solved

backup just a table

Posted on 2015-01-14
4
55 Views
Last Modified: 2015-01-20
sql server 2012

a Developer wants to delete a table in our production database and then run a script to recreate it.
Is there a way to backup just a table in the database?
if not, recommendations on how to proceed with this?
0
Comment
Question by:jamesmetcalf74
  • 2
4 Comments
 
LVL 22

Assisted Solution

by:Steve Wales
Steve Wales earned 333 total points
ID: 40549701
Depending upon the size of the table, couldn't you just take a copy of it ?

select * into mytable_backup from mytable;

Now, you've got possible issues with updates that might occur while the data is being copied (if it's a highly volatile table) but at least you'll have your original ...
0
 

Author Comment

by:jamesmetcalf74
ID: 40549999
sorry I'm new to sql.

the two tables you referenced in your solution.

mytable_backup   is this a table you first create before you issue this command or is it created on the fly with the command.
0
 
LVL 22

Assisted Solution

by:Steve Wales
Steve Wales earned 333 total points
ID: 40550065
The syntax "select * into mytable_backup" will create a new table on the fly based upon the results of the query.

It fails if the table already exists.
0
 
LVL 46

Accepted Solution

by:
Vitor Montalvão earned 167 total points
ID: 40550808
In SQL Server you can't backup only an object. You backup the full database.
For backup tables you can create a copy of it as mentioned above or export the data to a file. If you are going to change the table structure you should script the table before making the changes.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql join/ assign small # first 10 83
SQL Server R2 Stored procedure performance 8 42
BULK LOGGED - log full 9 25
SQL Query 3 48
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now