0

I have created a Database in Mysql from a Firebird Database. In the Database there is a Common Sequence table(Common_ID) which generates sequence for all tables (45 Tables in database). Some Tables are

Table1 = Sequence (ID Auto-increment)-The Common Sequence Table
Table2 = Process (Sequence, Process_Number(Unique), Category_Name)
Table2 = Tasks (Sequence, Barcode(Unique), Process_Number(sequence from Process Table), Product_Name)

This database already has more than 600,000 records. One "Process" can have Many "Tasks". My questions are: What relationship should be between "Sequence" Table and "Process/Tasks" tables? What relationship should be between Process Table and Tasks Table? How do i insert in "Sequence" Table and use that "ID" in other Tables?

This is my first question and i am new to databases, so apologies for any mistakes.

4

1 回答 1

0

The relation between Sequence and Process is one to one, the relation between Sequence and Task also is one to one (and the same with every other table which uses your sequence table in that way). The one side of this relation (Process resp. Task) don't need to exist.

The relation between Process and Task is one to many.

Your insert will be like

insert into Sequence values (0);
insert into Process values (last_insert_id(), ....);

insert into Sequence values (0);
insert into Task values (last_insert_id(), ....);

By the way, in your data model the table Process has two primary keys now. It might be a better data model when you use the process's sequence as a foreign key in Task.

于 2013-05-03T06:50:36.993 回答