Ternary Relation - How to code it in SQL Server ? +derived attribute -


enter image description herei have 3 tables wich in tenary relation (1:1:n) in er-modell. transfer sql-server, need add table it, right? (found solution @ least via google). i'm not sure how it.

code:

create table[buyer]   --1 in relation (id int primary key)  create table[payment] --1 in relation (id int primary key)  create table[product] --n in relation (id int primary key,)  create table[connecting_tab] ( id1 int constraint fk_buyer foreign key references buyer(id), id2 int constraint fk_payment foreign key references payment(id), id3 int constraint fk_product foreign key references product(id),     ) 

relation described in modell as"buys"

will build tenary relation in sql server? how can define relation 1:1:n - relation of connecting_tab buyer-,payment- , product-tab? (1:1,1:n or n:n)

also: there derived attribute detached relation-symbol in middle (->er-modell). write in connecting_table:

  create table [connecting_tab]   (...    attr int not null --derived attribute   ) 

or how should define derived attribute?

sorry poor english, not first language. in advanced

a natural way model seem be:

create table purchases (     buyer_id int constraint fk_buyer foreign key references buyer(id),     payment_id int constraint fk_payment foreign key references payment(id),     product_id constraint fk_product foreign key references product(id),      final_price decimal(10, 4)    ); 

although models diagram, seems strange. more used situations product purchases in tables called orderlines, these tied orders, , orders have key linking customers. customers (and perhaps orders) tied payments.

that may not true in case. if purchases single product @ time single method of payment, think expect "payment" attributes in purchases table.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

Voice chat over bluetooth between Android & Python (pybluez) -

Integrate jquery-globalize into an ASP.NET Core MVC App -