Kailash's Blogs

Create Database in SQL Server

Kailash Chandra Behera | Thursday, May 04, 2023
Kailash's Blogs

Introduction

Here in this blog Create Database in SQL Server, we are going to explore how to create a microsoft sql server database using Microsoft SQL Server Management Studio and T-SQL query.

Create a sql database
Create Database in SQL Server

Getting Started

A SQL database is a collection of highly structured tables, wherein each row reflects a data entity, and every column defines a specific information field. A maximum of 32,767 databases can be specified on an instance of SQL Server.

Above are a sort description of a SQL Database. Let focus to create a SQL database. The following steps guides create a database using Microsoft SQL Server Management Studio.

Create Database using Microsoft SQL Server Management Studio
  1. Open the Microsoft SQL Server Management Studio by typing ‘ssms’ or ‘SQL’ In the search.

  2. Connect to the Database Engine with your current authentication.

  3. In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance.

  4. Right-click Databases, and then select New Database.

  5. In New Database, enter a database name.

  6. To create the database by accepting all default values, select OK; otherwise, continue with the following optional steps.

  7. To change the owner name, select (...) to select another owner.

  8. To change the default values of the primary data and transaction log files, in the Database files grid, select the appropriate cell and enter the new value.

  9. To change the collation of the database, select the Options page, and then select a collation from the list.

  10. To change the recovery model, select the Options page and select a recovery model from the list.

  11. To change database options, select the Options page, and then modify the database options.

  12. To add a new filegroup, select the Filegroups page. Select Add and then enter the values for the filegroup.

  13. To add an extended property to the database, select the Extended Properties page.

    1. In the Name column, enter a name for the extended property.

    2. In the Value column, enter the extended property text. For example, enter one or more statements that describe the database.

  14. To create the database, select OK.

Create Database using Transact-SQL(T-SQL) Query
  1. Open the Microsoft SQL Server Management Studio by typing ‘ssms’ or ‘SQL’ In the search.

  2. Connect to the Database Engine with your current authentication.

  3. From the Standard bar, select New Query

  4. Copy and paste the following example into the query window and select Execute.

  5.  USE master;  
     GO  
     CREATE DATABASE TestDatabaseON  
     (NAME = TestDatabase_dat,  
       FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\TestDatabase.mdf',  
       SIZE = 10,  
       MAXSIZE = 50,  
       FILEGROWTH = 5)  
     LOG ON  
     (NAME = TestDatabase_log,  
       FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\TestDatabase.ldf',  
       SIZE = 5 MB,  
       MAXSIZE = 25 MB,  
       FILEGROWTH = 5 MB);  
     GO  
    

The above example creates the database TestDatabase. Because the keyword PRIMARY isn't used, the first file (TestDatabase_dat) becomes the primary file. Because MB or KB aren't specified in the SIZE parameter for the TestDatabase_dat file, it uses MB and is allocated in megabytes. The TestDatabase_log file is allocated in megabytes because the MB suffix is explicitly stated in the SIZE parameter.

Related Articles

  1. Create User In SQL Server Management Studio
  2. Recover SQL Databases from Suspect Mode in SQL Server
  3. SQL Sever Firewall Ports
  4. SQL Server Shrink Log File
  5. Shrink Database (SQL Server)
  6. SQL Server Enable Remote Connections

Summary

We discussed here to create a database using both T-SQL Query and SSMS. I hope this blog Create A Database in SQL Server my helpful to you.

Thanks


No comments: