Can foreign key be NULL?
800675Sep 29 2010 — edited Sep 29 2010Hi Guys,
I created two table products and orders -
CREATE TABLE products (
product_no number(2) PRIMARY KEY,
name varchar2(20),
price number(2) UNIQUE
);
Insert into products values(17,'test',10); --Value inserted in Products.
Result - 1 Row inserted.
CREATE TABLE orders (
order_id number(10),
product_no1 number(10) REFERENCES products (product_no),
quantity number(10)
);
Insert into orders
values(11,null,10); --Value inserted in orders.
Result - 1 Row inserted.
When I am entering the "NULL" entry in place of foreign key it is acceptable and row is inserted..May i know the complete reason that how is it possible to enter NULL values in place of foreign keys which are completely dependent here on the primary key values of the Base table(products)..
If "NULL" entries are allowed in foreign keys then it means currently no pointer to base table means we can delete base table without deleting the "ORDERS" table..instead of bothering about that it is having a foreign key reference in it...
Please Explain me this...