constraints error [message #601930] |
Wed, 27 November 2013 09:25 |
|
aravindreddy.akiti
Messages: 14 Registered: October 2013 Location: hyderabad
|
Junior Member |
|
|
create table subject
(
sub_code varchar2(10) constraint subj_code_pk
);
error at line 3:
constraint specification not allowed here.
can you explain me what is the error.
|
|
|
|
|
Re: constraints error [message #601935 is a reply to message #601933] |
Wed, 27 November 2013 09:48 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Wow, that was a big document for you to read through in just 17 minutes (assuming that you accessed the link as soon as it was posted). Was there no information in that link pertaining to constraints and the syntax surrounding them? I'm shocked! Shocked an appalled I say, that Oracle would not include information on such a topic.
[Updated on: Wed, 27 November 2013 09:49] Report message to a moderator
|
|
|
|
|
Re: constraints error [message #601974 is a reply to message #601960] |
Thu, 28 November 2013 00:50 |
John Watson
Messages: 8931 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
With regard to this syntax,create table test (col number primary key);
speaking as a DBA, please do not use it! In no particular order:
1. It will have a created a contraint and an index with a silly system generated name. You will have to rename them.
2. The index will be a unique index. This means that the constraint is non-deferrable.
3. If you disable the constraint, the index will be dropped.
This is better,create table test1 (col number constraint pk_test1 primary key); because the constraint and the index will have proper names. The other problems remain.
You should create the index first, and think about it: how should it be structured? Definitely nonunique. What columns, in what order? Reverse key? Compressed? Nologging? Then define the constraint: deferrable initially immediate? A constraint and an index are not the same thing (OK, they were decades ago) and should be created separately.
|
|
|
Re: constraints error [message #601975 is a reply to message #601974] |
Thu, 28 November 2013 01:03 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
John Watson wrote on Thu, 28 November 2013 12:203. If you disable the constraint, the index will be dropped.
A constraint and an index are not the same thing (OK, they were decades ago) and should be created separately.
Indeed a very important point made by John, specially whenever we want to DISABLE/NOVALIDATE the constraint. KEEP/USING index can't be used if a non-unique index was not pre-created. If we do not create an index explicitly, then the unique index which is automatically created will be dropped. A simple syntax, but it could impact the entire design.
|
|
|