Syed Kamran Ahmed
Syed Kamran Ahmed

Reputation: 107

Alter column which is a composite key-Sql Server

I am trying to alter Version column to decimal(3,1) but it is giving this error

The object 'PK__SlideVer__E0872D0E86F75C91' is dependent on column 'Version'.

fkSlideId is a foreign key.See the image

enter image description here

Upvotes: 1

Views: 887

Answers (2)

Tharunkumar Reddy
Tharunkumar Reddy

Reputation: 2813

I have just shown you a sample example.

CREATE TABLE TAR1
    (
    ID INT NOT NULL,
    NAME VARCHAR(20) NOT NULL
    )



        ALTER TABLE TAR1 ADD CONSTRAINT PK_1 PRIMARY KEY(ID,NAME)

        ALTER TABLE TAR1 ALTER COLUMN NAME VARCHAR(50) -- will throw an error

        ALTER TABLE TAR1 DROP CONSTRAINT PK_1

        ALTER TABLE TAR1 ALTER COLUMN NAME VARCHAR(50)  not null --You must specify not null
        ALTER TABLE TAR1 ADD CONSTRAINT PK_1 PRIMARY KEY(ID,NAME)

Upvotes: 1

Vicky_Burnwal
Vicky_Burnwal

Reputation: 981

As @Buddi pointed, you need to first drop the primary key and other any dependent object before altering your column.

ALTER TABLE SlideVersion
DROP CONSTRAINT PK__SlideVer__E0872D0E86F75C91

Upvotes: 0

Related Questions