Create a SQL Server database with a script

In order to create a new SQL Server database with one script, just follow this article and especially the code snippet. To create a Microsoft database with a Transact-SQL script, use the CREATE DATABASE function as explained in this post. First, a database represents the main part of a Relational Database Management System. An RDBMS contains and runs databases. A database contains SQL objects and mainly tables.

Create a SQL Server database with a T-SQL script in SSMS

This simple sample script allows to create a database with two SQL commands. Please make sure you understand the commands and adapt the script to your specific case, for example the name of the database.

USE [master];
GO

CREATE DATABASE [EXPERT-ONLY];
GO

The result of the script execution is available below.

Create a SQL Server database with a T-SQL script
Create a SQL Server database with a T-SQL script

Finally, the result is the creation of the [Expert-Only] database with the default SQL Server options. It is now visible under the server / instance, here it is localhost. Then select Databases.

Sql Server database created with a T-SQL script visible under Databases menu
Sql Server database created with a T-SQL script visible under Databases menu

It is also possible to list display the detailed version of the current database with a simple query. To create a Microsoft SQL database with no script, use the SSMS graphic interface.

Be the first to comment

Leave a Reply

Your email address will not be published.


*