I've scripted out the Roles from a specific db to import into the MSDB under System databases (why is not relevant, it's what i was told to do). The script will be run against a new server where other databases are being restored to. The script is obviously a bunch of "Create Role" lines for the roles themselves, however, i need each line to check if the role already exists. For instance i have
Use [msdb]
Create Role [DatabaseMailUserRole] AUTHORIZATION [dbo]
GO
I assume using an IF EXISTS would look something like this:
use msdb
IF EXISTS (SELECT * FROM (what goes here?) WHERE ROLE=[DatabaseUserRole]) ELSE
Create Role [DatabaseMailUserRole] AUTHORIZATION [dbo]
GO
I should also add that i need to script out the roles from the other databases which are being backed up from one server and restored to another as it appears that the roles and some other objects are not being restored when these backup/restores are being done.
Just wondering if i'm approaching this correctly.
thanks
james