On 15/12/2011, at 2:11 PM, Jeff Matthews wrote: > Customer Table > > ID > Name > > Invoice Table > > CustomerID > InvoiceNumber > > When I create a new invoice record for the selected customer, does > Invoice.CustomerID update with Customer.ID automatically, or do I need to do > this manually? If it's automatic, can someone explain how it does it > automatically?
What do you mean by "the selected customer"? It depends how you've set it up in your schema. For instance, if your schema is: create table "Customer" ( ID integer primary key not null , Name text collate nocase not null ) ; create table "Invoice" ( ID integer primary key not null , CustomerID integer references "Customer" (ID) on delete restrict on update cascade ) ; then: insert into "Invoice" (CustomerID) select max(ID) from "Customer"; will create a new Invoice assigned to the most recently added Customer (assuming no deletions). or: insert into "Invoice" (CustomerID) select ID from "Customer" where "Name" = 'Tom'; will create a new invoice assigned to the customer whose name is 'Tom'. Tom BareFeetWare -- iPhone/iPad/iPod and Mac software development, specialising in databases [email protected] -- Twitter: http://twitter.com/barefeetware/ Facebook: http://www.facebook.com/BareFeetWare _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

