Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Make a backup of a SQL Server table

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
Dovberman
Asked:
Dovberman
  • 3
3 Solutions
 
Lee SavidgeCommented:
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
 
Lee SavidgeCommented:
If you don't want to drop the table, then use something like this:

insert into StockHistBak
select * from StockHist
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
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
 
DovbermanAuthor Commented:
Thank you all.
0
 
Lee SavidgeCommented:
You're welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now