{"id":4654,"date":"2015-02-06T04:28:45","date_gmt":"2015-02-06T04:28:45","guid":{"rendered":"http:\/\/www.top-password.com\/blog\/?p=4654"},"modified":"2015-02-06T04:30:12","modified_gmt":"2015-02-06T04:30:12","slug":"difference-between-sql-server-logins-and-database-users","status":"publish","type":"post","link":"https:\/\/www.top-password.com\/blog\/difference-between-sql-server-logins-and-database-users\/","title":{"rendered":"Difference Between SQL Server Logins and Database Users"},"content":{"rendered":"<p>Although the words logins and users are often used interchangeably, they are very different things in Microsoft SQL Server. There has always been confusion over logins and users, especially for most new SQL Server users. Here I&#8217;ll explain the difference between SQL Server logins and database users.<\/p>\n<p><strong>Part 1: Logins vs. Users<\/strong><\/p>\n<p>Logins are created at the server level, while users are created at the database level. In other words, a login allows you to connect to the SQL Server service (also called an instance), and permissions inside the database are granted to the database users, not the logins. The logins will be assigned to server roles (for example, <em>serveradmin<\/em>) and the database users will be assigned to roles within that database (eg. <em>db_datareader<\/em>, <em>db_bckupoperator<\/em>).<\/p>\n<p>Logins must be mapped to a database user to connect to a database. If your login is not mapped to any database user, you can still connect to SQL Server instance using SQL Server Management Studio (SSMS), but you&#8217;re not allowed to access any objects in the database. To access any objects in the database, you must have a login that&#8217;s mapped to a user in the database, and that user must be granted appropriate rights in the database.<\/p>\n<p>The database user does not have credentials of its own and relies on the server login for authentication. This means that there is no password associated with a database user. Below we&#8217;ll walk you through the steps of creating a new login and user, mapping a user to a login.<\/p>\n<p><strong>Part 2: Create A New Login<\/strong><\/p>\n<p>To create a SQL Server login, please follow these steps:<\/p>\n<ol>\n<li>Open SQL Server Management Studio and connect to your SQL Server instance.<\/li>\n<li>In the Object Explorer panel (located on the left side), expand the server where you want to create a new login. Expand the <strong>Security<\/strong> option, right-click on <strong>Logins<\/strong> and then select <strong>New Login<\/strong>.\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2015\/02\/sql-server-login.png\" alt=\"sql-server-login\" width=\"600\" height=\"361\" class=\"alignnone size-full wp-image-4665\" \/><\/p>\n<\/li>\n<li>In the <strong>Login &#8211; New<\/strong> dialogue that appears, enter a new login name. In this example, I create a new login named <em>jack<\/em> and choose SQL Server authentication. Uncheck the box labeled &#8220;User must change password at next login&#8221;.\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2015\/02\/new-sql-server-login.png\" alt=\"new-sql-server-login\" width=\"600\" height=\"539\" class=\"alignnone size-full wp-image-4666\" \/><\/p>\n<\/li>\n<li>Click <strong>OK<\/strong> to create a new SQL Server login.<\/li>\n<\/ol>\n<p>Till now I haven&#8217;t set up User Mapping for the new login <em>jack<\/em>, so there is no database users mapped to this login currently. You can check out this at the Login Properties window by right-clicking the newly-created login and select Properties.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2015\/02\/no-user-mapping.png\" alt=\"no-user-mapping\" width=\"600\" height=\"539\" class=\"alignnone size-full wp-image-4667\" \/><\/p>\n<p>I can then use SQL Server Management Studio to connect to the SQL Server instance with this login. But when I try to expand the database <em>test<\/em>, I got the following error message due to lack of database permissions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2015\/02\/cannot-access-database.png\" alt=\"cannot-access-database\" width=\"600\" height=\"353\" class=\"alignnone size-full wp-image-4668\" \/><\/p>\n<p>In order to get access to a specific database, we need to create a new database user and map it to the login <em>jack.<\/em><\/p>\n<p><strong>Part 3: Create A New User<\/strong><\/p>\n<p>To create a database user, please follow these steps:<\/p>\n<ol>\n<li>Open SQL Server Management Studio and connect to your SQL Server instance.<\/li>\n<li>In the Object Explorer panel (located on the left side), Expand the database in which to create the new database user.<\/li>\n<li>Expand <strong>Security<\/strong> and then <strong>Users<\/strong>. Right-click on <strong>Users<\/strong> and then select <strong>New User<\/strong>.\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2015\/02\/sql-database-user.png\" alt=\"sql-database-user\" width=\"600\" height=\"445\" class=\"alignnone size-full wp-image-4669\" \/><\/p>\n<\/li>\n<li>In the <strong>Database User &#8211; New<\/strong> dialogue that appears, select <strong>SQL user with login<\/strong> from the User type list, and enter a name for the new database user.\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2015\/02\/new-sql-database-user.png\" alt=\"new-sql-database-user\" width=\"600\" height=\"539\" class=\"alignnone size-full wp-image-4670\" \/><\/p>\n<p>In this example, I create a new database user named <em>jack_user<\/em>, and set jack as the Login name as I want to map this database user to the login <em>jack<\/em> I created previously.<\/li>\n<li>Click <strong>OK<\/strong> to create the user.<\/li>\n<\/ol>\n<p>Once the database user is created, check out the Login Properties for the login <em>jack<\/em> and you&#8217;ll find the database user <em>jack_user<\/em> is now mapped to the login.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2015\/02\/user-mapped-to-login.png\" alt=\"user-mapped-to-login\" width=\"600\" height=\"539\" class=\"alignnone size-full wp-image-4671\" \/><\/p>\n<p>At this time you can connect to the SQL Server service with the login <em>jack<\/em>, and expand the database test without permission issue. <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.top-password.com\/blog\/wp-content\/uploads\/2015\/02\/gain-database-access.png\" alt=\"gain-database-access\" width=\"600\" height=\"334\" class=\"alignnone size-full wp-image-4672\" \/><\/p>\n<p>That&#8217;s it! I hope this article would be helpful for you to understand the difference between a login and a user in SQL Server.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Although the words logins and users are often used interchangeably, they are very different things in Microsoft SQL Server. There has always been confusion over logins and users, especially for most new SQL Server users. Here I&#8217;ll explain the difference between SQL Server logins and database users. Part 1: Logins vs. Users Logins are created [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,10],"tags":[2068,2067,2070,2069],"class_list":["post-4654","post","type-post","status-publish","format-standard","hentry","category-sql-server","category-tips-tricks","tag-create-sql-server-login","tag-sql-server-create-new-user","tag-sql-server-login-user-mapping","tag-sql-server-login-vs-user"],"_links":{"self":[{"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/posts\/4654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/comments?post=4654"}],"version-history":[{"count":16,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/posts\/4654\/revisions"}],"predecessor-version":[{"id":4678,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/posts\/4654\/revisions\/4678"}],"wp:attachment":[{"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/media?parent=4654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/categories?post=4654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.top-password.com\/blog\/wp-json\/wp\/v2\/tags?post=4654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}