Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select * form tbl_customer
column: id,name,price

select * from tbl_order

column:order_id,id,product_name


two table relationship foreign key..

but tbl_order how to accepted a 0 value from tbl_customer
Posted
Updated 10-Jun-15 3:34am
v2
Comments
CHill60 10-Jun-15 9:35am    
It's still not clear what you are trying to do. Can you provide an example of the data in the tables (3 or 4 rows only) and what you are expecting to see after running the query
ZurdoDev 10-Jun-15 9:44am    
The value in the foreign table has to match a value in the source table. You can't get around that, except for using NULL.
MohamedEliyas 11-Jun-15 2:26am    
any example query using null and foreignkey
ZurdoDev 11-Jun-15 7:29am    
Sure, insert NULL instead of a value.

1 solution

Your database design makes no sense.
1. Why is price in the tbl_customer table?
2. Why is product_name in the tbl_order table?
Re-look into the database design:
1. http://www.datanamic.com/support/lt-dez005-introduction-db-modeling.html[^]
2. http://www.studytonight.com/dbms/database-normalization.php[^]
Some example:
Table Name      Columns
tbl_customer    cust_id (primary key)
                cust_name 
tbl_product
                product_id (primary key)
                product_name
                price
tbl_order
                order_id (primary key)
                cust_id (foreign key to tbl_customer)
                product_id (foreign key to tbl_product)
 
Share this answer
 
Comments
Maciej Los 10-Jun-15 11:29am    
5ed!
Peter Leow 10-Jun-15 21:40pm    
Thank you, Maciej.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900