You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/t-sql/statements/alter-database-transact-sql-set-options.md
+5-52Lines changed: 5 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2694,31 +2694,6 @@ When encryption is enabled at the database level, all file groups will be encryp
2694
2694
2695
2695
You can see the encryption state of the database by using the [sys.dm_database_encryption_keys](../../relational-databases/system-dynamic-management-views/sys-dm-database-encryption-keys-transact-sql.md) dynamic management view.
2696
2696
2697
-
#### **\<db_update_option> ::=**
2698
-
Controls whether updates are allowed on the database.
2699
-
2700
-
READ_ONLY
2701
-
Users can read data from the database but not modify it.
2702
-
2703
-
> [!NOTE]
2704
-
> To improve query performance, update statistics before setting a database to READ_ONLY. If additional statistics are needed after a database is set to READ_ONLY, the [!INCLUDE[ssDE](../../includes/ssde-md.md)] will create statistics in `tempdb`. For more information about statistics for a read-only database, see [Statistics](../../relational-databases/statistics/statistics.md).
2705
-
2706
-
READ_WRITE
2707
-
The database is available for read and write operations.
2708
-
2709
-
To change this state, you must have exclusive access to the database.
2710
-
2711
-
#### **\<db_user_access_option> ::=**
2712
-
Controls user access to the database.
2713
-
2714
-
RESTRICTED_USER
2715
-
Allows for only members of the `db_owner` fixed database role and `dbcreator` and `sysadmin` fixed server roles to connect to the database, but doesn't limit their number. All connections to the database are disconnected in the timeframe specified by the termination clause of the ALTER DATABASE statement. After the database has transitioned to the RESTRICTED_USER state, connection attempts by unqualified users are refused. **RESTRICTED_USER** can't be modified with SQL Managed Instance.
2716
-
2717
-
MULTI_USER
2718
-
All users that have the appropriate permissions to connect to the database are allowed.
2719
-
2720
-
You can determine this option's status by examining the `user_access` column in the [sys.databases](../../relational-databases/system-catalog-views/sys-databases-transact-sql.md) catalog view or the `UserAccess` property of the [DATABASEPROPERTYEX](../../t-sql/functions/databasepropertyex-transact-sql.md) function.
2721
-
2722
2697
#### **\<delayed_durability_option> ::=**
2723
2698
Controls whether transactions commit fully durable or delayed durable.
2724
2699
@@ -2848,8 +2823,6 @@ When you set ALLOW_SNAPSHOT_ISOLATION to a new state (from ON to OFF, or from OF
2848
2823
2849
2824
You can't change the state of ALLOW_SNAPSHOT_ISOLATION if the database is OFFLINE.
2850
2825
2851
-
If you set ALLOW_SNAPSHOT_ISOLATION in a READ_ONLY database, the setting will be kept if the database is later set to READ_WRITE.
2852
-
2853
2826
You can change the ALLOW_SNAPSHOT_ISOLATION settings for the `master`, `model`, `msdb`, and `tempdb` databases. The setting is kept every time the instance of the [!INCLUDE[ssDE](../../includes/ssde-md.md)] is stopped and restarted if you change the setting for `tempdb`. If you change the setting for the `model` system database, that setting becomes the default for any new databases that are created, except for `tempdb`.
2854
2827
2855
2828
The option is ON, by default, for the `master` and `msdb` databases.
@@ -2865,8 +2838,6 @@ Turns off the Read-Committed Snapshot option at the database level. Transactions
2865
2838
2866
2839
To set READ_COMMITTED_SNAPSHOT to ON or OFF, there must be no active connections to the database except for the connection running the ALTER DATABASE command. However, the database doesn't have to be in single-user mode. You can't change the state of this option when the database is OFFLINE.
2867
2840
2868
-
If you set READ_COMMITTED_SNAPSHOT in a READ_ONLY database, the setting will be kept when the database is later set to READ_WRITE.
2869
-
2870
2841
READ_COMMITTED_SNAPSHOT can't be turned ON for the `master`, `tempdb`, or `msdb` system databases. If you change the setting for the `model` system database, that setting becomes the default for any new databases created, except for `tempdb`.
2871
2842
2872
2843
The current setting of this option can be determined by examining the `is_read_committed_snapshot_on` column in the [sys.databases](../../relational-databases/system-catalog-views/sys-databases-transact-sql.md) catalog view.
@@ -3075,28 +3046,10 @@ You can change the default values for any one of the database options for all ne
3075
3046
3076
3047
## Examples
3077
3048
3078
-
### A. Setting the database to READ_ONLY
3079
-
Changing the state of a database or file group to READ_ONLY or READ_WRITE requires exclusive access to the database. The following example sets the database to `RESTRICTED_USER` mode to restricted access. The example then sets the state of the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database to `READ_ONLY` and returns access to the database to all users.
3080
-
3081
-
```sql
3082
-
USE master;
3083
-
GO
3084
-
ALTERDATABASE [database_name]
3085
-
SET RESTRICTED_USER;
3086
-
GO
3087
-
ALTERDATABASE [database_name]
3088
-
SET READ_ONLY
3089
-
GO
3090
-
ALTERDATABASE [database_name]
3091
-
SET MULTI_USER;
3092
-
GO
3093
-
```
3094
-
3095
-
### B. Enabling snapshot isolation on a database
3049
+
### A. Enabling snapshot isolation on a database
3096
3050
The following example enables the snapshot isolation framework option for the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database.
3097
3051
3098
3052
```sql
3099
-
USE [database_name];
3100
3053
USE master;
3101
3054
GO
3102
3055
ALTERDATABASE [database_name]
@@ -3117,7 +3070,7 @@ The result set shows that the snapshot isolation framework is enabled.
### C. Enabling, modifying, and disabling change tracking
3073
+
### B. Enabling, modifying, and disabling change tracking
3121
3074
The following example enables change tracking for the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database and sets the retention period to `2` days.
3122
3075
3123
3076
```sql
@@ -3140,7 +3093,7 @@ ALTER DATABASE [database_name]
3140
3093
SET CHANGE_TRACKING = OFF;
3141
3094
```
3142
3095
3143
-
### D. Enabling the Query Store
3096
+
### C. Enabling the Query Store
3144
3097
The following example enables the Query Store and configures Query Store parameters.
3145
3098
3146
3099
```sql
@@ -3156,7 +3109,7 @@ SET QUERY_STORE = ON
3156
3109
);
3157
3110
```
3158
3111
3159
-
### E. Enabling the Query Store with wait statistics
3112
+
### D. Enabling the Query Store with wait statistics
3160
3113
The following example enables the Query Store and configures its parameters.
3161
3114
3162
3115
```sql
@@ -3174,7 +3127,7 @@ SET QUERY_STORE = ON
3174
3127
);
3175
3128
```
3176
3129
3177
-
### F. Enabling the Query Store with custom capture policy options
3130
+
### E. Enabling the Query Store with custom capture policy options
3178
3131
The following example enables the Query Store and configures its parameters.
0 commit comments