使用UUID生成列ID时如何插入表?
我用centreid
定义为uuid:
CREATE TABLE `Centres` (
`CentreID` VARCHAR(36) NOT NULL UNIQUE,
`CentreName` VARCHAR(45),
`Address1` VARCHAR(45),
`Address2` VARCHAR(45),
`City` VARCHAR(45),
CONSTRAINT `PK_Centres` PRIMARY KEY (`CentreID`)
);
INSERT INTO Centres VALUES(UUID(), 'my centre', 'address1', NULL, 'London');
它创建centreid
作为CCDD2852-B9DE-11EC-A791-F4EE08B2B85A
。
现在,我想将另一个表“开放时间”创建,centreid
作为其列之一。
CREATE TABLE `OpeningTime` (
`OpeningTimeID` VARCHAR(36) NOT NULL UNIQUE,
`Centres_CentreID` VARCHAR(36)
);
插入数据时,我应该只做:
INSERT INTO OpeningTime VALUES(UUID(), 'ccdd2852-b9de-11ec-a791-f4ee08b2b85a');
还是有更好的方法可以在没有长varchar的情况下插入UUID?
I created a table "Centres" with CentreID
defined as UUID:
CREATE TABLE `Centres` (
`CentreID` VARCHAR(36) NOT NULL UNIQUE,
`CentreName` VARCHAR(45),
`Address1` VARCHAR(45),
`Address2` VARCHAR(45),
`City` VARCHAR(45),
CONSTRAINT `PK_Centres` PRIMARY KEY (`CentreID`)
);
INSERT INTO Centres VALUES(UUID(), 'my centre', 'address1', NULL, 'London');
It created CentreID
as ccdd2852-b9de-11ec-a791-f4ee08b2b85a
.
Now I'd like to create another table "OpeningTime", with CentreID
as one of its columns.
CREATE TABLE `OpeningTime` (
`OpeningTimeID` VARCHAR(36) NOT NULL UNIQUE,
`Centres_CentreID` VARCHAR(36)
);
When inserting data, should I just do:
INSERT INTO OpeningTime VALUES(UUID(), 'ccdd2852-b9de-11ec-a791-f4ee08b2b85a');
Or is there a better way to insert the UUID without the long VARCHAR?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
或者是否有更好的方法来插入没有长 VARCHAR 的 UUID,另一种方法是插入..选择..其中中心名称已知且唯一。
Or is there a better way to insert the UUID without the long VARCHAR, ANOTHER way would be insert..select..where centre name is known and unique.