Link tables/rows in sqlite -


in database have 3 tables, 1 customers, 1 orders , 1 products. customer can have number of orders , order can have number of products. how can implement relationship between 3 tables?

information stored in database:

customer: social security number, name, address, phone number

order: order number, date

product: product id, category, price

ok here's start.

first need id each table (an id unique identifier, if want customer x, there won't 2 customer x in table) customer u can use social security number (or create column called customer_id)

a customer can have number of orders, should put column in order know order belongs customer. in order add column called customer_id references customer_id in table customer

so these 2 orders belong customer customer_id = 1:

order_number     date        customer_id 1                1/1/2013         1 2                2/1/2013         1 

customer_id in orders called foreign key

the same goes rest.

(ps : change name of table order, order keyword used in sql, order items select .... table1 order ....)


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -