As of today (Feb. 2020), a code like the following would be executed just fine on e.g. MariaDB (10.3.18-MariaDB-0+deb10u1
):
DROP SCHEMA IF EXISTS TABLE_TEST;
CREATE SCHEMA TABLE_TEST;
USE TABLE_TEST;
CREATE TABLE TABLE_TESTA(
id INT PRIMARY KEY
);
CREATE TABLE TABLE_TESTB(
fk INT REFERENCES TABLE_TESTA(id)
);
The syntax you would use would be
AttributeName AttributeType REFERENCES TableName(AttributeName)
inside a CREATE
statement.
BUT the foreign key would not be created.
You can see for yourself by executing
INSERT INTO TABLE_TESTB VALUES (2);
or even
SHOW CREATE TABLE TABLE_TESTB;
which returns
+-------------+--------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------------+--------------------------------------------------------------------------------------------------+
| TABLE_TESTB | CREATE TABLE `TABLE_TESTB` (
`fk` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 |
+-------------+--------------------------------------------------------------------------------------------------+
So, you can "declare" a foreign key inline, and it will be parsed, but it will not be enforced!
This is a bug that has been documented for a loooooong time but never addressed.