[SQL Server] 如何修改user / login 的mapping

有時搬SQL server 時, 正路的方法, 當然是於新DB server 建立schema及相關user privilage, 再透過ETL 將data full load 過去, 然後再從application level 修改 connection string 指往新DB server. 但有時只有一個bak file, restore 後再建立login 時, 會出現user group already existed的錯誤訊息. 這是因為與DB user name 的名字相同所致.

若在須要保留相同user name 下, 便須要執行SP sp_change_users_login 指回正確的user / login.

語法如下:

EXEC sp_change_users_login 'Update_One', '<<user name>>', '<<login name>>';

Reference

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.