SYS USERS Table

We are using suid > 2 and altuid = 0 to know if it is not system user but a application user.
This is working in most of the cases
The only problem when we restore a backup of one server DB to a DB on another it is setting suid to null as corresponding users may not have logins in this server.

to overcome this I am using ((Uid > 3 and suid=null) or suid > 2) and altuid = 0.

can any one suggest me a better way to do what we are doing now.
LVL 1
VnagarajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jboydCommented:
Hi Vinay... How are things at Phoenix... Kostas asked me the same question about a week ago and here are a few things you may want to try. Use sp_change_users_login with the "report" option to get a list of the users in database that do not have valid logins. Put the results of the stored procedure into a table that you can then reference for your script to create the logins. You can then also use the "AutoFix" option to remap the the relationship between syslogins and sysusers for people that did already have an entry in both tables.

Hope this helps,
Jeff Boyd
0
VnagarajAuthor Commented:
Jeff,
things are fine,

I am looking for any answer which will be based around sysusers. I want an answer where I can recognise a user is sytem or application created. I will reject it for now.

vinay
0
VnagarajAuthor Commented:
Increased to 150
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

jboydCommented:
Hi Vinay... Sorry that wasn't what you were looking for. Are you guys still using SQL Server authentication vs. NT authentication? I did a little testing to try to reproduce the problem you are seeing. I tried moving databases around four different servers here and I could not reproduce the problem of user SUIDs going NULL? I tried both the backup and restore and sp_detach_db and sp_attach_db methods to move the database but the the user SUIDs always came through even when no login for the user existed on the server. The one thin that I did notice was the roles always have an SUID of NULL. Could the user reset routine be having problems with roles? If this is the case you can exclude the roles from our select of sysusers by adding "issqlrole = 0" to your where clause.
0
Gustavo Perez BuenrostroCommented:
Try next query and let me know your opinion:

select UserName=name
      ,UserSID=sid
  from sysusers
 where issqluser=1 and
      (sid is not null and sid <> 0x0)and
       suser_sname(sid) is null
0
jboydCommented:
gpbuenrostro, I think your query excludes SID that are NULL, but he states that valid users SIDs are getting set to NULL when a database is restored to a different server. I could not reproduce this situation... Can anyone else out there?
0
VnagarajAuthor Commented:
gpbuenrostro

Suid is null  but not sid and I think u'r query helps.  I will use it with existing to check for this special Case.

for both of u'r efforts I will award 75 points each. post answers and pick them up
0
VnagarajAuthor Commented:
gpbuenrostro

post u'r comment as answer and pick it up
0
Gustavo Perez BuenrostroCommented:
Vnagaraj,
It was a pleasure to help you.
Please, Post the final approach.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VnagarajAuthor Commented:
select name
from sysusers
 where (uid > 1 and
      (sid is not null and sid <> 0x0 and suid is null)) or suid > 2

this what I am thinking of using now.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.