Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • 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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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