Neither column can be NULL if the column is part of the combination of primary key columns?

Started by Emi Luover 20 years ago2 messagesgeneral
Jump to latest
#1Emi Lu
emilu@cs.concordia.ca

Greetings,

A question about "combination of several columns " as primary key .

A table test (
col1 timestamp not null default now(),
col2 timestamp,
primary key (col1, col2)
);

If I setup primary key as the *combination* of (col1, col2), the col2
will be setup as "NOT NULL" automatically right?
(Although, I did not specify not null constraint for col2)

To allow *col2* to be NULL and make record combination (col1, col2)
unique, I should setup
unique (col1, col2) ?

Thanks,
Emi

#2Jaime Casanova
jcasanov@systemguards.com.ec
In reply to: Emi Lu (#1)
Re: Neither column can be NULL if the column is part of the combination of primary key columns?

To allow *col2* to be NULL and make record combination (col1, col2)
unique, I should setup
unique (col1, col2) ?

Thanks,
Emi

no, you must create a partial unique index...

create unique index indice_col2 on table(col1, col2) where col2 is not null;

--
Atentamente,
Jaime Casanova
(DBA: DataBase Aniquilator ;)