The Database class represents databases, either system or user-defined, on the instance of SQL Server. The Server class is the parent of the Database class.
By using the Database class, you can do the following:
-
Create a new database or drop and existing database.
-
Register the database in the Active Directory directory service.
-
Reference database objects in collections, such as tables, users, and triggers.
-
Set up database mirroring.
-
Create a master database key.
-
Set up a full-text search catalog.
-
Check data, allocations, catalogs, and tables.
-
Issue a checkpoint.
-
Grant, revoke, and deny permissions to users on the database.
-
Run Transact-SQL statements.
-
Enumerate database information, such as locks or object permissions.
-
Remove the backup history.
-
Monitor the number of transactions.
-
Set the database offline or online.
-
Change the owner of the database.
-
Update statistics.
-
Shrink the database.
-
Truncate the log.
-
Script the database.
To get Database object properties, users can be a member of the public fixed server role.
To set Database object properties and run the Alter method, users must have ALTER permission on the database, or be a member of the db_owner fixed database role.
To create a database, users must have CREATE DATABASE, CREATE ANY DATABASE, or ALTER ANY DATABASE permission on the parent server.
To drop a database, users must have CONTROL permission on the database, or be a member of the db_owner fixed database role.
To grant, revoke, or deny other users permission on the database, users must have CONTROL permission on the database or be a member of the db_owner fixed database role.