Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Make a backup of a SQL Server table

Posted on 2013-12-02
5
Medium Priority
?
309 Views
Last Modified: 2013-12-02
I created a backup table named StockHistBak by copying the structure of StockHist.

How to I populate StockHistBak from the data in StockHist?

Thanks,
0
Comment
Question by:Dovberman
  • 3
5 Comments
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 1600 total points
ID: 39689570
If it's a one off, drop it and do this:

select * into StockHistBak from StockHist

If it's something you want do do regularly, create a maintenance task to drop and recreate it sing the above code.
0
 
LVL 25

Assisted Solution

by:Lee Savidge
Lee Savidge earned 1600 total points
ID: 39689572
If you don't want to drop the table, then use something like this:

insert into StockHistBak
select * from StockHist
0
 
LVL 57

Assisted Solution

by:Raja Jegan R
Raja Jegan R earned 400 total points
ID: 39689573
via TSQL:

INSERT INTO StockHistBak
SELECT * FROM StockHist

If you have Identity column on the table then you have to use SET IDENTITY_INSERT StockHist ON and Off before and after the statements along with column list instead of * to get it work.
0
 

Author Closing Comment

by:Dovberman
ID: 39689651
Thank you all.
0
 
LVL 25

Expert Comment

by:Lee Savidge
ID: 39689667
You're welcome.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

916 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