In this guide, we will explain how to use the MySQL DATABASE function with syntax and examples.
Description
The DATABASE function returns the name of the default database.
Syntax
The syntax for the DATABASE function is:
DATABASE( )
Parameters or Arguments
There are no parameters or arguments for the DATABASE function.
Note
- The DATABASE function uses the utf8 character set, as of MySQL 4.1.
- The DATABASE function will return NULL, if there is no default database (Starting in MySQL 4.1.1).
- The DATABASE function will return an empty string, if there is no default database (Prior to MySQL 4.1.1).
Applies To
The DATABASE function can be used in the following versions :
- MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23
Example
Let’s look at some DATABASE function examples and explore how to use the DATABASE function.
For example:
mysql> SELECT DATABASE(); Result: 'quotations'
This DATABASE function example would return the name of the default database. So if our default database was called quotations, this example would return the string ‘quotations’.
Next Topic : Click Here
Pingback: MySQL: CURRENT_USER Function | Adglob Infosystem Pvt Ltd