SQL - How to create a Database

Creating a database in SQL involves using the `CREATE DATABASE` statement. Here’s the basic syntax:

“`sql
CREATE DATABASE database_name;
“`

Here’s an example:

“`sql
CREATE DATABASE EmployeeDB;
“`

This statement creates a new database named “EmployeeDB”.

However, depending on the database management system (DBMS) you’re using, there might be additional options or configurations available. For instance, in MySQL, you might specify the character set and collation for the database:

“`sql
CREATE DATABASE EmployeeDB
CHARACTER SET utf8mb4
COLLATE utf8mb4_unicode_ci;
“`

In SQL Server, you may need to set additional options such as file growth, file locations, etc.:

“`sql
CREATE DATABASE EmployeeDB
ON
(NAME = EmployeeDB_dat,
FILENAME = ‘C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\EmployeeDB.mdf’,
SIZE = 10MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 10%)
LOG ON
(NAME = EmployeeDB_log,
FILENAME = ‘C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\EmployeeDB.ldf’,
SIZE = 5MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 5MB);
“`

Always refer to the documentation specific to your DBMS for the complete list of options available when creating a database.

Scroll to Top
Skip to content