According to the sql standard the following is valid command:
CREATE TABLE Table_1 (
|
column_1 SMALLINT
|
CONSTRAINT constraint_1 CHECK(column_1<400),
|
column_2 CHAR(5));
|
Oracle grammar examples indicate the same:
CREATE TABLE employees_demo
|
( employee_id NUMBER(6)
|
, first_name VARCHAR2(20)
|
, last_name VARCHAR2(25)
|
CONSTRAINT emp_last_name_nn_demo NOT NULL
|
, email VARCHAR2(25)
|
CONSTRAINT emp_email_nn_demo NOT NULL
|
...
|
But both 10.2.6 and 10.3.0 show syntax error:
mysql> CREATE TABLE Table_1 (
|
-> column_1 SMALLINT
|
-> CONSTRAINT constraint_1 CHECK(column_1<400),
|
-> column_2 CHAR(5));
|
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CONSTRAINT constraint_1 CHECK(column_1<400),
|
column_2 CHAR(5))' at line 3
|
- relates to
-
MDEV-7563
Support CHECK constraint as in (or close to) SQL Standard
-
-
Closed
{"report":{"fcp":3342.7999999523163,"ttfb":733.5999999046326,"pageVisibility":"visible","entityId":61493,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"ba49f3df-f58c-440f-9c9a-b4540326fb0d","navigationType":0,"readyForUser":2408.2000000476837,"redirectCount":0,"resourceLoadedEnd":3987.4000000953674,"resourceLoadedStart":1022.9000000953674,"resourceTiming":[{"duration":360.7999999523163,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":1022.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1022.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1383.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":530.2999999523163,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1023.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1023.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1553.5,"responseStart":0,"secureConnectionStart":0},{"duration":539.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":1023.4000000953674,"connectEnd":1023.4000000953674,"connectStart":1023.4000000953674,"domainLookupEnd":1023.4000000953674,"domainLookupStart":1023.4000000953674,"fetchStart":1023.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1023.4000000953674,"responseEnd":1563.0999999046326,"responseStart":1563.0999999046326,"secureConnectionStart":1023.4000000953674},{"duration":657.4000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":1023.5999999046326,"connectEnd":1023.5999999046326,"connectStart":1023.5999999046326,"domainLookupEnd":1023.5999999046326,"domainLookupStart":1023.5999999046326,"fetchStart":1023.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1023.5999999046326,"responseEnd":1681,"responseStart":1681,"secureConnectionStart":1023.5999999046326},{"duration":794.8999998569489,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":1023.7000000476837,"connectEnd":1023.7000000476837,"connectStart":1023.7000000476837,"domainLookupEnd":1023.7000000476837,"domainLookupStart":1023.7000000476837,"fetchStart":1023.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":1023.7000000476837,"responseEnd":1818.5999999046326,"responseStart":1818.5999999046326,"secureConnectionStart":1023.7000000476837},{"duration":1034.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":1024,"connectEnd":1024,"connectStart":1024,"domainLookupEnd":1024,"domainLookupStart":1024,"fetchStart":1024,"redirectEnd":0,"redirectStart":0,"requestStart":1024,"responseEnd":2058.2999999523163,"responseStart":2058.2999999523163,"secureConnectionStart":1024},{"duration":1103.5999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":1024.2000000476837,"connectEnd":1024.2000000476837,"connectStart":1024.2000000476837,"domainLookupEnd":1024.2000000476837,"domainLookupStart":1024.2000000476837,"fetchStart":1024.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":1024.2000000476837,"responseEnd":2127.7999999523163,"responseStart":2127.7999999523163,"secureConnectionStart":1024.2000000476837},{"duration":1186.2000000476837,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":1024.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1024.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2210.5,"responseStart":0,"secureConnectionStart":0},{"duration":1181.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":1024.5,"connectEnd":1024.5,"connectStart":1024.5,"domainLookupEnd":1024.5,"domainLookupStart":1024.5,"fetchStart":1024.5,"redirectEnd":0,"redirectStart":0,"requestStart":1024.5,"responseEnd":2205.5999999046326,"responseStart":2205.5999999046326,"secureConnectionStart":1024.5},{"duration":1190.9000000953674,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":1024.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1024.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2215.5,"responseStart":0,"secureConnectionStart":0},{"duration":1181.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":1024.9000000953674,"connectEnd":1024.9000000953674,"connectStart":1024.9000000953674,"domainLookupEnd":1024.9000000953674,"domainLookupStart":1024.9000000953674,"fetchStart":1024.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1024.9000000953674,"responseEnd":2206.4000000953674,"responseStart":2206.4000000953674,"secureConnectionStart":1024.9000000953674},{"duration":2551.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":1025.7999999523163,"connectEnd":1025.7999999523163,"connectStart":1025.7999999523163,"domainLookupEnd":1025.7999999523163,"domainLookupStart":1025.7999999523163,"fetchStart":1025.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1025.7999999523163,"responseEnd":3577.0999999046326,"responseStart":3577.0999999046326,"secureConnectionStart":1025.7999999523163},{"duration":2626.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":1025.9000000953674,"connectEnd":1025.9000000953674,"connectStart":1025.9000000953674,"domainLookupEnd":1025.9000000953674,"domainLookupStart":1025.9000000953674,"fetchStart":1025.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1025.9000000953674,"responseEnd":3652.2000000476837,"responseStart":3652.2000000476837,"secureConnectionStart":1025.9000000953674},{"duration":1315.6000001430511,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1878.5999999046326,"connectEnd":1878.5999999046326,"connectStart":1878.5999999046326,"domainLookupEnd":1878.5999999046326,"domainLookupStart":1878.5999999046326,"fetchStart":1878.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1878.5999999046326,"responseEnd":3194.2000000476837,"responseStart":3194.2000000476837,"secureConnectionStart":1878.5999999046326},{"duration":1845,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":2274,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":2274,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":4119,"responseStart":0,"secureConnectionStart":0},{"duration":703.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":3283.5999999046326,"connectEnd":3283.5999999046326,"connectStart":3283.5999999046326,"domainLookupEnd":3283.5999999046326,"domainLookupStart":3283.5999999046326,"fetchStart":3283.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":3283.5999999046326,"responseEnd":3987.4000000953674,"responseStart":3987.4000000953674,"secureConnectionStart":3283.5999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":578,"responseStart":733,"responseEnd":1003,"domLoading":865,"domInteractive":4123,"domContentLoadedEventStart":4123,"domContentLoadedEventEnd":4188,"domComplete":4434,"loadEventStart":4434,"loadEventEnd":4434,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":4092.2000000476837},{"name":"bigPipe.sidebar-id.end","time":4093.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":4093.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":4095.7999999523163},{"name":"activityTabFullyLoaded","time":4215.599999904633}],"measures":[],"correlationId":"43c458b26ebecb","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":98,"dbReadsTimeInMs":10,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Please note that SQL-99 is not a MariaDB manual, it's the standard, of which MariaDB only implements a subset. Here is the documentation of the feature syntax in current MariaDB: https://mariadb.com/kb/en/mariadb/constraint/
You can either have CHECK(expression) as a part of a column definition, or CONSTRAINT [constraint_name] CHECK (expression). The latter goes outside the column definition; the page doesn't say that, it should probably be added as an explicit note; it is indeed not implemented as a part of a column definition, which the example in the description is about. [NOT] DEFERRABLE is not implemented either.
I've converted it into a task.