MySQL SCHEMA() Function
The MySQL SCHEMA() function returns the current database name as a string. This function is equivalent to the DATABASE() function.
SCHEMA() Syntax
Here is the syntax of the MySQL SCHEMA() function:
SCHEMA()
Parameters
The MySQL SCHEMA() function does not require any parameters.
Return value
The SCHEMA() function returns a UTF8 string, which is the current database name.
If you have not selected a database, the SCHEMA() function will return NULL.
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();
+------------+
| SCHEMA() |
+------------+
| NULL |
+------------+Then, we use USE statement to select testdb as the default database:
USE testdb;
Now, let’s use the SCHEMA() function get the current database:
SELECT SCHEMA();
+------------+
| SCHEMA() |
+------------+
| testdb |
+------------+