100 Days of SQL

sql

Day 28 – SQL CREATE DATABASE

SQL CREATE DATABASE statement is used to create a new database in a SQL Server instance. The syntax for the CREATE DATABASE statement is as follows:


CREATE DATABASE database_name;

In this syntax, “database_name” is the name of the new database that you want to create.

Here’s an example of how to create a new database named “my_database”:


CREATE DATABASE my_database;

When this statement is executed, SQL Server will create a new database named “my_database” in the default location configured for the SQL Server instance.

You can also specify additional options when creating a new database, such as specifying the location of the database files, the default collation, and other database-level settings. Here’s an example that shows some additional options:


CREATE DATABASE my_database
ON
( NAME = my_database_data, FILENAME = 'C:\\SQLData\\my_database_data.mdf'),
( NAME = my_database_log, FILENAME = 'C:\\SQLLogs\\my_database_log.ldf')
COLLATE SQL_Latin1_General_CP1_CI_AS;

In this example, we create a new database named “my_database” and specify the file locations for the primary data and log files. We also specify the collation for the database to be “SQL_Latin1_General_CP1_CI_AS”.