{"id":338,"date":"2021-01-22T12:00:00","date_gmt":"2021-01-22T17:00:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=338"},"modified":"2024-02-08T08:22:51","modified_gmt":"2024-02-08T13:22:51","slug":"mysql-column-enumeration-example","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/mysql-column-enumeration-example\/","title":{"rendered":"MySQL column enumeration example"},"content":{"rendered":"\n<p><strong>Problem<\/strong>:<\/p>\n\n\n\n<p>You are building a database and you have a field that can accept only certain responses. For example, there is a Gender column which accepts only M or F as values.<\/p>\n\n\n\n<p><strong>Solution<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Gender ENUM('M','F') not null<\/code><\/pre>\n\n\n\n<p>This means, the columns can take only one of the values explicitly listed in the column specification. Either F or M.<\/p>\n\n\n\n<p>ENUM allows you to specify a restricted set of values the column can hold.<\/p>\n\n\n\n<p>Multiple character values are also allowed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Gender ENUM('Male','Female') not null<\/code><\/pre>\n\n\n\n<p><strong>Complete Example:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a table:<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE Person (\n   Name VARCHAR(25) NOT NULL,\n   Gender ENUM('M','F') NOT NULL,\n   Id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY\n)<\/code><\/pre>\n\n\n\n<p>Insert a row:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO Person VALUES('John','M',NULL);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Problem: You are building a database and you have a field that can accept only certain responses. For example, there is a Gender column which accepts only M or F as values. Solution: This means, the columns can take only one of the values explicitly listed in the column specification. Either F or M. ENUM [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,204],"tags":[27],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-database","category-mysql","tag-mysql"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":339,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/338\/revisions\/339"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}