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 !
AraoCan'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?|||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,
anithasql
No comments:
Post a Comment