| by Arround The Web | No comments

SQL Server Create Database

“A database is a collection of small units of information used to organize data in pre-defined relationships in the order of tables containing columns and rows.

You can think of a database as the highest-level container with other objects holding the data. A database is responsible for keeping things such as tables, triggers, functions, custom data types, tables, views, and more.

Therefore, when you need to store specific data, you will need to ensure you have a database in which you can define the structure of your data.

This article aims to help you understand how to use the create database statement in SQL Server to initialize a new database.”

Without reluctance, let’s jump in.

Method 1 – SQL Server Create Database (Transact-SQL)

The first and most common database creation method in SQL Server is the CREATE DATABASE statement.

The statement follows a syntax as shown:

CREATE DATABASE [database_name];

We start with the CREATE DATABASE keyword, followed by the name of the database you wish to create. It is good to ensure that the database name adheres to SQL Server identifier naming rules.

SQL Server also limits the database name to 128 characters.

For example, to create a database called linuxhint, we can run the command:

CREATE DATABASE linuxhint;

Once we execute the command above, we can access the created database using the DB explorer or using the terminal.

For example, the following shows the created database in a Graphical Interface.

To show all databases in the server using the Transact-SQL statement, run the following:

SELECT
    name
FROM
    master.SYS.DATABASES D ;

This should list the names of all the databases in the server as follows:

name     |
---------+
master   |
tempdb   |
model    |
msdb     |
LOCAL    |
linuxhint|

NOTE: SQL Server recommends backing up the master database before creating, modifying, or dropping any user database in the server.

Depending on the server configuration, the command may require the CREATE DATABASE permission on the master database.

Method 2 – Using Graphical Interface – SQL Server Management Studio

SQL Server Management Studio is one of the most popular graphical IDEs for working with SQL Server.

You can create a database using SSMS, as shown in the steps below.

Step 1 – In the Object Explorer, Right Click the Databases Option and select “New Database.”

Step 2 – In the Window that opens, enter the name of the database you wish to create and click OK.

Feel free to customize your database options in the options menu.

Once the database has been created, you can find it in the object explorer:

Method 3 – Using Graphical Interface – Dbeaver

One of the most comprehensive and influential tools in the world of databases is Dbeaver. It is an excellent tool with support for almost every database you can think of.

You can use it to create a database in SQL Server, as shown in the steps below.

Start by connecting to the SQL Server. Next, locate the databases section in the Database Navigator:

Right-click and select “Create New Database.”

Provide the target database name and click OK.

This should create a new database in your server allowing you to store data.

Conclusion

In this post, we discussed using various methods such as Transact-SQL, SSMS, and Dbeaver to create a database in SQL Server.

Thanks for reading!!

Share Button

Source: linuxhint.com

Leave a Reply