Ad Code

How to Create Database in SQL Server

You can use SQL Server Management Studio (SSMS) or run a Transact-SQL (T-SQL) statement to create a database in Microsoft SQL Server. Here are the procedures for making a database using both approaches:

 

Using SQL Server Management Studio (SSMS):

·      Open SQL Server Management Studio and connect to your SQL Server instance.

·      Expand the "Databases" folder in the Object Explorer pane.

·      Right-click on the "Databases" folder and select "New Database."

·      In the "New Database" dialog box, enter a name for your database in the "Database name" field.

·      Optionally, you can specify the database owner, file locations, and other configuration settings in the appropriate fields.

·      Click the "OK" button to create the database.

Using Transact-SQL (T-SQL) statement:

·      Open SQL Server Management Studio and connect to your SQL Server instance.

·      Open a new query window.

·      Execute the following T-SQL statement to create a database:

 There are two ways.

 First Approach:

 Syntex:    Create Database Database_Name

Create Database Test

Replace YourDatabaseName with the desired name for your database. You should have appropriate permissions on the SQL Server to execute this command.

Second Method:

Additionally, you can specify some optional parameters when creating the database, such as the file locations and size. Here's an example of the CREATE DATABASE statement with additional parameters:

use [master];

GO

CREATE DATABASE [Test]

 CONTAINMENT = NONE

 ON  PRIMARY 

( NAME = N'Test', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL15.SQLEXPRESS\MSSQL\DATA\Test.mdf' , SIZE = 8192KB , FILEGROWTH = 65536KB )

 LOG ON 

( NAME = N'Test_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL15.SQLEXPRESS\MSSQL\DATA\Test_log.ldf' , SIZE = 8192KB , FILEGROWTH = 65536KB )

GO

This example specifies the file locations for both the data and log files, initial size, maximum size, and file growth settings. Adjust these values as per your requirements.

Remember that to execute this statement, you should have the necessary permissions, such as being a member of the dbcreator or sysadmin role or having the appropriate privileges granted by a database administrator.

Please note that creating a database requires appropriate permissions and access rights on the SQL server. If you are using a specific SQL server system, you may need to log in with a privileged account or consult your database administrator to create the database for you.





Post a Comment

0 Comments

Close Menu