I have the following as a CREATE TABLE in Oracle:
CREATE TABLE cs2_users (
empnum varchar2(12) PRIMARY KEY,
toolsId varchar2(20)
CONSTRAINT nn_cs2_users_toolsId NOT NULL
CONSTRAINT fk_cs2_users_users FOREIGN KEY REFERENCES users.userid,
admin number(1,0) DEFAULT 0
CONSTRAINT nn_cs2_users_admin NOT NULL
CONSTRAINT ck_cs2_users_admin (admin IN (0,1)),
givenname varchar2(30) NOT NULL,
middlename varchar2(30),
sn varchar2(30) NOT NULL,
mail varchar2(50) NOT NULL
);
However it fails with this error:
ERROR at line 5:
ORA-02253: constraint specification not allowed here`
When I connect using SQL*Plus, this is the version info:
SQL*Plus: Release 11.2.0.3.0 Production on Tue Dec 18 16:38:27 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Help?
If you want to specify an inline constraint, that definition is separate from the definition of the column. You need to specify the type of the constraint if you are creating a
CHECKconstraint. And your foreign key constraint needs to specify which column you are referencing. So, for example, this will workthough it seems odd that the
toolsIdreferences theuserIdcolumn fromusers. It would seem more likely that you would want thetoolsIdcolumn to reference thetoolsIdcolumn from atoolstable or that you would want to name the column something likeuserIdif you want to reference theuserIdcolumn fromusers. But then I’d question why you have a separatecs2_userscolumn rather than simply putting this information in theuserstable.