TSQL: Partially Contained Databases 70-462

Here’s some TSQL for the Partially Contained Databases section of the 70-462. Explanatory comments are included.

-- enable show advanced options and view current config 
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
EXEC sp_configure;
GO
-- enable the feature
EXEC sp_configure 'contained database authentication', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
-- view changed options
EXEC sp_configure;
GO
 
-- create the partially contained database
CREATE DATABASE partial_containment_db
CONTAINMENT = PARTIAL;
GO
 
USE partial_containment_db;
GO
-- create a contained user from a windows account
CREATE USER [contso\contained_user_b];
GO 
-- create a contained user that uses sql auth
CREATE USER [contained_user_c] WITH PASSWORD = 'Pa$$w0rd';
GO

Leave a Reply