Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: compound primary key with null columns... is it possible?
"Giovanni Azua" <bravegag_at_hotmail.com> wrote in message
news:atsbn8$25ar5$1_at_ID-114658.news.dfncis.de...
> The problem is that the two new columns could likely
> have null values and I was aware of the capability of having
> nullable columns inside unique indexes, is it possible with
> primary keys as a special case?
No
SQL> ed
Wrote file afiedt.buf
1 create table purchase_product(
2 Customer_ID number,
3 Product_ID number,
4 Branch_ID number,
5 Purchase_Date date default sysdate,
6 color_id number,
7 size_id number,
8 description varchar2(1000))
9* tablespace users
SQL> /
Table created.
SQL> alter table purchase_product
2 add constraint pk_pp primary key
(customer_id,product_id,branch_id,purchase_date);
Table altered.
SQL> desc purchase_product;
Name Null?Type
*
SQL>
> now I would like to add to this PK also COLOR_ID and SIZE_ID
> so the customers could also buy different of those the same day.
They could however only buy 1 of the same colour and size. Fortunately although purchase_date is a date column that is a datetime datatype so in fact the restriction doesn't apply to the same DAY but the same day and time (i.e Niall buys 3 large blue sweatshirts in one transaction).
I'm also a little confused as to why you 'prefer to use natural keys' but then have a bunch of id (or artificial key) columns in the table. I'd follow exactly what you seem to have done with the other tables and use a new column purchase_product_id as the primary key.
-- Niall Litchfield Oracle DBA Audit Commission UK ***************************************** Please include version and platform and SQL where applicable It makes life easier and increases the likelihood of a good answer ******************************************Received on Thu Dec 19 2002 - 06:27:10 CST