Friday, January 7, 2011

Update SQL Server Login After Restoring Database from Another Server

One useful SQL Server 2005 stored procedure is sp_change_users_login.
After I move Database from one server to another server by "backup and restore", I called this command below to update the username "MyUserName" in the database "MyDB".

Use MyDB;
EXEC sp_change_users_login 'update_one', 'MyUserName', 'MyUserName';

The purpose is to map an existing user in a database to a Microsoft® SQL Server™ login. Only after doing this, I can use account "MyUserName" to login to the newly restored DB.
Note that if the database are backup and restored from the same server, no need to call the above commands.

More details of this command can be found at:
http://msdn.microsoft.com/en-us/library/aa259633%28v=sql.80%29.aspx

New Year New Blog

As a software developer, sometimes I found myself keep looking for common commands or code snippets to use in my programming practice. I think it's a good idea to write a blog about those common commands or tricks that I found useful in my job. So here it comes: my first blog.

Hau'oli Makahiki Hou (Happy new year in Hawaiian).