How to add a "Constraint Unique" to a column without deleting the table or column

Asked

Viewed 2,140 times

1

This is the example table

create table usuario(
    id serial primary key not null,
    nome varchar(100),
    email varchar(100),
    login varchar(100),
    senha varchar(100),
    tipo varchar(50),
    status varchar(30)
)

I used that code, but it didn’t work

alter table usuario add constraint unique_login unique(login)

2 answers

1


hello. I tried it like this and it worked:

alter table usuario add unique(login);

0

the codes

alter table usuario add constraint unique_login unique(login)

and

alter table usuario add unique(login)

are correct. I tested them both and they both worked

Browser other questions tagged

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