In MariaDB, the SCHEMA()
function is a synonym for the DATABASE()
function. It returns the default (current) database name.
The result is returned as a string in the utf8
character set.
Syntax
The syntax goes like this:
SCHEMA()
No arguments are required or accepted.
Example
Here’s an example to demonstrate:
SELECT SCHEMA();
Here’s the result in my terminal window:
MariaDB [(none)]> SELECT SCHEMA(); +----------+ | SCHEMA() | +----------+ | NULL | +----------+
In this case I don’t have a current database and so the result is NULL
.
Let’s switch to a database:
USE Zap;
And run it again:
SELECT SCHEMA();
Result:
MariaDB [Zap]> SELECT SCHEMA(); +----------+ | SCHEMA() | +----------+ | Zap | +----------+
No Arguments are Accepted
Passing any arguments to SCHEMA()
results in an error:
SELECT SCHEMA(123);
Result:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '123)' at line 1
Stored Routines
Within a stored routine (such as a stored procedure, stored function, etc), the default database is the database that the routine is associated with, which is not necessarily the same as the database that is the default in the calling context