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.

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

(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 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.

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.
