创建表时是否可以使用全局变量?

发布于 2025-01-23 23:27:23 字数 500 浏览 2 评论 0原文

我正在尝试创建一个表:

CREATE TABLE `Appointment_Status` (
    `StatusID` VARCHAR(36) NOT NULL UNIQUE,
    `AppointmentFulfilled` ENUM('fulfilled', 'noshow', 'cancelled')
);

是否可以在最高级别上定义这样的全局变量:

SET GLOBAL AppointmentFulfilled = ENUM('fulfilled', 'noshow', 'cancelled');

创建表时使用它?像这样:

CREATE TABLE `Appointment_Status` (
    `StatusID` VARCHAR(36) NOT NULL UNIQUE,
    `AppointmentFulfilled` AppointmentFulfilled 
);

I'm trying to create a table:

CREATE TABLE `Appointment_Status` (
    `StatusID` VARCHAR(36) NOT NULL UNIQUE,
    `AppointmentFulfilled` ENUM('fulfilled', 'noshow', 'cancelled')
);

Is it possible to define a global variable like this on the very top level:

SET GLOBAL AppointmentFulfilled = ENUM('fulfilled', 'noshow', 'cancelled');

And use it when creating a table? Like this:

CREATE TABLE `Appointment_Status` (
    `StatusID` VARCHAR(36) NOT NULL UNIQUE,
    `AppointmentFulfilled` AppointmentFulfilled 
);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2025-01-30 23:27:23

MySQL不支持用户定义的类型(UDTS),但是您可以将检查约束放在timperment_status表上,该表将在此处瞄准您的效果。例如,

CREATE TABLE `Appointment_Status` (
    `StatusID` VARCHAR(36) NOT NULL UNIQUE,
    `AppointmentFulfilled` VARCHAR(9) CHECK (AppointmentFulfilled IN ('fulfilled','noshow','cancelled')) 
);

https://www.w3resource.com/ mysql/create-table-advance/constraint.php#cons3

MySQL does not support User Defined Types (UDTs), however you can put a CHECK constraint onto your Appointment_Status table that will have the effect you are aiming for here. E.g.

CREATE TABLE `Appointment_Status` (
    `StatusID` VARCHAR(36) NOT NULL UNIQUE,
    `AppointmentFulfilled` VARCHAR(9) CHECK (AppointmentFulfilled IN ('fulfilled','noshow','cancelled')) 
);

Full details at https://www.w3resource.com/mysql/creating-table-advance/constraint.php#cons3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文