Mysql
 SQL >> Database >  >> RDS >> Mysql

Usare DATABASE() per ottenere il nome del database MySQL corrente

La funzione integrata DATABASE() di MySQL restituisce il database attualmente impostato come predefinito per la sessione.

Il nome viene restituito come stringa nel set di caratteri utf8. Se non è stato selezionato alcun database, restituisce NULL.

Sintassi

DATABASE()

Non accetta argomenti.

Esempio

SELECT DATABASE();

Risultato senza database selezionato: NULL.

USE sakila;
SELECT DATABASE();

Risultato: sakila.

Stored routine

In una stored routine, il database predefinito è quello associato alla routine.

Sinonimo

SCHEMA() è un sinonimo di DATABASE().