SQL - SELECT Database, USE Statement

1 August 2025

The SQL USE DATABASE Statement – Choose Your Realm 🚪✨

To dance with the data, you first need to pick a partner – or in SQL terms, a database. The SQL USE DATABASE statement is your backstage pass to select the database where all the action happens.

Syntax Spotlight:

USE DatabaseName;

Here, DatabaseName is your ticket to a world of tables, records, and data-driven adventures. Every database is a unique universe within the RDBMS.


Step-by-Step Enchantment:

Creation Magic:

CREATE DATABASE testDB;


CREATE DATABASE testDB;

1. Check the Guest List:
SHOW DATABASES;

Behold the list:Copy code
Database

master

performance_schema

information_schema

mysql

testDB

2. Let the Switch Begin:

USE testDB;

3. Hear that? "Database changed" – you're now in the magical realm of testDB.
Create a Table Spell:


CREATE TABLE CALENDAR(MONTHS DATE NOT NULL);

4.Insert Magic Moments:

INSERT INTO CALENDAR(MONTHS) 
VALUES('2023-01-01');

INSERT INTO CALENDAR(MONTHS) VALUES('2023-02-01');

5.Reveal the Enchantment:

SELECT * FROM CALENDAR;

And voila! The output sparkles with magical months:
yamlCopy code
MONTHS

2023-01-01

2023-02-01

6. Caution – The Unknown Realm:

Beware! Trying to enter a non-existent database is like searching for Narnia in your closet – it doesn't end well.
USE unknownDatabase;
And the SQL oracle says:

ERROR 1049 (42000): Unknown database 'unknownDatabase'


It's a magical journey, but you need a real portal. No shortcuts here!So, there you have it – the SQL USE DATABASE statement, your gateway to realms of data wonders. Choose wisely, and may your queries be ever efficient! 🚪✨

Sajan Tonge
 Founder & CEO

My analytics School