我在数据库中有几个表,假设它们被称为table1,table 2等. 所有表都有一个具有自动增量的主键列"id".
I've got several tables in a database, let's say they're called table1, table 2, etc. All tables have a primary key column 'id' with auto-increment.
在我当前的配置中,碰巧插入表1时,生成的ID为1. 然后,当插入table2时,生成的ID也恰好是1.
In my current configuration it happens that when inserting into table1, the generated id is 1. Afterwards when inserting into table2, the generated id happens to be 1 as well.
如何在数据库的所有表中强制使用绝对唯一的ID?我想在插入table1时生成的ID为1,然后再插入到table2中时生成的ID为2?
How to force absolutely unique ids across all tables in a database? I want when inserting into table1, generated id to be 1, and if afterwards inserting into table2, generated id be 2?
我在某些计算机上使用了mysql服务器,但没有出现此问题,但是当我在本地计算机上安装mysql时,它开始出现.所以我想这一定是某种适用于mysql配置的设置吗?
I used mysql server on some machine and did not have this problem, but when I installed mysql on my local machine, it started to occur. So I guess it must be some kind of a setting that is applied to the mysql configuration?
谢谢
推荐答案,您可以使用UUID.
you can use UUID.
INSERT INTO mytable(id, name) VALUES(SELECT UUID(), 'some data');了解有关UUID的更多信息: mysqlbackupnet .codeplex/wikipage?title =使用%20MySQL%20With%20GUID%20or%20UUID
Read more about UUID: mysqlbackupnet.codeplex/wikipage?title=Using%20MySQL%20With%20GUID%20or%20UUID
更多推荐
如何为多个表中的行实现唯一的自动递增的id?
发布评论