Backup of tables

Hi Guys,< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I would like to take a backup of tables and further use them for manipulation purpose.

 

(e.g.)

          Select * into arc_employee_07_07_2005 from employee

 

Where 07_07_2005 is formatted from getdate().


How can i achieve this formate.

Thanks in advance.




Answer this question

Backup of tables

  • Stanley_S

    You cannot specify an expression as table name for the INTO clause. You have to generate the name and then use dynamic SQL to execute the SELECT INTO statement. If you do not want to use dynamic sql, another option is to do following:

    select * into _temp_arc_employee from Employee
    exec sp_rename '_temp_arc_employee', 'new name'

    This will work only if this is the only connection performing this operation otherwise you will get error due to same name being used for the SELECT...INTO table name from different connections.

  • PCHEEK

    Look at the day, month, year or datepart function. You can use those with string functions to generate the leading 0 also like:

    select right('00' + cast(day(current_timestamp) as varchar)), 2) 

  • IMT AG

    Hi JayaChandran

    i have just modified ur query to something like this.

    select * into Arc_Employee_+(select cast(day(current_timestamp) as varchar)+'_'+
    cast(month(current_timestamp) as varchar)+'_'+cast(year(current_timestamp) as varchar))
    from Employee

    Can you modify the above query. so that the table name should be having a suffix of date. (eg) Ar_TableName_Date.

    Thanks in Advance

  • Backup of tables