
UDF's.

CREATE TABLE account_ledger (
	id INT PRIMARY KEY AUTO_INCREMENT,
	transaction_name VARCHAR(100),
	credit_account VARCHAR(100),
	credit_amount INT,
	debit_account VARCHAR(100),
	debit_amount INT);

ALTER TABLE account_ledger 
ADD CONSTRAINT is_balanced 
  CHECK((debit_amount + credit_amount) = 0);

The constraint_name is optional. If you don't provide one in the ALTER TABLE
statement, MariaDB auto-generates a name for you. This is done so that you can
remove it later using DROP CONSTRAINT clause.

You can disable all constraint expression checks by setting the variable
check_constraint_checks to OFF. You may find this useful when loading a table
that violates some constraints that you want to later find and fix in SQL.

To view constraints on a table, query information_schema.TABLE_CONSTRAINTS:

SELECT CONSTRAINT_NAME, TABLE_NAME, CONSTRAINT_TYPE 
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_NAME = 'account_ledger';

+-----------------+----------------+-----------------+
| CONSTRAINT_NAME | TABLE_NAME     | CONSTRAINT_TYPE |
+-----------------+----------------+-----------------+
| is_balanced     | account_ledger | CHECK           |
+-----------------+----------------+-----------------+

DROP CONSTRAINT
---------------

MariaDB starting with 10.2.22
-----------------------------
DROP CONSTRAINT for UNIQUE and FOREIGN KEY constraints was introduced in
MariaDB 10.2.22 and MariaDB 10.3.13.

MariaDB starting with 10.2.1
----------------------------
DROP CONSTRAINT for CHECK constraints was introduced in MariaDB 10.2.1

Modifies the table, removing the given constraint.

ALTER TABLE table_name
DROP CONSTRAINT constraint_name;

When you add a constraint to a table, whether through a CREATE TABLE or ALTER
TABLE...ADD CONSTRAINT statement, you can either set a constraint_name
yourself, or allow MariaDB to auto-generate one for you. To view constraints
on a table, query information_schema.TABLE_CONSTRAINTS. For instance,

CREATE TABLE t (
 a INT,
 b INT,
 c INT,
 CONSTRAINT CHECK(a > b),
 CONSTRAINT check_equals CHECK(a = c));

SELECT CONSTRAINT_NAME, TABLE_NAME, CONSTRAINT_TYPE 
FROM information_schema.TABLE_CONSTRAINTS
WHERE TABLE_NAME = 't';

+-----------------+----------------+-----------------+
| CONSTRAINT_NAME | TABLE_NAME     | CONSTRAINT_TYPE |
+-----------------+----------------+-----------------+
| check_equals    | t              | CHECK           |
| CONSTRAINT_1    | t              | CHECK           |
+-----------------+----------------+-----------------+

To remove a constraint from the table, issue an ALTER TABLE...DROP CONSTRAINT
statement. For example,

ALTER TABLE t DROP CONSTRAINT is_unique;

ADD SYSTEM VERSIONING
---------------------

MariaDB starting with 10.3.4
----------------------------
System-versioned tables was added in MariaDB 10.3.4.

Add system versioning.

DROP SYSTEM VERSIONING
----------------------

MariaDB starting with 10.3.4
----------------------------
System-versioned tables was added in MariaDB 10.3.4.

Drop system versioning.

ADD PERIOD FOR SYSTEM_TIME
--------------------------

MariaDB starting with 10.3.4
----------------------------
System-versioned tables was added in MariaDB 10.3.4.

FORCE
-----

ALTER TABLE ... FORCE can force MariaDB to re-build the table.

In MariaDB 5.5 and before, this could only be done by setting the ENGINE table
option to its old value. For example, for an InnoDB table, one could execute
the following:

ALTER TABLE tab_name ENGINE = InnoDB;

The FORCE option can be used instead. For example, :

ALTER TABLE tab_name FORCE;

With InnoDB, the table rebuild will only reclaim unused space (i.e. the space
previously used for deleted rows) if the innodb_file_per_table system variable
is set to ON (the default). If the system variable is OFF, then the space will
not be reclaimed, but it will be-re-used for new data that's later added.

EXCHANGE PARTITION
------------------

This is used to exchange the contents of a partition with another table.

This is performed by swapping the tablespaces of the partition with the other
table.

See copying InnoDB's transportable tablespaces for more information.

DISCARD TABLESPACE
------------------

This is used to discard an InnoDB table's tablespace.

See copying InnoDB's transportable tablespaces for more information.

IMPORT TABLESPACE
-----------------

This is used to import an InnoDB table's tablespace. The tablespace should
have been copied from its original server after executing FLUSH TABLES FOR
EXPORT.

See copying InnoDB's transportable tablespaces for more information.

ALTER TABLE ... IMPORT only applies to InnoDB tables. Most other popular
storage engines, such as Aria and MyISAM, will recognize their data files as
soon as they've been placed in the proper directory under the datadir, and no
special DDL is required to import them.

ALGORITHM
---------

The ALTER TABLE statement supports the ALGORITHM clause. This clause is one of
the clauses that is used to implement online DDL. ALTER TABLE supports several
different algorithms. An algorithm can be explicitly chosen for an ALTER TABLE
operation by setting the ALGORITHM clause. The supported values are:

* ALGORITHM=DEFAULT - This implies the default behavior for the specific
statement, such as if no ALGORITHM clause is specified.
* ALGORITHM=COPY
* ALGORITHM=INPLACE
* ALGORITHM=NOCOPY - This was added in MariaDB 10.3.7.