【发布时间】:2020-09-09 08:01:38
【问题描述】:
如标题所述。我确实有下表:
CREATE TABLE exampleTable(
ID int NOT NULL,
Text varchar(255),
PRIMARY KEY (ID)
);
通过插入值:
INSERT INTO exampleTable (ID, Text)
VALUES (123, 'Hello World');
有时可以为表中已存在的主键添加值,从而为您提供Error。
问题:
我们可以通过哪种方法确保所选主键的值始终是唯一的?
如何生成始终唯一的主键值。
对于 2. 问题,可能的方法:
//Check if the new Value is already in the Table by
//Iterating and comparing through all the Primary Key Values.
【问题讨论】:
-
这是家庭作业吗?我想不出另一个不使用自动增量的理由。
-
嘿,该表没有设置 auto_increment。有没有其他办法?
标签: mysql sql datatable primary-key