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 Database in SQL Server |
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
- Open the Microsoft SQL Server Management Studio by typing ‘ssms’ or ‘SQL’ In the search.
- Connect to the Database Engine with your current authentication.
- In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance.
- Right-click Databases, and then select New Database.
- In New Database, enter a database name.
- To create the database by accepting all default values, select OK; otherwise, continue with the following optional steps.
- To change the owner name, select (...) to select another owner.
- 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.
- To change the collation of the database, select the Options page, and then select a collation from the list.
- To change the recovery model, select the Options page and select a recovery model from the list.
- To change database options, select the Options page, and then modify the database options.
- To add a new filegroup, select the Filegroups page. Select Add and then enter the values for the filegroup.
- To add an extended property to the database, select the Extended Properties page.
- In the Name column, enter a name for the extended property.
- In the Value column, enter the extended property text. For example, enter one or more statements that describe the database.
- To create the database, select OK.
Create Database using Transact-SQL(T-SQL) Query
- Open the Microsoft SQL Server Management Studio by typing ‘ssms’ or ‘SQL’ In the search.
- Connect to the Database Engine with your current authentication.
- From the Standard bar, select New Query
- Copy and paste the following example into the query window and select Execute.
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
- Create User In SQL Server Management Studio
- Recover SQL Databases from Suspect Mode in SQL Server
- SQL Sever Firewall Ports
- SQL Server Shrink Log File
- Shrink Database (SQL Server)
- SQL Server Enable Remote Connections
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