Create 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.

To create a SQL Server database use this script


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:


Finally, the result is the creation of the [Expert-Only] database with the default SQL Server options:

It is also possible to list all tables and disk space in one database with a simple query.