Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


SYSTEM_USER vs USER_ID(SYSTEM_USER) as default values


SYSTEM_USER vs USER_ID(SYSTEM_USER) as default values

Author
Message
aleksandar.ivanovski
aleksandar.ivanovski
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 55
Dear,

I have a huge database with millions of rows all containing SYSTEM_USER value.
The column value is defined as default
CREATE DEFAULT [dbo].[A_User] AS SYSTEM_USER

My idea is to get the ID instead of nvarchar value in order to shrink the table size and have a better query result over ids.

Now, I have few questions:
1. I can get the ID's via USER_ID(SYSTEM_USER), trough default column definition. However If I move the users to another table the values might be different so all things will be mixed up
2. If I use linked servers, (or move the DB to the DR site) will I have problems regarding different IDs
3. If I want to use sysusers table, I cannot write select nor UDF in the default definition.

Is there any more intelligent way to get the same functionality another way or should I use the master database and some login values???

Thanks
Aleksandar
Erland Sommarskog
Erland Sommarskog
SSC Eights!
SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)SSC Eights! (931 reputation)

Group: General Forum Members
Points: 931 Visits: 866
Maybe you should keep the default as it is.

You could use user_id() and this returns sys.principals.principal_id. The value would not change if the database is moved to a different server. This works well, as long as everyone has a user defined in the database.

However, in many places this is not likelyt to be the case, but users get access through Windows groups. In that case everyone will map to the same ID.

Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search