Solved

Make a backup of a SQL Server table

Posted on 2013-12-02
5
287 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 400 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 400 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 100 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

830 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