SQL CREATE DATABASE
Creating a database is the first step to start storing your data. The CREATE DATABASE
command creates a new, empty database in your SQL server.
🔹 Basic Syntax
CREATE DATABASE database_name;
- Replace
database_name
with your desired database name. - The database name must be unique on your server.
🔹 Examples
CREATE DATABASE sales_db;
Creates a database named sales_db
.
🔹 Notes by DBMS
- In MySQL, you can specify charset and collation:
CREATE DATABASE sales_db
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
- In SQL Server, optional options include specifying file locations:
CREATE DATABASE sales_db
ON PRIMARY (
NAME = sales_db_data,
FILENAME = 'C:\\data\\sales_db_data.mdf',
SIZE = 10MB,
MAXSIZE = 100MB,
FILEGROWTH = 5MB
)
LOG ON (
NAME = sales_db_log,
FILENAME = 'C:\\data\\sales_db_log.ldf',
SIZE = 5MB,
MAXSIZE = 50MB,
FILEGROWTH = 5MB
);
- In Oracle, creating a database is a more complex process usually handled by DBAs, involving creating a database instance and data files.
🧠 Quick Recap
Key Point | Explanation |
---|---|
Command | CREATE DATABASE database_name; |
Purpose | Creates a new empty database |
DBMS Variations | Charset, collation, file options |
💡 Once created, you connect to this database to create tables and store data.
🔜 Next: SQL DROP DATABASE