Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using SUSER_ID() or similiar

Author  Topic 

Racho
Starting Member

13 Posts

Posted - 2009-08-28 : 04:15:26
New to SQL Server so would appreciate some help.

I want a column to default to a unique integer UserID

I've looked at SUSER_NAME()which returns 'ServerName\LoginName'

But apart from being more verbose has the disadvantage that (in our organisation we use a firstname+lastname logins, and therefore) when our females marry their logins often change.

So I then looked at doing a lookup on the returned SUSER_NAME() value on our STAFF table and getting the integer UserId that way. This is fine for 1 or 100 or 1000 records, but I guess there is an overhead to doing this if the system is asked to write to a 'CreatedBy' or a 'ModifiedBy' (or both) column a few million times in a batch update or create process?

So I then looked at SUSER_(ID)which does appear to be returning a unique integer, but it is not clear from the documentation and reference material I have wether in msSQL2008 this number remains unique against that particular login (and does a new number get created if on change of name at marriage the login changes)

Can an SQL guru come to my aid on this and tell me if SUSER_ID() will do the trick or alternatively what is the best way to achieve my goal of using a unique numeric integer Id for each member of staff?

Thanks

SQL2008 and Visual Studio 2008 (VB Preferred)
   

- Advertisement -