T-SQL Tutorial

T-SQL Alter Database


This article describes how to alter database in SQL Server database.
The T-SQL statement ALTER DATABASE modifies a database, or the files and filegroups associated with the database.



Alter Database syntax

ALTER DATABASE database_name MODIFY NAME = new_database_name;
ALTER DATABASE database_name SET option_spec;
ALTER DATABASE database_name ADD FILE | ADD LOG FILE | REMOVE FILE | MODIFY FILE;


Alter Database example

CREATE DATABASE test_database;
ALTER DATABASE test_database MODIFY NAME = test_database2;
DROP DATABASE test_database2;

CREATE DATABASE test_database;
USE test_database;
GO
ALTER DATABASE test_database SET READ_ONLY
GO