<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'denali', 'SQL Server 11', 'database portability', and 'SQL 11'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=denali,SQL+Server+11,database+portability,SQL+11&amp;orTags=0</link><description>Search results matching tags 'denali', 'SQL Server 11', 'database portability', and 'SQL 11'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>SQL Server v.Next (Denali) : More on contained databases and &amp;quot;contained users&amp;quot;</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2010/12/10/sql-server-v-next-denali-more-on-contained-databases-and-contained-users.aspx</link><pubDate>Fri, 10 Dec 2010 12:34:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:31497</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;One of the reasons for contained databases (see &lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/16/sql-server-v-next-denali-contained-databases.aspx" title="http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/16/sql-server-v-next-denali-contained-databases.aspx" target="_blank"&gt;my previous post&lt;/a&gt;) is to allow for a more seamless transition when moving a database from one server to another.&amp;nbsp; One of the biggest complications in doing so is making sure that all of the logins are in place on the new server.&amp;nbsp; Contained databases help solve this issue by creating a new type of user: a database-level user with a password.&amp;nbsp; I want to stress that this is not the same concept as a &lt;a href="http://blogs.msdn.com/raulga/archive/2006/07/03/655587.aspx" title="http://blogs.msdn.com/raulga/archive/2006/07/03/655587.aspx" target="_blank"&gt;user without a login&lt;/a&gt;, which serves a completely different purpose altogether.&amp;nbsp; To avoid confusion, I'm going to call these database-level users "contained users." &lt;br&gt;&lt;/p&gt;

&lt;p&gt;To create a contained user, you must be in the context of a contained database.&amp;nbsp; So let's create a couple of contained databases:&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE DATABASE &lt;font color="black"&gt;CDB1&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;GO&lt;br&gt;CREATE DATABASE &lt;font color="black"&gt;CDB2&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;GO&lt;br&gt;ALTER DATABASE &lt;font color="black"&gt;CDB1&lt;/font&gt; SET CONTAINMENT &lt;font color="gray"&gt;=&lt;/font&gt; PARTIAL&lt;font color="gray"&gt;;&lt;/font&gt;&lt;br&gt;GO&lt;br&gt;ALTER DATABASE &lt;font color="black"&gt;CDB2&lt;/font&gt; SET CONTAINMENT &lt;font color="gray"&gt;=&lt;/font&gt; PARTIAL&lt;font color="gray"&gt;;&lt;/font&gt;&lt;br&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;


&lt;p&gt;So with those databases in place, we can create a contained user named Bob in each of these databases.&amp;nbsp; We'll make the passwords the same just to keep things simple.&lt;br&gt;&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE &lt;font color="black"&gt;CDB1&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;GO&lt;br&gt;CREATE USER &lt;font color="black"&gt;Bob&lt;/font&gt; WITH PASSWORD &lt;font color="gray"&gt;= &lt;font color="red"&gt;'bar'&lt;/font&gt;;&lt;/font&gt;&lt;br&gt;GO&lt;br&gt;USE &lt;font color="black"&gt;CDB2&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;br&gt;GO&lt;br&gt;CREATE USER &lt;font color="black"&gt;Bob&lt;/font&gt; WITH PASSWORD &lt;font color="gray"&gt;= &lt;font color="red"&gt;'bar'&lt;/font&gt;;&lt;/font&gt;&lt;br&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now when you try to connect to this server using Management Studio, you might be tempted to just type the user name and password and click Connect.&amp;nbsp; This won't work, because the user Bob is not a SQL login and does not have a default database, so SQL Authentication fails:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://sqlblog.com/files/folders/31488/download.aspx" height="465" width="432"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since no database is provided, SQL Server isn't able to check if there is a contained user - the engine is not going to go through the hassle of checking every single database and letting you into the first one that works.&amp;nbsp; However, if you click the Options &amp;gt;&amp;gt; button, on the Connection Properties tab there is a "Connect to database:" option.&amp;nbsp; But when you try to specify the database, the drop-down only offers &amp;lt;default&amp;gt; (which we've already established won't work), and &amp;lt;Browse server...&amp;gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://sqlblog.com/files/folders/31493/download.aspx" height="500" width="426"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you choose the &amp;lt;Browse server...&amp;gt; option, it brings up this prompt:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://sqlblog.com/files/folders/31494/download.aspx" height="500" width="581"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But if you say Yes, the connection immediately fails with the same "Login failed" error as above, because the contained user does not have access to the list of databases on the server.&amp;nbsp; &lt;/p&gt;

&lt;p&gt;This is by design.&amp;nbsp; And there is a fix for all of this, if you go back to the Connection Properties tab.&amp;nbsp; While the "Connect to database:" option appears to be a dropdown, it is actually a combo box, so you can type the name of your database, and this will allow you to connect.&amp;nbsp; You should create a registered server with these options so that you only have to perform this action once.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Once you're connected, you'll notice some slightly different behavior in Management Studio.&amp;nbsp; The Object Explorer list is quite sparse - as a contained database user, you don't have access to any of the other databases on the system (except for master and tempdb), or to server-level entities such as SQL Server Agent and the Security and Management nodes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://sqlblog.com/files/folders/31496/download.aspx" height="312" width="386"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'll also notice in a query window that the Use database dropdown list contains only the three databases you see above: the contained database you connected to, as well as master and tempdb. You don't get visibility into the other database you are also "contained" within, even though the username and password match (the sids do not, if you care to inspect the sys.database_principals view in each database).&amp;nbsp; In order to connect to that database, you need to change your current connection to target that database instead (you can do this by right-clicking within the query window and selecting Connection &amp;gt; Change Connection, and following the steps as above).&lt;/p&gt;


&lt;p&gt;For fun I tried to see what would happen if I tried to USE the other database: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE &lt;font color="black"&gt;CDB2&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;


&lt;p&gt;The result:&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;div style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="red"&gt;Msg 916, Level 14, State 1, Line 1&lt;br&gt;The server principal "S-1-9-3-3958803033-1179633189-3577740975-3121738123." is not able to access the database "CDB2" under the current security context.&lt;/font&gt;&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;[For what it's worth, I think this error message is wrong.&amp;nbsp;
 It should say "database principal" and it should show the name of the current user, instead 
of that horribly cryptic identifier.&amp;nbsp; Not that I can't figure out who I'm logged in as, or that it would help me figure out the problem quicker; I just think it could be tidier.]&lt;/p&gt;

&lt;p&gt;The same error message occurs if I try to perform a join between the two databases, or try to access a synonym that underneath accesses a 3-part name referencing the other database.&amp;nbsp; This is more or less what I expected, because the user is truly contained to this database, even though there happens to be a user with the same name and password in another database.&amp;nbsp; However, I hope this functionality is enhanced in the future... I believe that it would fit nicely with availability groups if I can fail over multiple databases as a unit, and also bring over contained users that can access any of the databases within the availability group.&amp;nbsp; This seems to be a more real-world scenario than a user that can only interact with and within a single database.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>SQL Server v.Next (Denali) : Contained Databases</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2010/11/16/sql-server-v-next-denali-contained-databases.aspx</link><pubDate>Tue, 16 Nov 2010 23:02:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:30472</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;A problem that has plagued SQL Server for a long time is that a database is not very portable.&amp;nbsp; Sure, you can backup or detach a database and restore or attach it elsewhere, but when you do that, you are missing a lot of the pieces that make that database a part of an application, and a lot of those pieces are really considered administration pieces as opposed to application pieces.&amp;nbsp; You don't get any synchronization of "outside of the database" items such as security, roles, linked servers, CLR, database mail, service broker objects, replication, and SQL Server Agent jobs; also, if the target server has a different collation, you are going to have issues when creating #temp tables or joining to different databases.&amp;nbsp; You also may be aware of many issues with moving databases to a new server, and having to deal with logins and other security aspects that tend to be incomplete (or wrong) after the initial move.&amp;nbsp; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;Enter "Contained Databases"&lt;/b&gt;&lt;/font&gt; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;In SQL Server Denali, some of these issues are being addressed with a feature called "contained databases."&amp;nbsp; I am not sure if that will be the marketing term you'll hear come release time, but for now I'm going with it.&amp;nbsp; Since it's built into the DDL, the name will be harder to change than, say, when they changed Dynamic Management Framework (DMF) to Policy Based Management (PBM).&amp;nbsp; Essentially, contained databases will help the database to be more of a black box, separating the application and database-specific responsibilities from the administration and server- or instance-specific responsibilities.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;In Denali, the first iteration of the contained databases feature will provide the following solutions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you can create a database-specific user without a login (and you can create multiple such users with the same name for different databases);&lt;/li&gt;

&lt;li&gt;you can have *some* compatible use of tempdb with databases of different collations, since #temp tables will be created in the collation of the calling database context; and,&lt;/li&gt;

&lt;li&gt;you can use a DMV to show most objects or code you have that will threaten containment.&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Objects and other entities can now be classed into two different categories: contained and uncontained.&amp;nbsp; A contained entity is one that has no external dependencies, or at least no dependencies on the instance or server.&amp;nbsp; An example of a contained object is one that lives within the database and has no external references. For a full list of contained entities, see this Books Online topic:&lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff929188%28v=SQL.110%29.aspx" title="http://msdn.microsoft.com/en-us/library/ff929188%28v=SQL.110%29.aspx" target="_blank"&gt;Features Within the Application Model&lt;/a&gt;&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An uncontained object is one that either has an explicit external dependencies (e.g. three- or four-part names) or where it cannot be determined (e.g. dynamic SQL).&amp;nbsp; For a full list of explicit objects that are considered uncontained, see this Books Online topic:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff929118%28v=SQL.110%29.aspx" title="http://msdn.microsoft.com/en-us/library/ff929118%28v=SQL.110%29.aspx" target="_blank"&gt;Features Outside of the Application Model &lt;/a&gt;&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that some things were missed; for example, HOST_NAME should not be in this list (and it has been &lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/622247/host-name-disallowed-in-contained-databases" title="http://connect.microsoft.com/SQLServer/feedback/details/622247/host-name-disallowed-in-contained-databases" target="_blank"&gt;reported on Connect&lt;/a&gt;).&amp;nbsp; Finally, if you want to understand what SQL Server features were modified to accommodate containment, see this Books Online topic:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff929143%28v=SQL.110%29.aspx" title="http://msdn.microsoft.com/en-us/library/ff929143(v=SQL.110).aspx" target="_blank"&gt;Modified Features (Contained Databases) &lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The most interesting thing here is the fact that CREATE / ALTER DATABASE has been changed, and actually works differently when affecting a contained database.&amp;nbsp; A new option called CURRENT has been added, so that if you move the database to a new instance or change the name of the database, the command will still work.&amp;nbsp; The documentation states that in a contained database you MUST use ALTER DATABASE CURRENT, and in an uncontained database, you MUST use ALTER DATABASE &amp;lt;database name&amp;gt;, but - in the current CTP at least - neither limitation is enforced.&amp;nbsp; The topic has some other useful information on a new collation type, limitations of temporary tables, and user options.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;Turning containment on&lt;/font&gt; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;In Denali, only partial containment is supported. This means that you can create uncontained entities, and you can discover these entities (using a new DMV), but the engine will not prevent you from creating them.&amp;nbsp; In a future version of SQL Server, full containment will be supported; this means that containment can actually be enforced.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;So, let's create a couple of databases (with different collation), and play with some of these features.&amp;nbsp; Note that you need to set a configuration option at the server level in order to use DDL dealing with CONTAINMENT.&lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[master]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;CREATE DATABASE &lt;/font&gt;&lt;font color="black"&gt;[ContainedDB1] &lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="blue"&gt;COLLATE&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; SQL_Latin1_General_CP1_CI_AS&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;CREATE DATABASE &lt;/font&gt;&lt;font color="black"&gt;[ContainedDB2] &lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="blue"&gt;COLLATE&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; Finnish_Swedish_100_CI_AI_SC&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;EXEC &lt;/font&gt;&lt;font color="darkred"&gt;sp_configure &lt;/font&gt;&lt;font color="red"&gt;'show advanced options'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;RECONFIGURE WITH OVERRIDE&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;EXEC &lt;/font&gt;&lt;font color="darkred"&gt;sp_configure &lt;/font&gt;&lt;font color="red"&gt;'contained database authentication'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;EXEC &lt;/font&gt;&lt;font color="darkred"&gt;sp_configure &lt;/font&gt;&lt;font color="red"&gt;'show advanced options'&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;0&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;RECONFIGURE WITH OVERRIDE&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;ALTER DATABASE &lt;/font&gt;&lt;font color="black"&gt;[ContainedDB1] &lt;/font&gt;&lt;font color="blue"&gt;SET CONTAINMENT &lt;/font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;font color="blue"&gt; PARTIAL&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;ALTER DATABASE &lt;/font&gt;&lt;font color="black"&gt;[ContainedDB2] &lt;/font&gt;&lt;font color="blue"&gt;SET CONTAINMENT &lt;/font&gt;&lt;font color="black"&gt;=&lt;/font&gt;&lt;font color="blue"&gt; PARTIAL&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;Creating a user without a login&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;You can now create a user that is not tied to a login.&amp;nbsp; The syntax is quite similar to CREATE LOGIN, and you will still have access to most of the other features such as password complexity, default_schema and default_language.&amp;nbsp; Here we will create two users, both named MyUser, with different passwords for each database:&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[ContainedDB1]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;CREATE USER &lt;/font&gt;&lt;font color="black"&gt;[MyUser] &lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;WITH PASSWORD&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; = &lt;font color="red"&gt;'DB1'&lt;/font&gt;;&lt;/font&gt;&lt;font color="gray"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;br&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[ContainedDB2]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;CREATE USER &lt;/font&gt;&lt;font color="black"&gt;[MyUser] &lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="blue"&gt;WITH PASSWORD&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; = &lt;font color="red"&gt;'DB2'&lt;/font&gt;;&lt;/font&gt;&lt;font color="gray"&gt;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

If I try to do this in an uncontained database, I get the following error:

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="red"&gt;Msg 33233, Level 16, State 1, Line 1&lt;br&gt;You can only create a user with a password in a contained database. &lt;br&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;You may ask yourself, if there are two users with the same name, how 
does SQL Server figure out which one you mean?&amp;nbsp; Well, users are now 
authenticated at the database level first (database is specified in the 
connection string), and SQL Server will try to find a login with the same name if 
no user is found at the database level.&amp;nbsp; Mainly for performance reasons, it will not do the opposite: try to find a login, 
then when it fails, poll every single database for a user with the same name - it will just fail outright if there is no database specified.&amp;nbsp; So, if 
you specify a valid contained database user name but no database context, the credentials 
will fail even if the password is correct.&amp;nbsp; This means you will want to 
stop relying on the default database setting (which in fact does not 
exist for a contained user), and explicitly specify the "Initial 
Catalog" property in your connection strings.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You can see the new properties page for contained database users, and they are of the type "SQL user with password":&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://sqlblog.com/files/folders/30645/download.aspx" height="660" width="377"&gt;&amp;nbsp;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So what's the big deal?&amp;nbsp; Well, now I can move either or both of these databases to others server, and just re-point connection strings; no login or SID mess.&amp;nbsp; I can also do the same with Windows principals, but this isn't as interesting because they are not tied to logins for uncontained databases either:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[ContainedDB1]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;CREATE USER&lt;/font&gt;&lt;font color="magenta"&gt; &lt;/font&gt;&lt;font color="black"&gt;[Domain\User]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;font color="green"&gt; -- note user@domain is not supported&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, note that in a contained database, the Windows principal is automatically granted access to the engine and the current database, whereas in an uncontained database, this must be granted through an associated login or via a Windows group.&amp;nbsp; For more information on the updated CREATE USER syntax, see &lt;a href="http://msdn.microsoft.com/en-us/library/ms173463%28v=SQL.110%29.aspx" title="http://msdn.microsoft.com/en-us/library/ms173463%28v=SQL.110%29.aspx" target="_blank"&gt;this Books Online topic&lt;/a&gt;.&amp;nbsp; There is also a new system stored procedure, &lt;a href="http://msdn.microsoft.com/en-us/library/ff929275%28v=SQL.110%29.aspx" title="http://msdn.microsoft.com/en-us/library/ff929275(v=SQL.110).aspx" target="_blank"&gt;sys.sp_migrate_user_to_contained&lt;/a&gt;, to help you migrate each SQL auth-based user to a contained database user with password.&lt;br&gt;&lt;/p&gt;
Note that when you move a database to a new server with different 
password complexity rules, these will not be validated unless you 
re-create a login or alter their password.&amp;nbsp; So it can be possible to end up with weak passwords even on a server where complexity rules are expected to be enforced.
&lt;p&gt;Security is a big issue, and I'm sure I've barely scratched the surface with how users and logins will or will not be able to co-exist in a contained database world.&amp;nbsp; Please let me know about any scenarios that you are interested in investigating.&amp;nbsp; Also be sure to check out this Books Online topic, "&lt;a href="http://msdn.microsoft.com/en-us/library/ff929055%28v=SQL.110%29.aspx" title="http://msdn.microsoft.com/en-us/library/ff929055%28v=SQL.110%29.aspx" target="_blank"&gt;Threats Against Contained Databases&lt;/a&gt;."&amp;nbsp; One interesting note from that topic, is just another nail in the coffin for AUTO_CLOSE: contained databases with AUTO_CLOSE enabled could be subject to a denial of service attack, because of the extra resources required to authenticate a contained database user. &lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="4"&gt;Resolving tempdb collation issues &lt;/font&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;It should be no surprise what happens if you run this code in an uncontained or pre-Denali database (on a server with a collation other than Finnish_Swedish_100_CI_AI):&lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[master]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE DATABASE &lt;/font&gt;&lt;font color="black"&gt;[test] &lt;/font&gt;&lt;font color="blue"&gt;COLLATE&lt;/font&gt;&lt;font color="black"&gt; Finnish_Swedish_100_CI_AI&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[test]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;dbo.foo&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="black"&gt;    bar &lt;/font&gt;&lt;font color="blue"&gt;NVARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;);&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="#434343"&gt;#foo&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;    &lt;/font&gt;&lt;font color="black"&gt;bar &lt;/font&gt;&lt;font color="blue"&gt;NVARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;32&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;);&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="gray"&gt;*&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="#434343"&gt;#foo &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;a&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INNER JOIN &lt;/font&gt;&lt;font color="black"&gt;dbo.foo &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;b&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;a.bar = &lt;/font&gt;&lt;font color="blue"&gt;&lt;/font&gt;&lt;font color="black"&gt;b.bar&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;DROP TABLE &lt;/font&gt;&lt;font color="#434343"&gt;#foo&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[master]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;DROP DATABASE &lt;/font&gt;&lt;font color="black"&gt;[test]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;font color="blue"&gt;&lt;br&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;The join condition yields this error message, because the temporary table was created in the default server collation, not the database's collation:
&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="red"&gt;Msg 468, Level 16, State 9, Line 3&lt;br&gt;Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Finnish_Swedish_100_CI_AI" in the equal to operation.&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;In a contained database in Denali, temporary objects are created with the database collation.&amp;nbsp; So if you make the database in the above sample contained and re-run the code, it will work just fine.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Of course this doesn't solve all of the issues... you can still have conflicts if you join your #temp tables to objects in databases with different collations.&amp;nbsp; And I do not mean to trivialize collation issues, I just don't have a lot of exposure to the problems, so if you are in a collation-sensitive environment, you will want to spend some more time investigating whether this creates more problems than it solves.&amp;nbsp; But if your T-SQL code is truly contained to the database and collation issues are minor, most of this should make moving the database to a new instance easier.&lt;br&gt;&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;&lt;font size="4"&gt;Discovering threats to database portability&lt;/font&gt; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;It can be important to understand what parts of your database won't be portable (a.k.a. contained) even if you are not utilizing database containment functionality.&amp;nbsp; So, there is a new DMV called &lt;a href="http://msdn.microsoft.com/en-us/library/ff929336%28v=SQL.110%29.aspx" title="http://msdn.microsoft.com/en-us/library/ff929336(v=SQL.110).aspx" target="_blank"&gt;sys.dm_db_uncontained_entities&lt;/a&gt; that will highlight these items for you.&amp;nbsp; Not only will it highlight the objects, but for procedure / functions / views / triggers, it will highlight the statement offset, so you can drill right down to the statement and be made immediately aware of multiple violations in the same module.&amp;nbsp; Let's use a contained database we've created above, and add a bunch of objects that we know will threaten containment:&lt;/p&gt;


&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[master]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;font color="green"&gt;&lt;br&gt;-- create a login:&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE LOGIN&lt;/font&gt;&lt;font color="black"&gt; MyLogin &lt;/font&gt;&lt;font color="blue"&gt;WITH PASSWORD&lt;/font&gt;&lt;font color="black"&gt; =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="red"&gt;'DB1'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;&lt;br&gt;USE &lt;/font&gt;&lt;font color="black"&gt;[ContainedDB1]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;&lt;font color="green"&gt;-- create a user bound to the above login:&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE USER&lt;/font&gt;&lt;font color="magenta"&gt; &lt;/font&gt;&lt;font color="black"&gt;[MyLogin] &lt;/font&gt;&lt;font color="blue"&gt;FROM LOGIN&lt;/font&gt;&lt;font color="black"&gt; [MyLogin]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;&lt;font color="green"&gt;-- create a procedure with dynamic SQL + deferred name resolution:&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;CREATE PROCEDURE &lt;/font&gt;&lt;font color="black"&gt;dbo.foo&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp; EXEC&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'SELECT * FROM table1'&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;EXEC&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="red"&gt;'SELECT * FROM table2'&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT &lt;/font&gt;&lt;font color="gray"&gt;* &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;dbo.object_does_not_exist&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;&lt;font color="green"&gt;-- create a synonym to an external, uncontained object:&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;CREATE SYNONYM&lt;/font&gt;&lt;font color="black"&gt; dbo.bar &lt;/font&gt;&lt;font color="blue"&gt;FOR &lt;/font&gt;&lt;font color="black"&gt;[master].&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;backup_devices&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;&lt;font color="green"&gt;-- create a procedure that references the synonym:&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;CREATE PROCEDURE &lt;/font&gt;&lt;font color="black"&gt;dbo.getbar&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp; SELECT &lt;/font&gt;&lt;font color="gray"&gt;* &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;dbo.bar&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font&gt;&lt;font color="blue"&gt;&lt;font color="green"&gt;-- create a procedure that calls xp_cmdshell:&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE PROCEDURE &lt;/font&gt;&lt;font color="black"&gt;dbo.use_xp_cmdshell&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp; EXEC &lt;/font&gt;&lt;font color="darkred"&gt;xp_cmdshell &lt;/font&gt;&lt;font color="red"&gt;'dir C:\'&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font&gt;&lt;font color="blue"&gt;&lt;font color="green"&gt;-- create a procedure that relies on database mail:&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE PROCEDURE &lt;/font&gt;&lt;font color="black"&gt;dbo.use_dbmail&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp; EXEC &lt;/font&gt;&lt;font color="black"&gt;msdb.dbo.&lt;/font&gt;&lt;font color="darkred"&gt;sp_send_dbmail&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;p&gt;&lt;font&gt;&lt;font color="blue"&gt;&lt;font color="green"&gt;-- create a silly function that generates a random object_id:&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE FUNCTION &lt;/font&gt;&lt;font color="black"&gt;dbo.GenRandNumber&lt;/font&gt;&lt;font color="gray"&gt;()&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;RETURNS BIGINT&lt;br&gt;AS&lt;br&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp; RETURN&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT TOP &lt;/font&gt;&lt;font color="black"&gt;1 [object_id]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;/font&gt;&lt;font color="black"&gt;msdb.&lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;objects&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;END&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font&gt;&lt;font color="blue"&gt;&lt;font color="green"&gt;-- create a table with a default constraint that references the function:&lt;/font&gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE TABLE &lt;/font&gt;&lt;font color="black"&gt;dbo.nonsense&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;id &lt;/font&gt;&lt;font color="blue"&gt;INT &lt;/font&gt;&lt;font color="gray"&gt;NOT NULL &lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;      DEFAULT &lt;/font&gt;&lt;font color="black"&gt;dbo.GenRandNumber&lt;/font&gt;&lt;font color="gray"&gt;()&lt;br&gt;);&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;/p&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;I threw this query together to show how the DMV can be used to pinpoint the problems and to dive directly into resolving them:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;e.feature_name&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;[object] = &lt;/font&gt;&lt;font color="blue"&gt;&lt;/font&gt;&lt;font color="magenta"&gt;COALESCE&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font&gt;&lt;font color="magenta"&gt;SCHEMA_NAME&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;o.[schema_id]&lt;/font&gt;&lt;font color="gray"&gt;)) + &lt;/font&gt;&lt;font color="red"&gt;'.' &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;o.[name]&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="magenta"&gt;SCHEMA_NAME&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;s.[schema_id]&lt;/font&gt;&lt;font color="gray"&gt;)) + &lt;/font&gt;&lt;font color="red"&gt;'.' &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="magenta"&gt;QUOTENAME&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;s.[name]&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp; ),&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;[line] = &lt;/font&gt;&lt;font color="blue"&gt;&lt;/font&gt;&lt;font color="magenta"&gt;COALESCE&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;e.statement_line_number&lt;/font&gt;&lt;font color="gray"&gt;, &lt;/font&gt;&lt;font color="black"&gt;0&lt;/font&gt;&lt;font color="gray"&gt;),&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;[statement / synonym target / route / user/login] =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="magenta"&gt;COALESCE&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;s.[base_object_name]&lt;/font&gt;&lt;font color="gray"&gt;, &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="magenta"&gt;SUBSTRING&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;m.[definition]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;e.statement_offset_begin&lt;/font&gt;&lt;font color="gray"&gt; / &lt;/font&gt;&lt;font color="black"&gt;2&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;e.statement_offset_end&lt;/font&gt;&lt;font color="gray"&gt; / &lt;/font&gt;&lt;font color="black"&gt;2&lt;/font&gt;&lt;font color="gray"&gt; - &lt;/font&gt;&lt;font color="black"&gt;e.statement_offset_begin&lt;/font&gt;&lt;font color="gray"&gt; / &lt;/font&gt;&lt;font color="black"&gt;2&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;) &lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;COLLATE CATALOG_DEFAULT&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;r.[name]&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="red"&gt;'User : ' &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="black"&gt;p.[name] &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="red"&gt;' / Login : ' &lt;/font&gt;&lt;font color="gray"&gt;+ &lt;/font&gt;&lt;font color="black"&gt;sp.[name]&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;dm_db_uncontained_entities&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;e&lt;br&gt;&lt;/font&gt;&lt;font color="magenta"&gt;LEFT &lt;/font&gt;&lt;font color="gray"&gt;OUTER &lt;/font&gt;&lt;font color="blue"&gt;JOIN &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;objects&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;o&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;e.major_id =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;o.[object_id]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;e.class =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;1&lt;br&gt;&lt;/font&gt;&lt;font color="magenta"&gt;LEFT &lt;/font&gt;&lt;font color="gray"&gt;OUTER &lt;/font&gt;&lt;font color="blue"&gt;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;sql_modules&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;m&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;e.major_id =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;m.[object_id]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;e.class =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;1&lt;br&gt;&lt;/font&gt;&lt;font color="magenta"&gt;LEFT &lt;/font&gt;&lt;font color="gray"&gt;OUTER &lt;/font&gt;&lt;font color="blue"&gt;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;synonyms&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;s&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;e.major_id &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;s.[object_id]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;e.class =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;1&lt;br&gt;&lt;/font&gt;&lt;font color="magenta"&gt;LEFT &lt;/font&gt;&lt;font color="gray"&gt;OUTER &lt;/font&gt;&lt;font color="blue"&gt;JOIN &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;routes&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;r&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;e.major_id =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;r.[route_id]&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;e.class =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;19&lt;br&gt;&lt;/font&gt;&lt;font color="magenta"&gt;LEFT &lt;/font&gt;&lt;font color="gray"&gt;OUTER &lt;/font&gt;&lt;font color="blue"&gt;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;database_principals&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;p&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;e.major_id =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;p.principal_id&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="gray"&gt;AND &lt;/font&gt;&lt;font color="black"&gt;e.class =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;4&lt;br&gt;&lt;/font&gt;&lt;font color="magenta"&gt;LEFT &lt;/font&gt;&lt;font color="gray"&gt;OUTER &lt;/font&gt;&lt;font color="blue"&gt;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;&lt;font color="green"&gt;sys&lt;/font&gt;.&lt;font color="green"&gt;server_principals&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;sp&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;p.[sid] =&lt;/font&gt;&lt;font color="blue"&gt; &lt;/font&gt;&lt;font color="black"&gt;sp.[sid]&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Results: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;img src="http://sqlblog.com/files/folders/30656/download.aspx" border="1" height="172" width="647"&gt;&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'll see that the stored procedure dbo.foo was picked up by the DMV three times: once for each use of dynamic SQL, and once for reference to an object that doesn't yet exist (this is captured so you're away that this *may* become an uncontained object when it eventually gets created).&amp;nbsp; I thought the line number could be pretty useful too, so that if you loaded the definition of the object, you could go straight to that line instead of performing a search.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Note that the DMV did not pick up the SYNONYM that referenced a three-part name; you'd have to identify any synonyms and then brute force discover them.&amp;nbsp; I filed &lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/622368/denali-engine-sys-dm-db-uncontained-entities-does-not-discover-usage-of-synonyms-with-uncontained-targets" title="http://connect.microsoft.com/SQLServer/feedback/details/622368/denali-engine-sys-dm-db-uncontained-entities-does-not-discover-usage-of-synonyms-with-uncontained-targets" target="_blank"&gt;Connect #622368&lt;/a&gt; in the hopes that they will rectify this issue.&amp;nbsp; &lt;br&gt;&lt;/p&gt;

