MariaDB SCHEMA() Function

In MariaDB, SCHEMA() is a built-in function that returns the current database name as a string.

It is a synonym for DATABASE().

MariaDB SCHEMA() Syntax

Here is the syntax of the MariaDB SCHEMA() function:

SCHEMA()

Parameters

The MariaDB SCHEMA() function do not require any parameters.

Return value

The MariaDB SCHEMA() function returns a UTF8 string which is the current database name.

If no database has been selected, the SCHEMA() function will return NULL.

MariaDB SCHEMA() Examples

If you have just connected to the MySQL server and have not selected a database, the SCHEMA() function will return NULL.

SELECT SCHEMA();

Output:

+----------+
| SCHEMA() |
+----------+
| NULL     |
+----------+

Then, you use the USE statement to select testdb as the default database:

USE testdb;

Now, use the SCHEMA() function to get the current database:

SELECT SCHEMA();

Output:

+----------+
| SCHEMA() |
+----------+
| testdb   |
+----------+

Conclusion

In MariaDB, SCHEMA() is a built-in function that returns the current database name as a string.