Needs to change default database for all logins. help me

  • hi

    I have some 1400 logins. I have to change default database for all this logins. Can i update syslogins table? will there be any problem if i do that? I have to point all 1400 logins to the same database.

    Thanks in advance

  • This should do the job:

    DECLARE @login nvarchar(128), @isql nvarchar(2000)

    DECLARE c1 CURSOR FOR

    SELECT name from syslogins where name <>'sa'

    OPEN c1

    FETCH NEXT FROM c1

    INTO @login

    WHILE @@FETCH_STATUS <> -1

    BEGIN

    SET @isql = 'EXEC sp_defaultdb ' + QUOTENAME(@login, '''') + ' , ''YourDatabase'''

    Exec sp_executesql @isql

    FETCH NEXT FROM c1

    INTO @login

    END

    CLOSE c1

    DEALLOCATE c1

    Just change the name to your database name and maybe you need to exclude some more logins besides "sa".

    [font="Verdana"]Markus Bohse[/font]

  • How about update master..sysxlogins?

    UPDATE master..sysxlogins SET dbid = ? WHERE ...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply