Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SUSER_NAME() vs SUSER_SNAME() Expand / Collapse
Author
Message
Posted Tuesday, April 12, 2011 5:40 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 9:44 AM
Points: 178, Visits: 186
Any reason to use one of the following over the other to return the user currently modifying data?

SELECT SUSER_NAME()
SELECT SUSER_SNAME()

The documentation for SUSER_NAME() says "SUSER_NAME returns a login name only for a login that has an entry in the syslogins system table.".
SUSER_SNAME() documentation makes no reference to this does this imply that SUSER_NAME is more limited in some way than SUSER_SNAME?
Post #1091981
Posted Tuesday, April 12, 2011 6:52 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: 2 days ago @ 1:11 PM
Points: 12,905, Visits: 32,161
I think you are supposed to use SUSER_SNAME() in most situations.

i believe the difference is SUSER_SNAME() would return a domain\username for those people who are not explicitly on the server, but only get access through an inherited role;

so if you grant a windows role access, SUSER_SNAME() would return results, but SUSER_NAME() is blank, because that user is not explicitly in the sys.server_principals table, right?


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1092027
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse