SQL Server table identity field configuration

Hi there!

After using "sp_rename" in certain tables, copying another one (say <new>) "over" the original one (say <old>) , renaming again, etc, I created a "PK_Temp" Key in the <new>ly created one because I guess I did not created two identical tables, at first, as I should.

Well, everything looks ok, with the first column defined as UserID (PK, int, not null) by the way.

Question: why should I create an INSERT procedure WITH the UserID number as one of the VALUE fields, if (as an identity and key-related field) it should create the UserID automatically?

In other words, could you please tell what property should I check (probably alter) so that the identity field continues the behavior it had in the past, previously to the whole renaming and copying over stuff?

Thanks!
fskilnikAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
You cannot add the IDENTITY property to an existing column.  You will have to recreate either the column or the table.

You could add a new column with the IDENTITY property, enable IDENTITY_INSERT, and then copy the values over from the existing column, disable IDENTITY_INSERT, and delete the old column or you could create a new table with the correct schema and copy the data over.

Here is a link that might explain it in a little more detail.

http://sqlmag.com/t-sql/adding-identity-property-existing-column
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fskilnikAuthor Commented:
Hi, Brian!

Got it. Thanks for the info and for the link.

Regards,
fskilnik
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.