Thursday, October 28, 2010

Vb.net How do i put data in a sql table that has a foreign key? invoice table has multiple ';start times'; table?

For each invoice, there is a foreign key to a start times table, each invoice has multiple start times.Vb.net How do i put data in a sql table that has a foreign key? invoice table has multiple ';start times'; table?
If the foreign key constraint has been defined for your invoice table, it will not allow any insert with a value that does not exist already in the 'start times' table. For multiple start times, this would work the same way, depending on just how you implemented that one-to-many relationship. The most normalized way would be a separate relation table like this:



Invoice table (invoice_number, ...)

Start_times table (start_timestamp, ...)

Invoice_time table (invoice_number, start_timestamp, date, duration, ...)



Here, the foreign-key relationship is moved down to the Invoice_time table, which allows however many time periods for the invoice as needed.

No comments:

Post a Comment