Contained Database SQL Server
Contained Database
A contained database is a database that is isolated from other databases and from the instance of SQL Server.
To use a contained database, it must first be enabled at the server level using the following command.
EXEC sp_configure 'contained database authentication', 1;
RECONFIGURE;
Create a Contained Database
Once contained database authentication is enabled, you can create a new contained database by specifying the CONTAINMENT option as PARTIAL. Here’s an example
-- Create a contained database
CREATE DATABASE ContainedDB
CONTAINMENT = PARTIAL;
Create Contained Users in the Database
Now that the contained database is created, you can add users directly within the database. There are two types of contained users:
- SQL user with password
- Windows user
Connect to the Contained Database
To connect to the contained database, specify the database name in the connection string or in the SQL Server Management Studio (SSMS) connection options. This allows the user to authenticate directly with the contained database.
Limitations
- Some server-level features are not supported within contained databases, such as cross-database queries that use three- or four-part naming conventions.
- The feature is available only in certain editions of SQL Server (starting from SQL Server 2012).
Comments
Post a Comment