How to add relationship on same fields of Two tables (Table Order and Table Product) in SQL Server?

Dear anyone can help me as i have two tables named as Order and Products which have more than two multiple same fields i want to make relationship among all same fields in both tables You can see tables in pictures below:

enter image description here

enter image description here

Upvotes: -3

Views: 762

Answers (1)

George Menoutis
George Menoutis

Reputation: 7260

This is quite simple, assuming product_id is a key for items.

Make the column Order.product_id be a FOREIGN KEY to Product.product_id. Drop all other columns that exist in Products from the table Order.

Note inspired by comment from @WEI_DBA: price and quantity are not really characteristics of product, but of order. These should remain in the Order table and be removed from the Product table instead. Generally, give each table the data which depend on that table's primary key.

Upvotes: 0

Related Questions