0

Trying to add UNIQUE attribute to existing column, getting syntax error

smartbrain=# ALTER TABLE users ALTER COLUMN email VARCHAR(100) UNIQUE NOT NULL;

ERROR:  syntax error at or near "VARCHAR"
LINE 1: ALTER TABLE users ALTER COLUMN email VARCHAR(100) UNIQUE NOT...
FoggyDay
  • 11,962
  • 4
  • 34
  • 48

1 Answers1

0

If "users" already has column "email", and the data type is already "varchar(100)", then try this:

ALTER TABLE users
  ADD  UNIQUE (email);

ALTER TABLE users
  ALTER COLUMN email set NOT NULL;
FoggyDay
  • 11,962
  • 4
  • 34
  • 48