Not Null on Primary Key???
I'm designing a new physical data model using a third party tool. When I generate the database creation script automatically it puts 'not null' constraints on the primary keys. I don't have much experience with this particular tool and can't find the correct setting to stop this.
The extra 'not null' constraints are redundant but what would be the problem if I just leave them? For example, would the 'not null' condition be checked twice for every insert or update?
Any ideas? I could always just edit the script... :)
Example of table creation...
Example:
create table TBL_PERSONWORK (
PERSONID NUMBER(9) not null,
LIMIT NUMBER(3),
PEREVERY NUMBER(3),
DAP NUMBER(5),
HAZARD NUMBER(1),
constraint PK_PERSONWORK primary key (PERSONID)
using index
tablespace INDX
);
So the 'not null' on PERSONID adds an extra not null constraint when this is already covered by the PK constraint?
Slimdave - Thanks for your help.
Cheers
Re: Example of table creation...
Quote:
So the 'not null' on PERSONID adds an extra not null constraint when this is already covered by the PK constraint?
Correct, it does, and this will be an overhead on insert.
SQL> create table my_table (my_column number not null primary key);
Table created.
SQL> select constraint_type from user_constraints
2 where table_name = 'MY_TABLE';
C
-
C
P
SQL> alter table my_table modify (my_column null);
Table altered.
SQL> select constraint_type from user_constraints
2 where table_name = 'MY_TABLE';
C
-
P
SQL> desc my_table;
Name Null? Type
----------------------------------------- -------- --------------------
MY_COLUMN NOT NULL NUMBER
Your tool may have a configuration setting to prevent such an unfortunate double-constraint.