Use of CREATE DATABASE Statement in SQL

Use of CREATE DATABASE Statement in SQL:

(1) “CREATE DATABASE” statement is used for creating a new database.

(2) Syntax of “CREATE DATABASE” statement is:

CREATE DATABASE databasename;
CREATE DATABASE databasename ON PRIMARY (Name =
N’Databasename_Data’,FILENAME= N’Pathe’)
LOG ON (Name = N’Databasename_Log’,FILENAME= N’Pathe’);

(3) Let’s create two databases in the below examples. One is created in by default path and the second one is created in the specified path.

(4) Select the database in the SQL server and click on the “New Query” button as shown.

click for new query in sql

(5) After that new query editor open as shown.

SQL new query editor open

(6) After doing the above steps, write a query in the editor, as shown.

query for create database statement in sql

Source Code:

–// Create database with system by default path
CREATE DATABASE [Create_First_Data_Bydefault_Path]
–// Create database with system by default path

–// Create database with specified path
CREATE DATABASE [Create_First_Data_WithSpecified_Path] ON PRIMARY
( NAME = N’Create_First_Data’, FILENAME = N’F:\Create First Database\Create_First_Data.mdf’)
LOG ON
( NAME = N’Create_First_Log’, FILENAME = N’F:\Create First Database\Create_First_Log.ldf’)
–// Create database with specified path

(7) After writing the query, then execute the query (Shortcut keys is F5) as shown.

execute the query for create database statement

(8) After executing the two queries in the same editor, SQL creates databases according to the SQL query as shown below. Note: Recommended write and execute query one by one for reporting.

Database Created by Using Create Database Statement

How to Create New Database in Microsoft SQL Server
How to Install SQL Management Studio
Microsoft D365 Business Central Process Flow
Use of SETRANGE and SETFILTER in Dynamics 365
Getting Started with AL– Microsoft Docs

Leave a Reply