Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Oracle unique user id and username

  • 05-10-2007 11:13am
    #1
    Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭


    I have a bit of a problem.

    I each user in my table to have a unique username and user_id.
    So the table cant contain 2 users with the same user id and it cant contain 2 users with the same username.

    I don't think oracle supports more than one primary key in a table so what could I use a secondary key?


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I don't know oracle but is there 'Is Unique' constraint you can set on the field?


  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    Anyone know about creating alternate keys in sql plus?
    Is that what Im looking for?


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    quinnd6 wrote:
    Anyone know about creating alternate keys in sql plus?
    Is that what Im looking for?

    Are you looking for a composite primary key?

    edit: no you are not

    My initial suggestion would be to have two seperate tables, one for usernames, one for user_ids with a foreign key linking them up.
    I don't know oracle but is there 'Is Unique' constraint you can set on the field?

    There is. ALTER TABLE X ADD UNIQUE(COLUMN_NAME)


  • Registered Users, Registered Users 2 Posts: 1,559 ✭✭✭quinnd6


    I read on some webpage that when you use unique it allows you to have blanks.
    So I could end up allowing blank usernames.

    Are you sure its not secondary key Im looking for?

    The user_id could be the primary key and the username could be the secondary key(I think they're called alternate keys in sql plus).


    If only I knew how to create a secondary key in sql plus.
    I cant find how to create a secondary key in sql plus anywhere.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Ht concept of "secondary key" doesn't exist in Oracle.

    If its in MySQL, I'd say its probably unique to that system.

    In Oracle, as well as any other ANSI-compliant RDBMS, you have UNIQUE constraints, which are typically enforced using a UNIQUE Index.

    A UNIQUE field may allow a null value, but not if you define the field to be NOT NULL, obviously.


  • Advertisement
Advertisement