Search⌘ K
AI Features

Enumerations in Computational Languages

Understand how enumerations are defined and used in different computational languages like JavaScript, SQL, and XML Schema. Learn to implement enumerations as objects in JavaScript with constant properties and how to validate enumeration attributes effectively.

Enumerations in SQL

Unfortunately, standard SQL does not support enumerations. Some DBMS, such as MySQL and Postgres, provide their own extensions of SQL column definitions in the CREATE TABLE statement that define enumeration-valued columns.

A MySQL enumeration is specified as a list of enumeration labels with the keyword ENUM within a column definition, as shown below:

MySQL
CREATE TABLE people (
name VARCHAR(40),
gender ENUM('MALE', 'FEMALE', 'UNDETERMINED')
);

A Postgres enumeration is specified as a special user-defined type that can be used in column definitions:

MySQL
CREATE TYPE GenderEL AS ENUM ('MALE', 'FEMALE', 'UNDETERMINED');
CREATE TABLE people (
name text,
gender GenderEL
)

Enumerations in XML schema

In XML Schema, an enumeration ...