且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在mysql中使用自动增量创建自定义序列ID

更新时间:2022-02-07 22:33:07

I我认为这是一个坏主意。这种逻辑会给数据库设计和编程带来不必要的复杂性,如何使用数据库。这有什么好处?



例如,如果你有项目1和11,并且他们有任务11和1,那么会发生什么。这两个任务的关键值都是111.如何处理这种情况...



我建议使用纯代理键。查询并从每个表中获取所有相关数据时,您始终可以加入表。
In my opinion this would be a bad idea. This logic wuold introduce unnecessary complexity to the databsae design and to the programming, how the data base is used. What would be the benefit of this?

For example consider what happens if you have projects 1 and 11 and they have tasks 11 and 1 correspodingly. Both these tasks would have a key value of 111. How to handle this situation...

I would suggest using pure surrogate keys. You can always join the tables when querying and fetch all the relevant data from each table.