&lt;p&gt;Also note that the table using a function that itself has an uncontained reference is not picked up.&amp;nbsp; I didn't file a Connect item for this one as I think it is a relatively rare issue, however if you have situations like this it is something to keep in mind.&lt;/p&gt;

&lt;p&gt;Finally, I am not sure exactly what you can do about the AutoCreatedLocal route; this is the first time I've ever noticed this entity. &lt;br&gt;&lt;/p&gt;

&lt;p&gt;There are some other entities covered by the DMV that I didn't treat here, such as Assembly, Type, Full-text Index, Database DDL Trigger, and Audit Specification, but if you are using these items, you should see them show up in the list as well (and you can adjust the query to include any relevant information from those catalog views). &lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;br&gt;&lt;font size="4"&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;There are obviously plenty of angles to work on, and it will likely take several versions to get to all of them.&amp;nbsp; Having linked servers and agent at the database level, for example, could be very interesting.&amp;nbsp; I can sense the level of investment here and have witnessed the team's excitement first hand, so I am looking forward to the evolution of this feature over the next few major releases.&lt;br&gt;&lt;/p&gt;
For more information on contained databases, there is a great Books Online topic in the works:
&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ff929071%28v=SQL.110%29.aspx" title="http://msdn.microsoft.com/en-us/library/ff929071%28v=SQL.110%29.aspx" target="_blank"&gt;http://msdn.microsoft.com/en-us/library/ff929071%28v=SQL.110%29.aspx&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&amp;nbsp; &lt;br&gt;&lt;/p&gt;</description></item></channel></rss>