Mysql-所有表的单个序列表 [英] Mysql- Single Sequence Table for all Tables

查看:86
本文介绍了Mysql-所有表的单个序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从Firebird数据库在Mysql中创建了一个数据库。
数据库中有一个公共序列表(Common_ID),它为所有表(数据库中的45个表)生成序列。某些表是

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)

此数据库已经有600,000条记录。
一个进程可以有多个任务。
我的问题是:
序列表和过程/任务表之间应该是什么关系?
流程表和任务表之间应该有什么关系?
如何在序列表中插入并在其他表中使用该 ID?

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.

推荐答案

Sequence和Process之间的关系是一对一的,Sequence和Task之间的关系也是一对一的(并且与其他所有以这种方式使用序列表的表相同)。

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.

Process与Task之间的关系是一对多的。

The relation between Process and Task is one to many.

您的插入内容将类似于

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

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

顺便说一句,在您的数据模型中,表Process现在有两个主键。当您将流程的序列用作Task中的外键时,它可能是一个更好的数据模型。

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.

这篇关于Mysql-所有表的单个序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