Lesson 3 |
Database permissions |
Objective |
List the permissions required to create, modify, or delete a database. |
Permissions Required for Database Operations in SQL Server 2022
To create, modify, or delete databases in SQL Server 2022, you need specific permissions at both the server and database levels. Here's a breakdown of the required permissions:
-
Create a Database
- Minimum Permission:
CREATE DATABASE
permission in the master database
-
Alternative Permissions:
- Membership in the
dbcreator
fixed server role
- Membership in the
sysadmin
fixed server role (has all permissions)
CONTROL SERVER
permission (equivalent to sysadmin)
-
Modify a Database
-
Minimum Permissions:
ALTER
permission on the database
- Membership in the
db_owner
fixed database role
-
For specific modifications:
- To shrink a database:
ALTER
permission
- To set options:
ALTER
or CONTROL
permission
- To rename: Requires
ALTER
permission plus membership in either dbcreator
or sysadmin
roles
-
Delete (Drop) a Database
- Minimum Permission:
DROP DATABASE
permission in the master database
-
Alternative Permissions:
- Membership in the
dbcreator
fixed server role
- Membership in the
sysadmin
fixed server role
CONTROL
permission on the database
ALTER ANY DATABASE
server-level permission
Server-Level Roles with Database Management Privileges:
- sysadmin: Can perform all activities in SQL Server
- dbcreator: Can create, alter, drop, and restore any database
- serveradmin: Can modify server-wide configuration options and shut down the server
Database-Level Roles:
- db_owner: Can perform all database maintenance and configuration activities
Important Notes:
- To create databases using T-SQL (
CREATE DATABASE
), you need permission in the master database
- To create databases via SSMS GUI, you need both the appropriate permissions and access to the interface
- Azure SQL Database has slightly different permission requirements (using
dbmanager
role instead of dbcreator
)
- Always follow the principle of least privilege when assigning permissions
SQL Server 2022
SQL-Server Database Owner
The person who creates a database is referred to as the database owner, or more commonly known as the DBO.
The database owner (DBO) holds a critical role in managing and maintaining a database within a SQL Server environment. The DBO is responsible for the overall structure and integrity of the database, which includes designing and implementing the database schema. This involves creating tables, defining relationships between them, and establishing constraints to ensure data consistency and accuracy. The DBO also sets up indexes to optimize query performance and creates views or stored procedures to facilitate efficient data access. Beyond the initial setup, the DBO monitors the database’s performance, identifies bottlenecks, and makes adjustments to maintain optimal functionality, ensuring the database meets the needs of applications and users.
In addition to structural responsibilities, the DBO manages access control and security for the database. This includes assigning permissions to users and roles, ensuring that only authorized individuals can access, modify, or delete data. The DBO implements security measures such as encryption, auditing, and compliance with organizational policies or regulatory requirements. They also handle user account management, such as creating or disabling accounts and troubleshooting access issues. By maintaining a secure environment, the DBO protects sensitive data from unauthorized access or breaches while ensuring that legitimate users can perform their tasks without unnecessary restrictions.
The DBO is also tasked with ongoing maintenance and disaster recovery planning. This includes performing regular backups to safeguard data against loss and testing restore procedures to ensure recoverability in case of hardware failures, corruption, or other disasters. The DBO monitors database health, checking for errors, fragmentation, or capacity issues, and takes corrective actions like rebuilding indexes or expanding storage as needed. They also manage database upgrades, apply patches, and ensure compatibility with the SQL Server environment. By proactively addressing these tasks, the DBO ensures the database remains reliable, available, and capable of supporting business operations.
SQL-Server Administrator
The person who installs SQL Server 2022 is generally referred to as the system administrator, or SA. To create, modify, or delete databases, you must be assigned privileges, or permissions, to do so. The following table illustrates the permissions required to perform each of these actions:
Action |
Required Permission |
Create |
SA or those who have CREATE DATABASE permissions |
Modify |
DBO (with CREATE DATABASE permissions) or SA |
Delete |
DBO (with CREATE DATABASE permissions) or SA |
In the next lesson, we will take an initial look at actually creating a database.
Database Permissions - Quiz
Before moving on to the next lesson, click the Quiz button to check your knowledge of the material covered so far on databases with a short, multiple-choice quiz.
Database Permissions - Quiz
