This is how I create the table:
CREATE TABLE IF NOT EXISTS division (
DIV_ID INTEGER PRIMARY KEY ,
DIV_CODE VARCHAR(10) ,
DIV_NAME VARCHAR(20) ,
GR_ID INTEGER ,
UNIQUE (DIV_CODE, DIV_NAME, GR_ID) ,
CONSTRAINT FK1 FOREIGN KEY (GR_ID) REFERENCES grade(GR_ID) )
If a row exists where DIV_CODE="1"
, DIV_NAME="1"
and GR_ID=1
, and I try inserting another row with values "1", "1" and 1, then I get a SQL integrity error, which is expected.
If a row exists where DIV_CODE="1"
, DIV_NAME="1"
and GR_ID=null
, and I try inserting another row with vales "1", "1" and null, then the new row is inserted. I now have 2 rows with the same values for each column. Can I setup the table differently to get a similar integrity error for this scenario?
Thanks
EDIT
removed NOT NULL
from GR_ID
definition.