The CREATE DATABASE command is used to create a database.
This will add a new database to the server with associated files and filegroups.
To remove a database use DROP DATABASE.
This example creates a new database named Inventory.
CREATE DATABASE Inventory
Syntax to create a new database.
CREATE DATABASE database-name
Syntax to drop (delete) a database.
DROP DATABASE database-name
Note: Dropping a database will also delete all its content with data and database objects.
Syntax to rename a database.
ALTER DATABASE database-name MODIFY NAME = modified-database-name
For ALTER to work, the database needs to be in single-user mode (see example below).
DROP DATABASE Inventory
USE master;
ALTER DATABASE Inventory SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE Inventory MODIFY NAME = Distribution;
ALTER DATABASE Distribution SET MULTI_USER;
The database is placed in single-user mode, and then back into multi-user mode.