View Poll Results: How do i insert a identity column and rename a particular table

Voters
3. You may not vote on this poll
  • Inserting a identity column using tsql

    0 0%
  • Renaming the table, using tsql

    3 100.00%
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2002
    Posts
    3

    Exclamation Unanswered: Scheduling a job !

    hi,
    i am trying to automate the following process using TSQL.
    1. Import table 'A' from Database 'x' to my Database 'Y'
    2. After the import is complete , insert an identity column in table A, make it a Primary key and then rename it as 'B'.

    I was successful in Scheduling a job to import the table from database 'X' to "Y'. but i am not able to insert the identity column and rename the table.

    Can anyone please help me !
    thanks in advance !
    Arao

  2. #2
    Join Date
    Jul 2002
    Posts
    229
    Can't you let the job first do a Create Table to create the new table with the name you want it to have, then imort into that table?

  3. #3
    Join Date
    Aug 2002
    Posts
    3

    Post

    i will try doing that. but i need to drop the previous table which has the same name. and the job is erroring out at this point. it says " the @newname value is already in use as a object name and would cause duplicate that is not permitted. the step failed " but it's not in use by any of the users. i tried several times but it will never drop the table ! the following is my code.

    if exists (select * from sysobjects where id = object_id(N'[dbo].[AR_ACCOUNTS') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    drop table [dbo].[AR_ACCOUNTS]
    GO
    EXEC sp_rename 'AR1_CUSTOMERMASTER', 'AR_ACCOUNTS'
    GO

    thanks,
    anitha

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •