SQL Create Database

Learn how to create a database in SQL and understand its structure and commands.

Overview

A database is a structured set of data stored in a computer. In SQL, you can create a database using the CREATE DATABASE statement. This command establishes a new database that can be populated with tables and other database objects.

Creating a Database

To create a new database, use the following syntax:

CREATE DATABASE database_name;

Here, database_name is the name you want to assign to your new database. Make sure to follow the naming conventions for databases.

Example:

CREATE DATABASE my_database;

This command creates a new database called my_database.

Using the Database

After creating a database, you can start using it by selecting it with the USE statement:

USE my_database;

This command sets my_database as the active database for subsequent operations.

Checking Existing Databases

You can check existing databases using the following command:

SHOW DATABASES;

This command lists all the databases in the current MySQL server.

Example Scenario

Suppose you are building a library management system. You can create a database to store all related information:

CREATE DATABASE library_management;
USE library_management;

You can now proceed to create tables within this database to manage books, authors, and members.

Conclusion

Creating a database in SQL is a straightforward process that lays the foundation for organizing and managing data. The CREATE DATABASE command is essential for setting up new databases for various applications.