DB2支持枚举吗?

Tim*_*Tim 3 db2 enums enumeration

DB2支持枚举吗?我在网上找不到任何东西.查询不起作用:

create table prototype.test(id int not null primary key, level ENUM('upper', 'lower') not null);
Run Code Online (Sandbox Code Playgroud)

提前致谢!

Ang*_*ocA 8

您可以为此创建检查约束.

alter table prototype.test add constraint checklevel check (level in ('upper', 'lower'));
Run Code Online (Sandbox Code Playgroud)

或者您可以在create table中包含它:

create table prototype.test(
 id int not null primary key,
 level varchar(5) check (level in ('upper', 'lower')
);
Run Code Online (Sandbox Code Playgroud)


Rah*_*thi 5

没有DB2 不支持 ENUMS。我知道一些支持 Enums 的数据库是 MySql 和 Postgresql,但 DB2 肯定支持它。