CREATE DATABASE statement in SQL

CREATE DATABASE is the basic and main statement to implement a database in SQL Server. As its name indicates, the CREATE DATABASE statement allows us to create a database in our SQL Server management system.

Next, we will see two examples of how to create a database in SQL Server, the first through the CREATE SQL statement and the next through SQL Server Management Studio (SSMS).

CREATE DATABASE

  1. Open the SQL Server Management Studio (SSMS), establish the connection with the server, and open a new Transact SQL editing screen. This will be opened by selecting the New Query option in the menu bar or by using the keyboard shortcut (Ctrl + N).

SQL edition window

  1. Write the CREATE DATABASE statement databaseName; and execute the statement from the Execute menu option or pressing the F5 key;
CREATE DATABASE store;

create database statement in SQL

The Messages window located below the statement will give us information about the result of the execution. If all went well, we can view our database from the menu on the left, in the Databases directory. To display the newly created database in the menu, we must first refresh at the Refresh icon in the connection menu bar or pressing F5.

It’s a good idea to get used to preselecting Transact SQL statements. This is necessary when we have written several sentences in the same edition window, so that the system is capable of discerning which one it should execute.

  1. It is important once our database is created, to place ourselves correctly in it so that the rest of the statements are executed in the database that we have created. From SQL commands, this is done using the USE statement databaseName;
USE store;

use database statement in SQL

We can also locate ourselves correctly in the desired database from the dropdown of the option highlighted in the image without needing a command.