Unique Key Syntax
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: Unique Key Syntax

Hybrid View

  1. #1
    Join Date
    Jul 2002
    Posts
    32

    Unique Key Syntax

    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.
    SHIVANAND HANUMANTAPPA

  2. #2
    Join Date
    Jan 2002
    Location
    Up s**t creek
    Posts
    1,525
    This should help

    Code:
    ALTER TABLE table_name
     ADD CONSTRAINT constraint_name
     UNIQUE (column_name)
    Regards
    Jim
    Oracle Certified Professional
    "Build your reputation by helping other people build theirs."

    "Sarcasm may be the lowest form of wit but its still funny"

    Click HERE to vist my website!

  3. #3
    Join Date
    Nov 2000
    Location
    Israel
    Posts
    268
    Hi,
    use:
    ALTER TABLE
    ADD CONSTRAINT
    UNIQUE ();

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

    Cheers,
    R.
    It is better to ask and appear ignorant, than to remain silent and remain ignorant.

    Oracle OCP DBA 9i,
    C++, Java developer

  4. #4
    Join Date
    Jul 2002
    Posts
    32
    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
    SHIVANAND HANUMANTAPPA

  5. #5
    Join Date
    Sep 2001
    Location
    Düsseldorf, Germany.
    Posts
    588
    You are trying to create UNIQUE constraint on column WISP_NAME, but it has duplicate contents.

    Code:
    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
    Last edited by Sameer; 12-16-2002 at 07:22 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width