Saturday, March 23, 2019

MSSQL: Contained Database

The Contained database consisted of all the settings enabling the database to be self-reliance and not depending on the instance or the database engine. Benefits of a contained database are to enable the ease to migrate to another instance or Azure platform easily.

The process of making converts a database to contained database consist of 2 steps.

To view if an instance contains any Contained database.
select name, containment from sys.databases;
select * from sys.dm_db_uncontained_entities;  
select * from sys.sql_modules; 
Step 1: Enable server property Contained Database authentication parameter
sp_configure 'Contained database authentication', 1;  
go  
Reconfigure  
Step 2: set database to contained database
use master  
go  
alter database vcdb_2016 set containment = PARTIAL  
To view Contained database
select name, containment from sys.databases;
If there is a need to migrate any users to the Contained database. It can be achieved with the following TSQL. Please check provided link if many users need to be migrated. Otherwise, each user will need to be migrated manually with "sp_migrate_user_to_contained" procedure.
 sp_migrate_user_to_contained    
 @username = N'Barry',   
 @rename = N'keep_name',   
 @disablelogin = N'do_not_disable_login' ;  

Other means of migration to Azure can be done using SQL Server Management Studio to copy the database over. Detach and attach method works as well.

No comments:

Post a Comment

MSSQL: Getting more detail information for failed jobs.

Often when a job failed, it provides trivial information for diagnostic. In order to expand the detail of the failed job, it can be done th...