How to create a Primary Key Constraint named in Postgres?

Asked

Viewed 1,926 times

1

I am proceeding this way to create a table without primary key initially. Then I add a field id serial type and try to create the Constraint to the Primary Key (PK):

create table macaco(
  nome varchar(50),
  idade integer
);

--adicionando o id do tipo serial
ALTER TABLE "macaco" ADD COLUMN id SERIAL;

--criando a primary key 
ALTER TABLE "macaco" ADD PRIMARY KEY (id);

The way I do above, it creates the PK with the name of macaco_pkey. So far so good. But what if I want to create the Constraint with the name id_macaco_pk, what should I do?

1 answer

0


  • All right, man, you helped a lot!

Browser other questions tagged

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