Get your business online with free website builder (en)

Create Database via query in SQL Server

Create Database via query in SQL Server:

(1) “CREATE DATABASE” command is used to create a new database in SQL Server.

(2) Syntax:

Create Database NameOfDataBase;

(3) Let’s create a database via query. Select the database in the SQL server and click on the “New Query” button as shown.

click for new query in sql

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

new query editor open in sql

(5) After doing the above steps, write a query in the editor and press F5 (for executing query) as shown.

  • Database Created in system defined path automatically.
Database created in system by default path in sql
  • Database Created in predefined path. Note: in predefined path, before executing the query, please give access to SQl Server to create database, otherwise it will give Access denied error.
database created in predefined path in sql

Source Code:

–// Create in define folder
CREATE DATABASE MyFirstDBWithDefinePath
on (Name = MyFirstDBWithDefinePath_dat,
FileName = ‘C:\Users\Amit\Desktop\Amit\MyFirstDBWithDefinePath.mdf’)
LOG on (Name = MyFirstDBWithDefinePath_log,
FileName = ‘C:\Users\Amit\Desktop\Amit\MyFirstDBWithDefinePath.ldf’);
–// Create in define folder

(5) After doing the above activity. Refresh or re-login the SQL Server and check the result, as shown.

database created in sql

Use of INNER JOIN in SQL Server
Types of JOINS Statement in SQL Server
How to Take BACKUP from SQL Database
Use of REPEAT-UNTIL in Dynamics 365
Understanding the General Ledger and the COA– Microsoft

Leave a Reply