1

I need to copy a SQL Server Express database from one one server to another (virtual) server.

I know how to do this for the database itself - with a backup and restore. I have also looked at this and this which show how to script this - that's great.

However, I also need the permissions to go with it but can't figure out how to do that.

Any pointers would be warmly welcomed.

Community
  • 1
  • 1
Chris
  • 1,449
  • 1
  • 18
  • 39

2 Answers2

1

The logins need to exist already on the destination server, but once they exist, you can wire-up the logins back to the users with a script like this:

sp_change_users_login 'Update_One', 'user-name', 'login-name'

More information on sp_change_users_login can be found on MSDN

Logins are at a server level. Users are at a per-database level. Generally I keep the login name and user name the same to avoid confusion, but they can be different. The Users define the permissions within the database and you've not lost them, just the link to the login.

Colin Mackay
  • 18,736
  • 7
  • 61
  • 88
1

As an alternative to sp_change_users_login

 ALTER USER username WITH LOGIN = newlogin
podiluska
  • 50,950
  • 7
  • 98
  • 104