Re: Key field in a table?
Date: Tue, 19 Jan 1999 21:00:37 GMT
Message-ID: <36a5f1d1.29776205_at_inet16.us.oracle.com>
On 19 Jan 1999 20:16:58 GMT, sjx_at_peon.rightiming.com (Sheng Juexin) wrote:
>I want to create a table with a field "User_Id". I want "User_Id" to be the key
>to distinguish different rows in the table. If I insert a new row with the same
>"Uer_Id" value, the Oracle should refuse to insert the now row. Can I define
>such a kind of table?
>
>Thank you!
You want to define that column as the primary key.
eg.
SQL> create table mytable(
2 user_id number primary key,
3 name varchar2(30) );
Table created.
SQL> insert into mytable values ( 1, 'Chris' ); 1 row created.
SQL> insert into mytable values ( 2, 'Tom' ); 1 row created.
SQL> insert into mytable values ( 1, 'Joel' ); insert into mytable values ( 1, 'Joel' )
*
ERROR at line 1:
ORA-00001: unique constraint (CLBECK.SYS_C0034782) violated
SQL> select * from mytable;
USER_ID NAME
---------- ------------------------------ 1 Chris 2 Tom
Hope this helps.
chris.
>
>sjx
-- Christopher Beck Oracle Corporation clbeck_at_us.oracle.com Reston, VA. ---------------------------------------------------------------------------- Opinions are mine and do not necessarily reflect those of Oracle CorporationReceived on Tue Jan 19 1999 - 22:00:37 CET