i want to drop a column from composite primary key(not to delete from table). if my table is like this.
create table "scott"."xyz"(
"column1" not null,
"column2" not null,
"column3" not null,
"column4" not null,
"column5" not null,
"column6",
CONSTRAINT PRIMARY KEY ("column1","column2","column3","column4")
);
i want to alter this primary key to first three column without dropping it. beacuse i don't know CONSTRAINT name.
You don't need the constraint name:
ALTER TABLE "scott"."xyz" DROP PRIMARY KEY;
ALTER TABLE "scott"."xyz" ADD PRIMARY KEY ("column1","column2","column3");
But it is probably a good idea to give your PK a name in the future:
ALTER TABLE "scott"."xyz"
ADD CONSTRAINT pk_xyz PRIMARY KEY ("column1","column2","column3");
And I would not recommend to use quoted identifiers. You will have problems with various tools in the long run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With