©SQL :: Manager
HomeProgram InformationTechnical detailsFree downloadDonate for a cup of coffee
myway SQL Manager for MySQL and MariaDB, Download on Uptodown
SQL functionMySQLMariaDB

The SCHEMA SQL Function in MySQL and MariaDB - Name of current database

SCHEMASyntax:SCHEMA()
Return value:CHAR
Synonyms:DATABASE
Function type:Information function
Function Description

The SCHEMA() function returns the current database name as a string.

Within stored routines, the default database is the database associated with the routine.

A database can be selected with the USE statement.

If no default database is defined, the SCHEMA() function returns NULL.

SQL Examples for the SCHEMA function

 1
 2
 3
 4
 5
 6
 7
 8
 9

SELECT schema();

use test;
SELECT schema();

use information_schema;
SELECT schema();

schema()
varchar(34) BINARY
NULL
schema()
varchar(34) BINARY
test
schema()
varchar(34) BINARY
information_schema
The examples were created with the MyWAY SQL manager: Download

How to use the SCHEMA() function in MySQL and MariaDB databases

The SCHEMA() function in MySQL and MariaDB is used to retrieve the name of the currently used database. The function can be used directly in a SQL statement or within a SQL query, requires no arguments, and returns a string representing the name of the current database.

The SCHEMA() function can be used to get the current database name within a query or procedure, for example to switch between databases or to reference objects in the current database. The function can be used to organize queries or statements based on the current database, for example, different queries can be executed or different logic can be applied depending on the database context. When creating dynamic SQL statements, the function is useful to include the current database name in the generated SQL code, allowing for more flexible and dynamic queries that adapt to the current database context.
RPADRPAD_ORACLERTRIMSCHEMASEC_TO_TIMESECONDSESSION_USER

Further MySQL und MariaDB SQL Information functions

BENCHMARKBENCHMARK(Number, Expression)
More about BENCHMARK Function

BINLOG_GTID_POSBINLOG_GTID_POS()

CHARSETCHARSET(String)
More about CHARSET Function

COERCIBILITYCOERCIBILITY(String)
More about COERCIBILITY Function

COLLATIONCOLLATION(String)
More about COLLATION Function

CONNECTION_IDCONNECTION_ID()
More about CONNECTION_ID Function

CURRENT_USERCURRENT_USER()
More about CURRENT_USER Function

CURRENT_ROLECURRENT_ROLE()
More about CURRENT_ROLE Function

DATABASEDATABASE()
More about DATABASE Function

DECODE_HISTOGRAMDECODE_HISTOGRAM()

DEFAULTDEFAULT(Column)
More about DEFAULT Function

FOUND_ROWSFOUND_ROWS()
More about FOUND_ROWS Function

LAST_INSERT_IDLAST_INSERT_ID([Expression])
More about LAST_INSERT_ID Function

LAST_VALUELAST_VALUE(Expression [, Expression ...])
More about LAST_VALUE Function

ROWNUMROWNUM()

ROW_COUNTROW_COUNT()
More about ROW_COUNT Function

SESSION_USERSESSION_USER()
More about SESSION_USER Function

SYSTEM_USERSYSTEM_USER()
More about SYSTEM_USER Function

USERUSER()
More about USER Function

VERSIONVERSION()
More about VERSION Function

Numeric functionsString functionsRegular ExpressionsDate and Time functions
Comparison functionsEncryption & CompressionConversion functionsNULL functions
Aggregate functionsWindow functionsJSON functionsGeometric functions
Sequence functionsInformation functionsDynamic ColumnsMiscellaneous functions
More information about the SCHEMA SQL function: mysql.com and mariadb.com
Updated: 2023-09-17ImprintContactTerms & conditionsPrivacy & CookiesUpdatesSitemapFacebookLinkedinTwitterStatistics©2020-2024 Heino Cunze-Fischer