Home >> FAQs/Tutorials >> SQL Server FAQ

SQL Server FAQ - User_Name() - Database Level Security Principal of Your Session

By: FYIcenter.com

(Continued from previous topic...)

What Is the Security Principal at the Database Level That Represents Your Session?

Security principal identifies who you are when you interact with the SQL Server. What can do you at the database solely depends on the security principal that represents you. So it is very important to know your security principal at the database level.

What is the database level security principal of your session? The answer is simple - the user name in the current database that has been mapped to your login name. For example, if you connects to the server with the login name "sa", and sets "FyiCenterData" as the current database, SQL Server will map "sa" to a user name defined in "FyiCenterData" based on some logics. That mapped user name is your security principal for "FyiCenterData" at the database level.

On a Unix system, there is a nice command called "whoami" which returns your security principal on the system. SQL Server provides a similar function called User_Name(), which returns your security principal (a user name mapped to the login name) at the database level. Try it by following this tutorial example:

PRINT Suser_Sname();
GO
sa

USE FyiCenterData;
GO

-- Find out your security principal at the database level
PRINT User_Name();
GO
dbo

This example shows you that "dbo" is user name in "FyiCenterData" that mapped to login name "sa".

(Continued on next topic...)

  1. What Is the Security Model Used in SQL Server 2005?
  2. What Are Security Principals Used in SQL Server 2005?
  3. What Is the Security Principal at the Server Level That Represents Your Session?
  4. What Is the Security Principal at the Database Level That Represents Your Session?
  5. How To Create a New Login Name in SQL Server?
  6. How To Verify a Login name with SQLCMD Tool?
  7. How To List All Login Names on the Server?
  8. How To Change the Password of a Login Name?
  9. How To Change a Login Name?
  10. How To Disable a Login Name?
  11. How To Delete a Login Name?
  12. How To Create a User Name in a Database?
  13. How To List All User Names in a Database?
  14. How To Find the Login Name Linked to a Given User Name?
  15. How To Verify a User name with SQLCMD Tool?
  16. How To Change the Name of a Database User?
  17. How To Delete an Existing Database User?

Related Articles:

More...


Other Tutorials/FAQs:

More...


Related Resources:

More...


Selected Jobs:

More...