|
-
Jan 3rd, 2002, 07:24 AM
#1
Thread Starter
Member
Switching Identity Off
I want to know is it possible to swich off an Identlty property on a column through T-SQL? I want to set up a job to turn off this property whist making some other changes to the table.
I know I can alter the properties through the database diagram
or the table designer. There is an idex on this field but the numbers are remining unique.
Thanks in advance
-
Jan 3rd, 2002, 08:10 AM
#2
Fanatic Member
Yup sure is. Use the following to allow explicit entry of a value in an identity column.
SET IDENTITY_INSERT tblTableName ON
To set it back:
SET IDENTITY_INSERT tblTableName OFF
The liver is bad. It must be punished.
-
Jan 3rd, 2002, 09:25 AM
#3
Thread Starter
Member
Thanks Rsingh
The problem I have is that the Identity property is being switched off permently and not just to allow explicit insertions. If I use the Set_Identity Insert and trying to insert explicit values into another table at the same time (which could happen) then SQL is going to return an error.
I need to completly drop the identity property not just turn if off.
Any Ideas?
-
Jan 3rd, 2002, 09:36 AM
#4
Fanatic Member
OK - I haven't tried this, but have you considered the ALTER table command for changing the column definition? Its of the form
ALTER TABLE tblTable ALTER COLUMN colColumnName INTEGER(scale,precision)
The liver is bad. It must be punished.
-
Jan 3rd, 2002, 10:39 AM
#5
Thread Starter
Member
yes I have!!!!
but to date I've had no luck.
-
Jan 3rd, 2002, 10:46 AM
#6
Fanatic Member
O arse!
BOL states:
'If the altered column is an identity column, new_data_type must be a data type that supports the identity property. '
What is your highest identity value? You might need to convert to a larger datatype. I'll try it on one of my db's and see if I can get something that works.
The liver is bad. It must be punished.
-
Jan 3rd, 2002, 11:21 AM
#7
Fanatic Member
It doesn't look like it can be done. The quote above implies that although you can change the datatype of the column, it wil still remain an identity. It also stated that the changed column cannot be one that is 'Used in a PRIMARY KEY or [FOREIGN KEY] REFERENCES constraint.
It might be possible to do it by working against the system tables directly if you're confident with them - but I'm not sure
I couldn't find any sp's or xp's either so you'll probably have to use Enterprise Manager.
The liver is bad. It must be punished.
-
Jan 3rd, 2002, 11:56 AM
#8
Thread Starter
Member
Thanks for the help anyway!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|