In this SQL Server tutorial, I will show you how to create a database in SQL server using query.
You will understand the syntax to create a database in SQL Server. Also, you will learn about where to execute SQL Query on SQL Server Management Studio. Finally, you will create a database with examples.
Create Database in SQL Server Using Query
To create a database in SQL Server using a query, you can use the SQL Server Management Studio (SSMS), which means you can also run the query in SQL Server Management Studio that you run on the command line.
Create Database in SQL Server Using Query on SSMS
Open SQL Server Management Studio and connect to SQL Server instance. To run the query, SQL Server provides a Query window where you can execute the SQL server query to interact with databases.
There are different ways to open the New Query window in SQL Server. The simplest way is to press ‘CTRL + N’ from your keyboard, and it opens the New Query window.
Other ways are shown in the below picture.
In the above picture, you can select the New Query option from the toolbar of SSMS or select your SQL Server instance, right-click on it, and then select the New Query from the options.
When you follow any of the ways to open New Query, you see the Query Editor window area, as shown in the below picture.
To create a database in SQL Server using a query, you need to follow the below syntax:
CREATE DATABASE new_database_name;
- CREATE DATABASE: It is the command to create a new database on SQL Server.
- new_database_name: The name of the database that you want to create; remember to always follow best practices while specifying the database name.
Now go to your Query Editor area and write the below query to create a database named ‘Products’.
CREATE DATABASE Products;
To execute the query ‘CREATE DATABASE PRODUCTS’, click on the Execute button as shown in the above picture or just press F5 from your keyboard.
As soon as you execute the query, it shows a message ‘Commands completed successfully’, which means the database is created in SQL Server as shown in the below picture.
To check the created database ‘Products’, expand the Database node from the Object Explorer panel, and you will see the newly created database as shown in the below picture.
If you don’t see the newly created database, then refresh the Object Explorer by clicking on the reload icon, as shown in the above picture.
In this SQL Server tutorial, you learn how to create a database using a query in SQL Server Management Studio.
You may also like:
- How to Create a Database in SQL Server Management Studio?
- How to Create a Database in SQL Server Using Command Line?
- How to Change Database Owner in SQL Server?
- How to Check Database Size in SQL Server Using Query?
- How to Check Database Log File Size in SQL Server Using Query?
After working for more than 15 years in the Software field, especially in Microsoft technologies, I have decided to share my expert knowledge of SQL Server. Check out all the SQL Server and related database tutorials I have shared here. Most of the readers are from countries like the United States of America, the United Kingdom, New Zealand, Australia, Canada, etc. I am also a Microsoft MVP. Check out more here.