SQL Server Contained database

3,758 views

Published on

For More Information Check

http://sqlserver-training.com/What-is-Contained-Database-in-SQL-Server/-


What is Contained Database ?

Contained database is a new feature launched in SQL Server 2011.
This model clearly separates the database application from the management of SQL Server. Users can connect to the database without authenticating a login at the Database Engine level.
Applications within contained databases can be isolated from other databases from the instance of SQL Server, on which they reside, simplifying development and management.
Why Contained Databases feature was Required ?

One of the problems facing the existing database model is data being left behind when an application is moved from one instance to another. Some data connected with an application, (for example, login information and agent job information) is currently stored within the instance instead of inside the database and When you move a non-contained database application from one instance to another instance of SQL Server, this data is left behind.

Later On, DBA's nee to identify the data which was left behind and move it with your application to the new instance of SQL Server. This process can be time consuming and difficult.

What all is being saved inside a Contained Database?

The contained database, keeps all necessary information and objects in the database, for example

Tables
Functions
Constraints
Schemas
types.
It also stores all application-level objects in the database, including

Logins
Application-level agent jobs
Persisted error messages
Linked server information
System settings
What are the Benefits of using Contained Database ?

Contained databases can be easily moved to another server and start working instantly without the need of any additional configuration like adding user, mapping SID’s again. As Contained database have no external dependencies.

What type of Authentication Modes are supported by Contained Database?

Contained Databases supports

SQL Server Authentication
Windows Based Authentication
A contained user is a user without a login in the master database which resides in a Contained Database and can connect to this database specifying its credentials in the connection string. This user doesn’t exists in master’s syslogins tables and will not even show up when you list all SQL Users.

How we create a Contained Database ?

Prior to create a Contained database we need to enable "contained database authentication" property at SQL Server Level. This can be enabled using the following code.

-- Enable contained database authentication on the instance of SQL Server
-- This can done by A member of the sysadmin fixed server role
sp_configure 'show advanced', 1;
RECONFIGURE WITH OVERRIDE;
go
sp_configure 'contained database authentication', 1;
RECONFIGURE WITH OVERRIDE;
go
How to create Users in Contained Databases ?

A Contained database can be created as a normal user database, but with a property named "CONTAINMENT".

Following code, will create a database named "TEST" as contained database.

-- To create contained db you have to specify CONTAINMENT property
CREATE DATABASE TEST
CONTAINMENT = PARTIAL;
go
How to create a user inside a Contained Database ?

A user can be created as a normal user in contained database. The following code, will create a new user name "usr_TEST" inside a TEST Contained database.

USE TEST;
go
-- Create a contained SQL Server Authentication user
CREATE USER usr_TEST
WITH PASSWORD = 'TEST@123$';
goHow to connect to Contained database using a user which exists in Contained Database

While making a connection to SQL Server, we need to specify the [Contained Database name] as default database during the connection.


Published in: Technology
  • Be the first to comment

  • Be the first to like this

SQL Server Contained database

  1. 1. SQL Server – Denali CTP1 Contained Databases Presented by : DBATAG Independent Database Consultant
  2. 2. AGENDA <ul><li>What is Contained Database </li></ul><ul><li>Why Contained Databases were Required </li></ul><ul><li>What all is being saved inside a Contained Database </li></ul><ul><li>Benefits of using Contained Databases </li></ul><ul><li>DEMO </li></ul><ul><li>QA session </li></ul>
  3. 3. What is Contained Database <ul><li>Contained database is a new feature launched in SQL Server 2011. </li></ul><ul><li>This model clearly separates the database application from the management of SQL Server. </li></ul><ul><li>Applications within contained databases can be isolated from other databases from the instance of SQL Server, on which they reside, simplifying development and management. </li></ul>
  4. 4. Why Contained Databases were Required ? <ul><li>One of the problems facing the existing database model is data being left behind when an application is moved from one instance to another. </li></ul><ul><li>Some data connected with an application, (for example, login information and agent job information) is currently stored within the instance instead of inside the database and When you move a non-contained database application from one instance to another instance of SQL Server, this data is left behind. </li></ul><ul><li>Then you must identify the data left behind and move it with your application to the new instance of SQL Server. This process can be time consuming and difficult. </li></ul>
  5. 5. What all is being saved inside a Contained Database <ul><li>The contained database, keeps all necessary information and objects in the database, for example </li></ul><ul><ul><li>Tables </li></ul></ul><ul><ul><li>Functions </li></ul></ul><ul><ul><li>Constraints </li></ul></ul><ul><ul><li>Schemas </li></ul></ul><ul><ul><li>types. </li></ul></ul><ul><li>It also stores all application-level objects in the database, including </li></ul><ul><ul><li>Logins </li></ul></ul><ul><ul><li>application-level agent jobs </li></ul></ul><ul><ul><li>persisted error messages </li></ul></ul><ul><ul><li>linked server information </li></ul></ul><ul><ul><li>system settings. </li></ul></ul>
  6. 6. Benefits of using Contained Databases <ul><li>Contained databases can be easily moved to another server and start working instantly without the need of any additional configuration like adding user, mapping SID’s again. As Contained database have no external dependencies. </li></ul>
  7. 7. Authentication Mode supported by Contained Databases <ul><li>Contained Databases supports </li></ul><ul><ul><li>SQL Server Authentication </li></ul></ul><ul><ul><li>Windows Based Authentication </li></ul></ul><ul><li>For SQL Server Authentication Users, the password will have to be provided when such users are created; </li></ul><ul><li>Windows Authentication Users can be created the same way they are traditionally created </li></ul>
  8. 8. Contained Database - Points <ul><li>A contained user is a user without a login in the master database which resides in a Contained Database and can connect to this database specifying its credentials in the connection string. </li></ul><ul><li>This user doesn’t exists in master’s syslogins tables and will not even show up when you list all SQL Users. </li></ul>
  9. 9. DEMO <ul><li>Lets take a quick tour How we create a Contained Database </li></ul><ul><li>How to create Users in Contained Databases </li></ul><ul><li>How to connect to Contained database using a user which exists in Contained Database </li></ul>
  10. 10. <ul><li>Send me your queries at : </li></ul><ul><li>[email_address] </li></ul><ul><li>More Information can be checked at </li></ul><ul><li>www.sqlServer-Training.com </li></ul><ul><li>www.DBATAG.com </li></ul><ul><li>Lot of Other Video Tutorials are available at these sites freely. </li></ul>Questions and Answers

×