Statement of 2 PK Sql

Asked

Viewed 43 times

0

Good afternoon.

I have the table Icms that has as PK the columnIcmClaFiscal, need to pass the column IcmEmpresa also as PK, but SQL gives me an alert. As I have been able to do this procedure in other cases through the Design and it worked, I was afraid to do the same for this case because, in others did not return this warning. Could advise me how to proceed?

inserir a descrição da imagem aqui

Thank you.

  • Do you want a composite PK or replace your old PK with the new one? Also which Database you are using?

  • I want a composite PK. I’m using Microsoft SQL Server Management Studio 2014

1 answer

1

First you will have to drop your PK and then recreate it, to do this you will need to execute the following commands.

ALTER TABLE Icms
DROP CONSTRAINT <constraint_name>

ALTER TABLE Icms
ADD CONSTRAINT <constraint_name> PRIMARY KEY (IcmClaFiscal,IcmEmpresa )

Where has <constraint_name> you have to put the name of your PK, same as it is in the database

Browser other questions tagged

You are not signed in. Login or sign up in order to post.