{"id":2353,"date":"2014-04-18T11:00:45","date_gmt":"2014-04-18T15:00:45","guid":{"rendered":"http:\/\/sqlity.net\/en\/?p=2353"},"modified":"2014-11-13T12:30:11","modified_gmt":"2014-11-13T17:30:11","slug":"auto-fix-orphaned-users","status":"publish","type":"post","link":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/","title":{"rendered":"Auto Fix Orphaned Users"},"content":{"rendered":"<div>\n<h3>Introduction<\/h3>\n<p>\nOver the last few days we talked about how to <a href=\"http:\/\/sqlity.net\/en\/2349\/scripting-all-logins\/\">copy logins<\/a> from one instance of SQL Server to another. We also talked about how to <a href=\"http:\/\/sqlity.net\/en\/2338\/fix-orphaned-users\/\">fix orphaned users<\/a> that lost their association with the underlying login, for example because the database was restored on a different server.\n<\/p>\n<p>Today I would like to show you a T-SQL query that you can use to generate the statements necessary to auto fix orphaned users.\n<\/p>\n<h3>Identifying Fixable Orphaned Users<\/h3>\n<p>\nIn SQL Server, a login is associated with a database user if (and only if) their SIDs match. If that link is severed, there is no way to tell, which user belongs to which login. That makes automatically fixing this link a little difficult.\n<\/p>\n<p>\nIt is however considered a best practice to give your logins and their users the same name. If you follow that practice, you can use the name to identify which login to link to which user. While that is not a perfect solution, it will work in most cases. Therefore that is the solution I am going with in this article.\n<\/p>\n<p>\nLet us begin by figuring out when a user needs to be re-linked and what would stop us from doing that automatically. A user is linked to a login if their SIDs match. That means in turn that a user needs to be considered for auto fixing, if there is no login with the same SID. To find those users we can (left) join <span class=\"tt\">sys.database_principals<\/span> with <span class=\"tt\">sys.server_principals<\/span> on the SID:\n<\/p>\n<div>\n[sql]\n  FROM sys.database_principals AS DP<br \/>\n  LEFT JOIN sys.server_principals AS SP2<br \/>\n    ON DP.sid = SP2.sid<br \/>\n[\/sql]\n<\/div>\n<p>\nNo users that have a matching login already need to be looked at any further. The others however might, as they are orphaned users.\n<\/p>\n<p>\nWe said before that we are going to use the name to find match candidates. Not every user will have a candidate login however. To find out, we are going to have to left join to <span class=\"tt\">sys.server_principals<\/span> again, this time on the name:\n<\/p>\n<div>\n[sql]\n  FROM sys.database_principals AS DP<br \/>\n  LEFT JOIN sys.server_principals AS SP<br \/>\n    ON DP.name = SP.name COLLATE SQL_Latin1_General_CP1_CI_AS<br \/>\n  LEFT JOIN sys.server_principals AS SP2<br \/>\n    ON DP.sid = SP2.sid<br \/>\n[\/sql]\n<\/div>\n<p>\nDepending on your collation settings, this join might cause a collation conflict. I added the <span class=\"tt\">COLLATE<\/span> clause to prevent that.\n<\/p>\n<p>\nIn SQL Server a login can be associated with at most one database user in any given database. That means, if the candidate login we just found by looking at the name is already associated with another user in our database, we cannot use it. To identify those conflicting logins we need to left join to <span class=\"tt\">sys.database_principals<\/span> one more time:\n<\/p>\n<div>\n[sql]\n  FROM sys.database_principals AS DP<br \/>\n  LEFT JOIN sys.server_principals AS SP<br \/>\n    ON DP.name = SP.name COLLATE SQL_Latin1_General_CP1_CI_AS<br \/>\n  LEFT JOIN sys.database_principals AS DP2<br \/>\n    ON SP.sid = DP2.sid AND DP.principal_id &lt;&gt; DP2.principal_id<br \/>\n  LEFT JOIN sys.server_principals AS SP2<br \/>\n    ON DP.sid = SP2.sid<br \/>\n[\/sql]\n<\/div>\n<p>\nThere are database principals that we do not want to mess with. For example the <span class=\"tt\">dbo<\/span> user. <span class=\"tt\">dbo<\/span> always has the <span class=\"tt\">principal_id<\/span> <span class=\"tt\">1<\/span> so it is easy to identify. We also have users that cannot be linked to a login. Examples are users that where created <span class=\"tt\">WITHOUT LOGIN<\/span> or users that use database authentication in a partially contained database.\n<\/p>\n<p>\nThe users that can be linked can be identified by their authentication type, which needs to be either <span class=\"tt\">INSTANCE<\/span> or <span class=\"tt\">WINDOWS<\/span>. With that we can add the following <span class=\"tt\">WHERE<\/span> clause to our query:\n<\/p>\n<div>\n[sql]\nWHERE DP.authentication_type_desc IN ('INSTANCE','WINDOWS')<br \/>\n  AND DP.principal_id&gt;1<br \/>\n[\/sql]\n<\/div>\n<p>\nNow we have filtered fixable users and we have joined to a bunch of other CVs. The next step is to combine the data from all tables to something meaningful:\n<\/p>\n<div>\n[sql]\nSELECT DP.name, DP.type_desc,<br \/>\n       CASE WHEN SP.sid IS NOT NULL THEN 1 ELSE 0 END has_name_match,<br \/>\n       CASE WHEN SP.sid = DP.sid THEN 1 ELSE 0 END is_name_sid_matched,<br \/>\n       CASE WHEN SP2.sid IS NOT NULL THEN SP2.name END has_sid_match,<br \/>\n       CASE WHEN dp2.sid IS NOT NULL THEN 1 ELSE 0 END name_sid_conflict<br \/>\n  FROM sys.database_principals AS DP<br \/>\n  LEFT JOIN sys.server_principals AS SP<br \/>\n    ON DP.name = SP.name COLLATE SQL_Latin1_General_CP1_CI_AS<br \/>\n  LEFT JOIN sys.database_principals AS DP2<br \/>\n    ON SP.sid = DP2.sid AND DP.principal_id &lt;&gt; DP2.principal_id<br \/>\n  LEFT JOIN sys.server_principals AS SP2<br \/>\n    ON DP.sid = SP2.sid<br \/>\nWHERE DP.authentication_type_desc IN ('INSTANCE','WINDOWS')<br \/>\n  AND DP.principal_id&gt;1<br \/>\n[\/sql]\n<\/div>\n<p>\nYou can see an example result of this query below:\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/List_of_orphaned_users.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/List_of_orphaned_users.jpg\" alt=\"List of orphaned users.\" title=\"List of orphaned users.\" width=\"816\" height=\"546\" class=\"aligncenter size-full wp-image-2354\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/List_of_orphaned_users.jpg 816w, https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/List_of_orphaned_users-300x200.jpg 300w, https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/List_of_orphaned_users-150x100.jpg 150w\" sizes=\"auto, (max-width: 816px) 100vw, 816px\" \/><\/a>\n<\/p>\n<p>\nThe query returns one row for each user in the current database. The <span class=\"tt\">has_name_match<\/span> column indicates if there is a login with the same name. Similarly, <span class=\"tt\">has_sid_match<\/span> indicates if a login with the same SID exists. This column however is not 0 or 1 but instead contains the name of the login if it exists and <span class=\"tt\">NULL<\/span> otherwise.\n<\/p>\n<p>\n <span class=\"tt\">is_name_sid_matched<\/span> equals <span class=\"tt\">1<\/span> if the same login matches our user in name and SID. <span class=\"tt\">name_sid_conflict<\/span> finally is <span class=\"tt\">1<\/span>, if the login that matches in name is already associated with another user in this database.\n<\/p>\n<h3>The Auto Fix Orphaned Users Query<\/h3>\n<p>\nNow we can identify users that need fixing and that also have a suitable login candidate with this <span class=\"tt\">WHERE<\/span> clause:\n<\/p>\n<div>\n[sql]\nWHERE has_name_match = 1<br \/>\n   AND has_sid_match IS NULL<br \/>\n   AND name_sid_conflict = 0<br \/>\n[\/sql]\n<\/div>\n<p>\nThe only step that remains is now to create the actual <span class=\"tt\">ALTER USER<\/span> statement:\n<\/p>\n<div>\n[sql]\nSELECT 'ALTER USER '+QUOTENAME(name)+' WITH LOGIN '+QUOTENAME(name)+';' AS cmd<br \/>\n[\/sql]\n<\/div>\n<p>\nThe expression uses the <span class=\"tt\">QUOTENAME<\/span> function to make sure that the generated statements work with oddly named users too.\n<\/p>\n<p>\nNow it is time to put all the pieces together:\n<\/p>\n<div>\n[sql]\nSELECT 'ALTER USER '+QUOTENAME(OU.name)+' WITH LOGIN '+QUOTENAME(OU.name)+';' AS cmd<br \/>\n  FROM(<br \/>\n       SELECT DP.name, DP.type_desc,<br \/>\n              CASE WHEN SP.sid IS NOT NULL THEN 1 ELSE 0 END has_name_match,<br \/>\n              CASE WHEN SP.sid = DP.sid THEN 1 ELSE 0 END is_name_sid_matched,<br \/>\n              CASE WHEN SP2.sid IS NOT NULL THEN SP2.name END has_sid_match,<br \/>\n              CASE WHEN dp2.sid IS NOT NULL THEN 1 ELSE 0 END name_sid_conflict<br \/>\n         FROM sys.database_principals AS DP<br \/>\n         LEFT JOIN sys.server_principals AS SP<br \/>\n           ON DP.name = SP.name COLLATE SQL_Latin1_General_CP1_CI_AS<br \/>\n         LEFT JOIN sys.database_principals AS DP2<br \/>\n           ON SP.sid = DP2.sid AND DP.principal_id &lt;&gt; DP2.principal_id<br \/>\n         LEFT JOIN sys.server_principals AS SP2<br \/>\n           ON DP.sid = SP2.sid<br \/>\n       WHERE DP.authentication_type_desc IN ('INSTANCE','WINDOWS')<br \/>\n         AND DP.principal_id&gt;1<br \/>\n      )OU<br \/>\n WHERE OU.has_name_match = 1<br \/>\n   AND OU.has_sid_match IS NULL<br \/>\n   AND OU.name_sid_conflict = 0<br \/>\n[\/sql]\n<\/div>\n<p>\nThis query takes all the rules we talked about into consideration and generates auto-fix statements for just those orphaned users that can be safely re-associated with an unambiguous login. The output in my case looks like this:\n<\/p>\n<p>\n<a href=\"http:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg\" alt=\"Generated auto fix orphaned user statements.\" title=\"Generated auto fix orphaned user statements.\" width=\"816\" height=\"546\" class=\"aligncenter size-full wp-image-2355\" srcset=\"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg 816w, https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements-300x200.jpg 300w, https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements-150x100.jpg 150w\" sizes=\"auto, (max-width: 816px) 100vw, 816px\" \/><\/a>\n<\/p>\n<h3>Final Thoughts<\/h3>\n<p>\nWhile it sounds simple, identifying the correct login to associate with an orphaned user is not completely trivial. But it can be done if you follow a few simple rules. The query that we came up with can be used to generate the statements necessary to auto fix orphaned users. However, it just generates those statements. Actually executing them I will leave to you as an exercise.\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>To auto fix orphaned users safely is a surprisingly complex task. But, as demonstrated in this article, it is possible if you follow a handful of rules.<\/p>\n<p> <a href=\"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/\">[more&#8230;]<\/a><\/p>\n","protected":false},"author":3,"featured_media":2355,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5,34],"tags":[59,166,38,58,56,15],"class_list":["post-2353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","category-security","tag-database-principals","tag-orphaned-users","tag-security-2","tag-security-management","tag-server-principals","tag-sql-server"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Auto Fix Orphaned Users - sqlity.net<\/title>\n<meta name=\"description\" content=\"To auto fix orphaned users safely is a surprisingly complex task. But, as demonstrated in this article, it is possible if you follow a handful of rules.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Auto Fix Orphaned Users - sqlity.net\" \/>\n<meta property=\"og:description\" content=\"To auto fix orphaned users safely is a surprisingly complex task. But, as demonstrated in this article, it is possible if you follow a handful of rules.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/\" \/>\n<meta property=\"og:site_name\" content=\"sqlity.net\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/sqlity.net\" \/>\n<meta property=\"article:published_time\" content=\"2014-04-18T15:00:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-13T17:30:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"816\" \/>\n\t<meta property=\"og:image:height\" content=\"546\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sebastian Meine\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sqlity\" \/>\n<meta name=\"twitter:site\" content=\"@sqlity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sebastian Meine\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/\"},\"author\":{\"name\":\"Sebastian Meine\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"headline\":\"Auto Fix Orphaned Users\",\"datePublished\":\"2014-04-18T15:00:45+00:00\",\"dateModified\":\"2014-11-13T17:30:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/\"},\"wordCount\":1330,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2014\\\/04\\\/auto-fix-orphaned-user-statements.jpg\",\"keywords\":[\"database principals\",\"orphaned users\",\"security\",\"security management\",\"server principals\",\"SQL Server\"],\"articleSection\":[\"General\",\"Security\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/\",\"name\":\"Auto Fix Orphaned Users - sqlity.net\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2014\\\/04\\\/auto-fix-orphaned-user-statements.jpg\",\"datePublished\":\"2014-04-18T15:00:45+00:00\",\"dateModified\":\"2014-11-13T17:30:11+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"description\":\"To auto fix orphaned users safely is a surprisingly complex task. But, as demonstrated in this article, it is possible if you follow a handful of rules.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/#primaryimage\",\"url\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2014\\\/04\\\/auto-fix-orphaned-user-statements.jpg\",\"contentUrl\":\"https:\\\/\\\/sqlity.net\\\/wp-content\\\/uploads\\\/2014\\\/04\\\/auto-fix-orphaned-user-statements.jpg\",\"width\":816,\"height\":546,\"caption\":\"Generated auto fix orphaned user statements.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/2353\\\/auto-fix-orphaned-users\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Auto Fix Orphaned Users\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\",\"name\":\"sqlity.net\",\"description\":\"Quality for SQL\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sqlity.net\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\",\"name\":\"Sebastian Meine\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g\",\"caption\":\"Sebastian Meine\"},\"sameAs\":[\"http:\\\/\\\/sqlity.net\",\"https:\\\/\\\/x.com\\\/sqlity\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Auto Fix Orphaned Users - sqlity.net","description":"To auto fix orphaned users safely is a surprisingly complex task. But, as demonstrated in this article, it is possible if you follow a handful of rules.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/","og_locale":"en_US","og_type":"article","og_title":"Auto Fix Orphaned Users - sqlity.net","og_description":"To auto fix orphaned users safely is a surprisingly complex task. But, as demonstrated in this article, it is possible if you follow a handful of rules.","og_url":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/","og_site_name":"sqlity.net","article_publisher":"https:\/\/www.facebook.com\/sqlity.net","article_published_time":"2014-04-18T15:00:45+00:00","article_modified_time":"2014-11-13T17:30:11+00:00","og_image":[{"width":816,"height":546,"url":"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg","type":"image\/jpeg"}],"author":"Sebastian Meine","twitter_card":"summary_large_image","twitter_creator":"@sqlity","twitter_site":"@sqlity","twitter_misc":{"Written by":"Sebastian Meine","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/#article","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/"},"author":{"name":"Sebastian Meine","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"headline":"Auto Fix Orphaned Users","datePublished":"2014-04-18T15:00:45+00:00","dateModified":"2014-11-13T17:30:11+00:00","mainEntityOfPage":{"@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/"},"wordCount":1330,"commentCount":0,"image":{"@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg","keywords":["database principals","orphaned users","security","security management","server principals","SQL Server"],"articleSection":["General","Security"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/","url":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/","name":"Auto Fix Orphaned Users - sqlity.net","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/#primaryimage"},"image":{"@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/#primaryimage"},"thumbnailUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg","datePublished":"2014-04-18T15:00:45+00:00","dateModified":"2014-11-13T17:30:11+00:00","author":{"@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"description":"To auto fix orphaned users safely is a surprisingly complex task. But, as demonstrated in this article, it is possible if you follow a handful of rules.","breadcrumb":{"@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/#primaryimage","url":"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg","contentUrl":"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg","width":816,"height":546,"caption":"Generated auto fix orphaned user statements."},{"@type":"BreadcrumbList","@id":"https:\/\/sqlity.net\/en\/2353\/auto-fix-orphaned-users\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sqlity.net\/en\/"},{"@type":"ListItem","position":2,"name":"Auto Fix Orphaned Users"}]},{"@type":"WebSite","@id":"https:\/\/sqlity.net\/en\/#website","url":"https:\/\/sqlity.net\/en\/","name":"sqlity.net","description":"Quality for SQL","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sqlity.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c","name":"Sebastian Meine","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4ab0a6d02dd494849a584a2c3c8bc3bdcef1d0aa5f87e98bf905dbdb9ad2ce3a?s=96&d=mm&r=g","caption":"Sebastian Meine"},"sameAs":["http:\/\/sqlity.net","https:\/\/x.com\/sqlity"]}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/sqlity.net\/wp-content\/uploads\/2014\/04\/auto-fix-orphaned-user-statements.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2wXuw-BX","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/2353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/comments?post=2353"}],"version-history":[{"count":0,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/2353\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/media\/2355"}],"wp:attachment":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/media?parent=2353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/categories?post=2353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/tags?post=2353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}