[sqlite] database development - correct way?

2010-06-09 Thread Oliver Peters
Hello, despite it's just a question about construction I hope somebody is willing to push me into the right direction if necessary. my simplified case -- I've the 3 tables customer, article and order my thoughts about the table customer: the customernumber can be from 3 different

Re: [sqlite] database development - correct way?

2010-06-09 Thread Adam DeVita
I wouldn't advise using an SQL keyword as a table name: "Order" I presume that your order collection table example is shorter than the real one for the sake of the example? One often sees a date or time of some sort associated with an order so that one can create reports based on dates. (How many

Re: [sqlite] database development - correct way?

2010-06-09 Thread Tim Romano
Placing a unique composite index on (customer, article) in the Orders table prevents recurring purchases of the same article by the same customer. Acme might buy a widget in June and then place another order for a widget in September, but the order would be rejected as a duplicate. Typically, Ord

Re: [sqlite] database development - correct way?

2010-06-09 Thread Oliver Peters
Adam DeVita writes: > > I wouldn't advise using an SQL keyword as a table name: "Order" > > I presume that your order collection table example is shorter than the real > one for the sake of the example? [...] yes - and the content has nothing to do with my real tables. The example should be o

Re: [sqlite] database development - correct way?

2010-06-09 Thread Rich Shepard
On Wed, 9 Jun 2010, Tim Romano wrote: > Typically, Orders are divided into OrderHeader and OrderDetail tables: > > OrderHeader > id integer primary key > orderdate > customerid > > OrderDetail > id > orderid references OrderHeader(id) > articleid references article(id) > quantity int > > And you

Re: [sqlite] database development - correct way?

2010-06-09 Thread Rich Shepard
On Wed, 9 Jun 2010, Oliver Peters wrote: > So I assume that it is not(!) a mistake not(!) to use a composite PK in my > table "customer" (customernumber,customerorigin) and to refer to it from > the table "order" where I had to use these fields as a composite FK? Oliver, Too many negatives th

Re: [sqlite] database development - correct way?

2010-06-09 Thread Oliver Peters
Rich Shepard writes: > > On Wed, 9 Jun 2010, Oliver Peters wrote: > > > So I assume that it is not(!) a mistake not(!) to use a composite PK in my > > table "customer" (customernumber,customerorigin) and to refer to it from > > the table "order" where I had to use these fields as a composite FK

Re: [sqlite] database development - correct way?

2010-06-09 Thread Tim Romano
Oliver, Your first solution CREATE TABLE customer( idINTEGER PRIMARY KEY AUTOINCREMENT, customernumberINTEGER, customeroriginINTEGER, name TEXT, UNIQUE(customernumber,customerorigin) ); is the better of the two because it simplifies foreign keys: t