sqlserver login name and user name of the differences and connections - with pre-existing - follow-up study (rpm)

sqlserver login name and user name of the differences and connections - with pre-existing - follow-up study

In summary: enter the login name can be understood as the key to the whole building, the user name can be understood as the key to a room, building here is the sql server server, but the room is this specific sql server server library, pay attention to the login name is present in the syslogins table in the master database, the user name is established under each specific library (that is, first enter the various libraries), the key is: can a login name and user in a number of different libraries do mapping , but in the same library and a user can only do mapping, and a user name can have multiple logins mapping relationship, the real authority is the user name, simply use the login name to board into a database, and then go user name mapping looking for, so I have the appropriate authority, has just started to build the login name as long as the login server role is set to database Creator, you can create a new database, and the establishment of this new database will automatically generates two username: dbo and guest. And the newly established and dbo login name on the map, and there is also rbo sa mapped, because rbo as an administrator user sa login and each library mapping.

1.// according to the database overview (Wang Shan edition, custom mode)

create schema test authorization guest

create table tab1(col1 smallint,

col2 int,

col3 char(20),

col4 numeric (10,3)

col5 decimal(5,2)

);

2. concepts elaborated

Login: a server-side entity, the use of a login name can only enter the server, but can not allow the user to access the resource database server. The definition of each login name is stored in the syslogins table in the master database

Username: mapping one or more objects in the database login, you can authorize the user object in order to provide access to the database for the target to be registered. User-defined information is stored in each database sysusers table.

SQLSERVER the relationship with the user login name is called mapping. After logging in with the login name SQLSERVER, when accessing various databases, SQLSERVER will automatically check whether there is a user name and login are associated with this database, if there is permission to use this user to access this database, if there is a guest user access this database (guest is a special user name will be mentioned later).

A login name can be granted access to multiple databases, but a login name in each database can only be mapped once. I.e. may correspond to a plurality of user login, a user may be using a plurality of log. Like SQLSERVER as a building, each room is inside a database. Just login into the keys to the building, and the user name is entered the room key. Login name can have a key multiple rooms, but a login name in a room can only have a key to this room.

Link or log Sql Server server login name is used instead of the user's login name, user name, program the link inside the string also refers to the login name.

3.SQLSERVER There are several special login name and user name:

The most common dbo (username) is a user with sa (login name) or windows administration (Windows integrated authentication login) login, which means that the database administrator username in the SQLSERVER called dbo, not called sa it looks a bit strange, because usually the same user name and login name (the same is not mandatory, but using the same login name is usually the time to glance at creating a user name), for example, create a login name for me, then can me add that login name in the specified database, a user of the same name, the login name me able to access data in the database. when a user is added after me in the database, then log in as me login name in the database all objects (tables, functions, stored procedures, etc.) are created by the owner of me, as me.table1, me.fn_test (), rather than dbo.table1, dbo.fn_test ().

There is also a special SQL Server database role public, it exists in every database, including database systems, such as the master, msdb, model and user databases, user databases are all part of the public role and can not be removed from the public role .

In SQLSERVER database, guest account is a special user account. If you use a database accessible USE database statement is not associated with this user account, the user is associated with the guest user.

In addition SQLSERVER take login - user name of safety rules, and a bit like Oracle schema inside. SQLSERVER use qualifying them by owner (similar schema Oracle in), because different users may create objects of the same name, such as a login name and login name me you were in the pubs database to create a user name me and you, these two users are created with this testtable watches, and although these two tables with the same name but the structure or data may be completely different, in order to avoid calling errors, you must limit the use of the name of the owner.

? 4. How to call objects created by other users such as me do users access tables you access user-created or table dbo created this situation, two conditions must be met:

1. The user database roles me to db_owner, otherwise inaccessible objects to other users (including dbo user) created (Enterprise Manager -> user, right-click menu <property> set):

2. Use the owner to limit access to such as me testtable you created:.. Select * from you.testtable In addition, dbo user as the administrator, the system gives all of its rights, you can call any user-created objects if a database exists two or more than two user name if the user has the db_owner role omitted from the owner when accessing objects, the system first looks up the user's object, if no then find dbo user has the same name as objects in the library inside For example: select * from testtable or select * from pubs..testtable

Experiment: Note l create a login login_ibrahim

l With this login name "Query Analyzer" and found only view system comes with a database, such as the master, Northwind, pubs, etc.

l The login name login_ibrahim server role is set to Database Creator (if not set this, you can not create a database)

l Enter the create database test in the "Query Analyzer", and then executed, which creates a database named test

l see the usernames test database has found the system automatically creates a dbo and guest both user name. Where the dbo user name corresponding login name login_ibrahim, can not change the username dbo test database login login_ibrahim corresponding to, at this time dbo user name test database, which corresponds to the login name there are two, one is login_ibrahim, and the other is sa (^ _ ^ did not expect it, because members of the sysadmin fixed server role automatically mapped to dbo.) l create a login login_ibrahim2, does not set any server role can access the database to test

l Open list of usernames test database, you will find the system will automatically create a user name login_ibrahim2 the same name as the login name login_ibrahim2, and then create a data table called the T_ibrahim

l this time with login_ibrahim2 login SQLSERVER, can not create a table found in the test database

l with login_ibrahim login SQLSERVER, db_ddladmin granted permission to test the database for the user name login_ibrahim2

A log l SQLSERVER with login_ibrahim2, found to create a data table (creation of data tables is called T_ibrahim), and inserting data.

Guess you like

Origin www.cnblogs.com/LiZhongZhongY/p/11488651.html