Changing the data type of column from varchar to int

  • Hi All,

    I have a column which is a primary key. It was mistakenly made NCHAR which actually shoud have been int. Now I am trying to change the data type by using the alter table command I get the following errror

    Msg 5074, Level 16, State 1, Line 2

    The object 'PK_INK_NEXT_OPERATION' is dependent on column 'operation_id'.

    Msg 4922, Level 16, State 9, Line 2

    ALTER TABLE ALTER COLUMN operation_id failed because one or more objects access this column.

    Shoud I drop the primary key make the change and then re create the Primary key??

  • Yes, smth like this:

    alter table MyTable drop constraint PK_INK_NEXT_OPERATION;

    alter table MyTable alter column operation_id int not null

    alter table MyTable add constraint PK_INK_NEXT_OPERATION primary key (operation_id);


    I am really sorry for my poor gramma. And I hope that value of my answers will outweigh the harm for your eyes.
    Blog: http://somewheresomehow.ru[/url]
    Twitter: @SomewereSomehow

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply