Home » SQL & PL/SQL » SQL & PL/SQL » Constraint Unique question
Constraint Unique question [message #23078] Sat, 16 November 2002 20:05 Go to next message
nat
Messages: 11
Registered: March 2002
Junior Member
What is the meaning of this error?

21:27:36 ORACLE> CREATE TABLE Lodging1
21:28:11 2 (
21:28:11 3 lodgename VARCHAR2(15) CONSTRAINT lodging_PK PRIMARY KEY,
21:28:11 4 address VARCHAR2(20),
21:28:11 5 name VARCHAR2(25) constraint lodging1-UQ UNIQUE,
21:28:11 6 FOREIGN KEY (name) REFERENCES worker(name)
21:28:11 7 );
name VARCHAR2(25) constraint lodging1-UQ UNIQUE,
*
ERROR at line 5:
ORA-02253: constraint specification not allowed here

But this works:

21:16:50 ORACLE> CREATE TABLE Lodging
21:17:06 2 (
21:17:10 3 lodgename VARCHAR2(15) CONSTRAINT lodging_PK PRIMARY KEY,
21:17:18 4 address VARCHAR2(20),
21:17:22 5 name VARCHAR2(25) UNIQUE,
21:17:25 6 FOREIGN KEY (name) REFERENCES worker(name)
21:17:32 7 );

Table created.
Re: Constraint Unique question [message #23083 is a reply to message #23078] Mon, 18 November 2002 00:07 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
You have used an invalid character in your name specification: the hyphen (-).

Check out the following test I ran:
SQL> create table temp_mhe
  2  (
  3  lodgename varchar2
  4  .
SQL> ed
Wrote file afiedt.buf

  1  create table temp_mhe
  2  (
  3  lodgename VARCHAR2(15) CONSTRAINT lodging_PK PRIMARY KEY,
  4  address VARCHAR2(20),
  5  name VARCHAR2(25) constraint lodging1-UQ UNIQUE,
  6* )
SQL> /
name VARCHAR2(25) constraint lodging1-UQ UNIQUE,
                  *
ERROR at line 5:
ORA-02253: constraint specification not allowed here

SQL> ed
Wrote file afiedt.buf

  1  create table temp_mhe
  2  (
  3  lodgename VARCHAR2(15) CONSTRAINT lodging_PK PRIMARY KEY,
  4  address VARCHAR2(20),
  5  name VARCHAR2(25) constraint <B>lodging1_UQ</B> UNIQUE
  6* )
SQL> /

Table created.

SQL> select constraint_type, table_name, status
  2    from user_constraints where constraint_name = 'LODGING1_UQ';

C TABLE_NAME                     STATUS
- ------------------------------ --------
U TEMP_MHE                       ENABLED

SQL> 


MHE
Re: Constraint Unique question [message #23098 is a reply to message #23083] Mon, 18 November 2002 07:31 Go to previous message
nat
Messages: 11
Registered: March 2002
Junior Member
Thanks Maaher. I could not catch the error!! I am a typical sql novice! Suspect the the system!
Previous Topic: date problem
Next Topic: analyze command
Goto Forum:
  


Current Time: Mon Apr 29 07:29:00 CDT 2024