0
DROP TABLE Backup_LOAD_EMPLOYEE
SELECT * INTO dbo.Backup_LOAD_Employee FROM LOAD_Employee WHERE 1=1
TRUNCATE TABLE LOAD_Employee

I am bulk inserting employee data from external source . In my sp each time after import , I will truncate the load_employee table. Before truncate I would like to take a table backup,previous day data should truncate .

how to give auto increment table name ( in an SP)?

1 Answer 1

1

This doesn't answer your question directly (but you can use dynamic SQL), but a better solution is probably to put the backup date into a column, instead of creating one table per day. Then you can more easily query the archived data for multiple days, because it's all in one table. Something like this:

create table dbo.Backup_LOAD_Employee (
    BackupDate date,
    --- other columns
    )
go

insert into dbo.Backup_LOAD_Employee (BackupDate, ...)
select cast(getdate() as date), ... -- other columns
from dbo.LOAD_Employee

truncate table dbo.LOAD_Employee
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the info. Main idea behind this is to retain the backup table for a day very next day it will it should dropped. As the its contain huge data.
I would still use a column for the date. It's highly likely that at some point you'll need to use it, even if it's only for development/debugging purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.