Friday, March 23, 2007

Sybase add user error

Error Message
Server Message: Number 17331, Severity 16
Server 'SYBASE', Procedure 'sp_adduser', Line 253:
User already has a login under a different name.

use the following sp

CREATE PROCEDURE drop_user_null_userdb
AS
DECLARE @username VARCHAR(25)
DECLARE GetOrphanUsers CURSOR
FOR
select Username = name
from userdb..sysusers
where suid not in(select suid from master..syslogins) and gid = 16390 and suid != -2

OPEN GetOrphanUsers
FETCH GetOrphanUsers
INTO @username

WHILE @@sqlstatus = 0
BEGIN

exec sp_dropuser @username


FETCH GetOrphanUsers
INTO @username
END

gid and suid need to change before exec