Click to See Complete Forum and Search --> : Unique Key Syntax


shivanand
12-16-2002, 04:40 AM
hi

There is a table with rows , with one column as NOT NULL constratint.
I want to add unique key constraint in that column

can u please provide me syntax.

jovery
12-16-2002, 04:50 AM
This should help


ALTER TABLE table_name
ADD CONSTRAINT constraint_name
UNIQUE (column_name)


Regards

rotem_fo
12-16-2002, 04:52 AM
Hi,
use:
ALTER TABLE <table_name>
ADD CONSTRAINT <contraint_name>
UNIQUE (<columns_name>);

example:
ALTER TABLE EMP ADD CONSTRAINT EMP_NO_UNQ UNIQUE (EMPNO);

Cheers,
R.

shivanand
12-16-2002, 05:58 AM
hi all i am getting this error vcan any one help me out.

ALTER TABLE PRONTO_WISP ADD CONSTRAINT WPNAME_UN UNique(WISP_NAME)
*
ERROR at line 1:
ORA-02299: cannot validate (WINTER02.WPNAME_UN) - duplicate keys found

Sameer
12-16-2002, 07:20 AM
You are trying to create UNIQUE constraint on column WISP_NAME, but it has duplicate contents.


SELECT * FROM pronto_wisp
WHERE ROWID NOT IN
( SELECT MIN(ROWID) FROM pronto_wisp GROUP BY wisp_name)


Above sql stmt will give you duplicate records for WISP_NAME. You need to delete duplicate entries prior to creating constraint.

Sameer