{"id":1770,"date":"2014-01-06T11:00:44","date_gmt":"2014-01-06T16:00:44","guid":{"rendered":"http:\/\/sqlity.net\/en\/?p=1770"},"modified":"2014-11-13T13:22:06","modified_gmt":"2014-11-13T18:22:06","slug":"using-database-roles-database-level-security-management","status":"publish","type":"post","link":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/","title":{"rendered":"Using Database Roles for Database Level Security Management"},"content":{"rendered":"<div>\n<h3>Introduction<\/h3>\n<p>\nOver the last two days I introduced you to <a href=\"http:\/\/sqlity.net\/en\/1759\/using-server-roles-server-level-security-management\/\">server roles<\/a> and their <a href=\"http:\/\/sqlity.net\/en\/1764\/member-management-server-roles\/\">member management<\/a>. Server roles can simplify the management of server level permissions. However, for database level permissions they are not the right tool.\n<\/p>\n<p>\nTo manage database level permissions SQL Server offers a similar solution: Database Roles. Any user that is a member of a database role inherits the permissions granted to that role.<br \/>\nThe only real difference between server roles and database roles is that database roles get defined in a particular database whereas server roles are defined for the entire server. Any member of a database role must be a principal defined in the same database that the role is defined in.\n<\/p>\n<h3>Create a Database Role<\/h3>\n<p>\nThe statement to create a database role is very similar to the one to create a server role:\n<\/p>\n<div>\n[sql]\nCREATE ROLE role_name [ AUTHORIZATION database_principal ];<br \/>\n[\/sql]\n<\/div>\n<p>\nNotice that the word <span class=\"tt\">DATABASE<\/span> is not part of this statement. Historically (before SQL 2012), SQL Server had only nine fixed server roles, so any user-defined role was a database role. So the word database was implied and not called out. That is reflected in the syntax of that create statement.\n<\/p>\n<p>\nThe statement has to be executed while inside the database that you want to create the role in and <span class=\"tt\">role_name<\/span> has to be unique within that database. The <span class=\"tt\">AUTHORIZATION<\/span> clause is optional and specifies the owner of the new role.\n<\/p>\n<p>\nAfter the role is created, permissions can be set with <span class=\"tt\">GRANT<\/span>, <span class=\"tt\">DENY<\/span> or <span class=\"tt\">REVOKE<\/span> and members can be added with the <span class=\"tt\">ALTER ROLE<\/span> statement.\n<\/p>\n<h3>Permissions<\/h3>\n<p>\nPermissions that can be granted to a role are all local to the database including for example <span class=\"tt\">CONNECT<\/span> to the database, <span class=\"tt\">CREATE SCHEMA<\/span> or <span class=\"tt\">SELECT<\/span> from a table. Any permission granted to the role will be effective for all its members.\n<\/p>\n<h3>Fixed Database Roles<\/h3>\n<p>\nSQL Server comes with nine fixed database roles, the most prominent being <span class=\"tt\">db_owner<\/span>.  Similar to the fixed server roles, the fixed database roles cannot be changed. Any attempt to grant or deny permissions to a fixed database role will result in an error.\n<\/p>\n<h3>Summary<\/h3>\n<p>\nUser-defined database roles provide the same maintenance simplification on a database level that server roles offer on the server level.  SQL Server comes with nine fixed database roles out of the box that address common job requirements. Permissions granted to a database role get inherited by every member of that role.\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Database roles simplify security management on a database level. With database roles we can grant or deny permissions to a group of database users. Find out how you can use database roles in your environment.<\/p>\n<p> <a href=\"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/\">[more&#8230;]<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"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":[29,5,34],"tags":[18,57,50,38,58,15],"class_list":["post-1770","post","type-post","status-publish","format-standard","hentry","category-fundamentals","category-general","category-security","tag-best-practice","tag-database-roles","tag-permission","tag-security-2","tag-security-management","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>Using Database Roles for Database Level Security Management - sqlity.net<\/title>\n<meta name=\"description\" content=\"Database roles simplify security management on a database level. With database roles we can grant or deny permissions to a group of database users. Find out how you can use database roles in your environment.\" \/>\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\/1770\/using-database-roles-database-level-security-management\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Database Roles for Database Level Security Management - sqlity.net\" \/>\n<meta property=\"og:description\" content=\"Database roles simplify security management on a database level. With database roles we can grant or deny permissions to a group of database users. Find out how you can use database roles in your environment.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/\" \/>\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-01-06T16:00:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-13T18:22:06+00:00\" \/>\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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/\"},\"author\":{\"name\":\"Sebastian Meine\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"headline\":\"Using Database Roles for Database Level Security Management\",\"datePublished\":\"2014-01-06T16:00:44+00:00\",\"dateModified\":\"2014-11-13T18:22:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/\"},\"wordCount\":434,\"commentCount\":0,\"keywords\":[\"Best Practice\",\"database roles\",\"Permission\",\"security\",\"security management\",\"SQL Server\"],\"articleSection\":[\"Fundamentals\",\"General\",\"Security\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/\",\"url\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/\",\"name\":\"Using Database Roles for Database Level Security Management - sqlity.net\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#website\"},\"datePublished\":\"2014-01-06T16:00:44+00:00\",\"dateModified\":\"2014-11-13T18:22:06+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/#\\\/schema\\\/person\\\/bcffd8c572bc2f1bd10fdba80135e53c\"},\"description\":\"Database roles simplify security management on a database level. With database roles we can grant or deny permissions to a group of database users. Find out how you can use database roles in your environment.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sqlity.net\\\/en\\\/1770\\\/using-database-roles-database-level-security-management\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sqlity.net\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using Database Roles for Database Level Security Management\"}]},{\"@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":"Using Database Roles for Database Level Security Management - sqlity.net","description":"Database roles simplify security management on a database level. With database roles we can grant or deny permissions to a group of database users. Find out how you can use database roles in your environment.","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\/1770\/using-database-roles-database-level-security-management\/","og_locale":"en_US","og_type":"article","og_title":"Using Database Roles for Database Level Security Management - sqlity.net","og_description":"Database roles simplify security management on a database level. With database roles we can grant or deny permissions to a group of database users. Find out how you can use database roles in your environment.","og_url":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/","og_site_name":"sqlity.net","article_publisher":"https:\/\/www.facebook.com\/sqlity.net","article_published_time":"2014-01-06T16:00:44+00:00","article_modified_time":"2014-11-13T18:22:06+00:00","author":"Sebastian Meine","twitter_card":"summary_large_image","twitter_creator":"@sqlity","twitter_site":"@sqlity","twitter_misc":{"Written by":"Sebastian Meine","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/#article","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/"},"author":{"name":"Sebastian Meine","@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"headline":"Using Database Roles for Database Level Security Management","datePublished":"2014-01-06T16:00:44+00:00","dateModified":"2014-11-13T18:22:06+00:00","mainEntityOfPage":{"@id":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/"},"wordCount":434,"commentCount":0,"keywords":["Best Practice","database roles","Permission","security","security management","SQL Server"],"articleSection":["Fundamentals","General","Security"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/","url":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/","name":"Using Database Roles for Database Level Security Management - sqlity.net","isPartOf":{"@id":"https:\/\/sqlity.net\/en\/#website"},"datePublished":"2014-01-06T16:00:44+00:00","dateModified":"2014-11-13T18:22:06+00:00","author":{"@id":"https:\/\/sqlity.net\/en\/#\/schema\/person\/bcffd8c572bc2f1bd10fdba80135e53c"},"description":"Database roles simplify security management on a database level. With database roles we can grant or deny permissions to a group of database users. Find out how you can use database roles in your environment.","breadcrumb":{"@id":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/sqlity.net\/en\/1770\/using-database-roles-database-level-security-management\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sqlity.net\/en\/"},{"@type":"ListItem","position":2,"name":"Using Database Roles for Database Level Security Management"}]},{"@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":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2wXuw-sy","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/1770","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=1770"}],"version-history":[{"count":0,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/posts\/1770\/revisions"}],"wp:attachment":[{"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/media?parent=1770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/categories?post=1770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sqlity.net\/en\/wp-json\/wp\/v2\/tags?post=1770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}