Reconnect an SQL login to a user

Sometimes a user in a database gets disconnected from a server login and you can re-map the login to the database as the user is already there.

This usually happens after you restore a database to a server.

So the following gived you a report of all the disconnected users:

sp_change_users_login report

And this remaps a login(tramdba(server login)) to a user(tramdba(user))

sp_change_users_login update_one,,

thanks

RuSs

Advertisements

Batch Deleting in T-SQL


DECLARE @BatchSize int

DECLARE @Rows int

SET @Rows = 1

SET @BatchSize = 100000

WHILE (@Rows > 0)

BEGIN

delete TOP (@BatchSize) FROM PropertyMonthProperty
from PropertyMonthProperty PMP
inner join Property P
on
PMP.propertyid = P.propertyid
where
p.scenarioid = 14149

SET @Rows = @@ROWCOUNT

END