arrow-left

All pages
gitbookPowered by GitBook
1 of 1

Loading...

DATABASE

Return the default database name. This function outputs the name of the currently selected database for the session.

hashtag
Syntax

DATABASE()
SCHEMA()

hashtag
Description

Returns the default (current) database name as a string in the utf8 character set. If there is no default database, DATABASE() returns NULL. Within a , 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.

SCHEMA() is a synonym for DATABASE().

To select a default database, the statement can be run. Another way to set the default database is specifying its name at command line client startup.

hashtag
Examples

This page is licensed: GPLv2, originally from

SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| NULL       |
+------------+

USE test;
Database changed

SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| test       |
+------------+
stored routine
USE
mariadb
fill_help_tables.sqlarrow-up-right
spinner