Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Difference between table level and column level NOT NULL constraint?

Re: Difference between table level and column level NOT NULL constraint?

From: Uwe Schneider <uwe_at_richard-schneider.de>
Date: Fri, 22 Feb 2002 21:08:44 +0100
Message-ID: <3C76A54C.83DE8856@richard-schneider.de>


Vishalm wrote:
>
> Hi,
>
> What is the difference between table level and column level NOT NULL
> constraint?
>
> for e.g.a not null constraint can be defined in the foll ways
>
> 1)
>
> Create table test
> (testnull VARCHAR2(10) NOT NULL)
>
> 2)
>
> Create table test
> (testnull VARCHAR2(10));
>
> ALTER TABLE ADD CHECK (testnull NOT NULL);
>
> Is there any difference in the way Oracle does validation for the
> above defined constraint methods or are there any performance
> differences?
>

There are indeed two differences:

SQL> create table nulltest (x number, y number not null);  

Tabelle wurde angelegt.  

SQL> alter table nulltest add check (x is not null);  

Tabelle wurde geändert.  

SQL> insert into nulltest values (NULL, 3); insert into nulltest values (NULL, 3)
*
FEHLER in Zeile 1:
ORA-02290: Verstoß gegen CHECK-Regel (AMIS.SYS_C00958)    

SQL> insert into nulltest values (3, NULL); insert into nulltest values (3, NULL)
*
FEHLER in Zeile 1:
ORA-01400: Einfügen von NULL in ("AMIS"."NULLTEST"."Y") nicht möglich

SQL> select column_name, NULLABLE from user_tab_columns where   2 table_name = 'NULLTEST';  

COLUMN_NAME                    N
------------------------------ -
X                              Y
Y                              N


I guess an inline NOT NULL constraint is faster, but try it yourself.

Uwe

> Thanx in advance.
>
> regards,
> Pradeep
>
> (Pls cc ur response to : pradeep.mittal_at_iflexsolutions.com)

-- 
Uwe Schneider       | Telefon +49 7244 / 609504
Haydnstr. 1         | Mail    uwe_at_richard-schneider.de
DE-76356 Weingarten | http://www.richard-schneider.de/uwe
Linux - OS al dente!
Received on Fri Feb 22 2002 - 14:08:44 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US