【发布时间】:2012-03-08 22:56:47
【问题描述】:
我想弄清楚如何做一个有 3 列的表格:
unique_id, type, version
其中 unique_id 是每个记录的 AUTO_INCREMENT,版本是每个类型的 AUTO_INCREMENT。
目的是,当我插入时,我只需要指定“类型”,并且会自动生成 unique_id 和 version_id。例如:
insert type 'a', then values are: 1 , a , 1
insert type 'a', then values are: 2 , a , 2
insert type 'a', then values are: 3 , a , 3
insert type 'b', then values are: 4 , b , 1
insert type 'b', then values are: 5 , b , 2
insert type 'a', then values are: 6 , a , 4
还可以公平地说,这样的设置并没有真正标准化吗?而是应该是两张表?
【问题讨论】:
-
这不是版本的自动递增,因为它不会在每次插入时递增。您正在谈论触发存储过程的触发器。它可以作为子表完成,在这种情况下,版本将不在此表中,而是在子表中。尽管如此,它仍然不会自动增加版本。
标签: mysql auto-increment