If I have a fairly large expression then the box to display it isn't big
enough.
Please can you let us resize the precedence constraint editor?
DCR?
Thanks.
-JamieYes, please open a DCR Jamie. Thanks for the feedback.
K|||OK. Track ID 375512625
Please can you let us resize the precedence constraint editor?
DCR?
Thanks.
-JamieYes, please open a DCR Jamie. Thanks for the feedback.
K|||OK. Track ID 375512625
Greetings all,
I have an identity field that I need to drop the constraint and recreate it inside a stored procedure. Actually if there is a better way to do what I'm trying to do, I'm all ears.
My concern is that the 2^31 will eventually be exceeded on the int declaration for this field and I'm not using the field for anything other than to identify uniqueness for a specific task.
What I would like to do is re-number this field each time the table is populated. (not remember the last index)Once I'm finished with the table, I'd like the constraint to be removed.
Any thoughts?
Adamus
The only 'real' option is to drop the existing IDENTITY field, and recreate a new one.|||I was leaning that way.
Thank you,
Adamus
is it possible? if so how can i do it.
Nope, you cannot remove the identity property from a column. What you can do is to transfer the values to a different column and drop the column:
create table testIdentity
(
identityColumn int identity
)
go
insert into testIdentity default values
insert into testIdentity default values
insert into testIdentity default values
insert into testIdentity default values
insert into testIdentity default values
insert into testIdentity default values
go
alter table testIdentity
add nonIdentityColumn int null
go
update testIdentity
set nonIdentityColumn = identityColumn
go
alter table testIdentity
drop column identityColumn
go
select *
from testIdentity
But i would like to know why it is not possible through t-sql while we are able to do it from EM|||
Because EM does something along the lines of what I did. EM actually is pretty inefficient in many cases in how it performs operations (like adding a new column it does a drop column then and adds a new column where an ALTER TABLE would suffice). But it is usually understandable as it takes the easiest, most straightforward path for automation, rather than a method that looks better but cannot be automated quite as easy.
One thing to try is to trace what EM does using profiler. That is a great place to see the queries it does. In Management Studio, I changed the identity property, and these are the action queries that were sent:
CREATE TABLE dbo.Tmp_testIdentity
(
IdentityColumn int NOT NULL
) ON [PRIMARY]
go
IF EXISTS(SELECT * FROM dbo.testIdentity)
EXEC('INSERT INTO dbo.Tmp_testIdentity (IdentityColumn)
SELECT IdentityColumn FROM dbo.testIdentity WITH (HOLDLOCK TABLOCKX)')
go
DROP TABLE dbo.testIdentity
go
EXECUTE sp_rename N'dbo.Tmp_testIdentity', N'testIdentity', 'OBJECT'
go
The method I gave you is far less distructive, but either will work.