Yes you do, the command is a ALTER TABLE:
ALTER TABLE nome-da-tablea ADD PRIMARY KEY (nome-do-campo)
Now, the contents of the field must respect the rules of a Primary key (quoted from the link above):
Limitations and Restrictions A table can contain only one PRIMARY KEY Constraint.
- All Columns defined Within a PRIMARY KEY Constraint must be defined as NOT NULL.
- If nullability is not specified, all Columns Participating in a PRIMARY KEY Constraint have their nullability set to NOT NULL.
That is to say:
- The table can only have a primary key
- If not specified, fields that are part of the Primary key must be non-null
If you have duplicated values in the key will give error, so just validate/correct/delete the data that do not respect the rules of Primary key that will work
Are you making a mistake? If so, what mistake?
– anonimo
would not be
add constraint
??? is wrong there– Ricardo Pontual