Tuesday, February 14, 2012

Counter settings?

I'm changing databases for a website from Access to SQl Server.
In the Access file, the ID column is assign as 'counter' so the value is automaticly raised by 1 when 'Insert'-statement is used.
How is the equivalent made for SQL Server?
I get an error message when I use the 'Insert statement'

Thanks
CalleOriginally posted by Calle
I'm changing databases for a website from Access to SQl Server.
In the Access file, the ID column is assign as 'counter' so the value is automaticly raised by 1 when 'Insert'-statement is used.
How is the equivalent made for SQL Server?
I get an error message when I use the 'Insert statement'

Thanks
Calle

Try changing your ID column to an integer and set the Identity property to Yes (not for replication), set seed to 1 and increment to 1.

This is the same as the Autonumber function in Access.|||I think this has already been done. actually this is the reason for the error. you can remove identity property on the target table and do your insert. once it completes you can reestablish identity(1,1). another way would be to set identity_insert your_table_name on before the insert, and then set it off after insert completes. third way would be to exclude the identity field from being populated. but the last method would assign brand new identity values which may break relationship between tables.

No comments:

Post a Comment