
-- Deletes IONMaintenance User
-- Adds new IONMaintenance User to all 4 DBs and the Security
-- Edit [MyComputer\IONMaintenance] to use the computer name the script is running on. Change 6 instances of MyComputer with system name.


USE [ApplicationModules]
GO
DROP USER [IONMaintenance]
GO

USE [ION_Data]
GO
DROP USER [IONMaintenance]
GO

USE [ION_Network]
GO
DROP USER [IONMaintenance]
GO

USE [ION_SystemLog]
GO
DROP USER [IONMaintenance]
GO

USE [master]
GO
DROP LOGIN [MyComputer\IONMaintenance]
GO

-- 

USE [master]
GO
CREATE LOGIN [MyComputer\IONMaintenance] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
GO

USE [ApplicationModules]
GO
CREATE USER [IONMaintenance] FOR LOGIN [MyComputer\IONMaintenance]
GO
USE [ApplicationModules]
GO
ALTER ROLE [db_backupoperator] ADD MEMBER [IONMaintenance]
GO
USE [ApplicationModules]
GO
ALTER ROLE [db_ddladmin] ADD MEMBER [IONMaintenance]
GO
USE [ApplicationModules]
GO
ALTER ROLE [Maintenance] ADD MEMBER [IONMaintenance]
GO

USE [ION_Data]
GO
CREATE USER [IONMaintenance] FOR LOGIN [MyComputer\IONMaintenance]
GO
USE [ION_Data]
GO
ALTER ROLE [db_backupoperator] ADD MEMBER [IONMaintenance]
GO
USE [ION_Data]
GO
ALTER ROLE [db_ddladmin] ADD MEMBER [IONMaintenance]
GO
USE [ION_Data]
GO
ALTER ROLE [Maintenance] ADD MEMBER [IONMaintenance]
GO

USE [ION_Network]
GO
CREATE USER [IONMaintenance] FOR LOGIN [MyComputer\IONMaintenance]
GO
USE [ION_Network]
GO
ALTER ROLE [db_backupoperator] ADD MEMBER [IONMaintenance]
GO
USE [ION_Network]
GO
ALTER ROLE [db_ddladmin] ADD MEMBER [IONMaintenance]
GO
USE [ION_Network]
GO
ALTER ROLE [Maintenance] ADD MEMBER [IONMaintenance]
GO

USE [ION_SystemLog]
GO
CREATE USER [IONMaintenance] FOR LOGIN [MyComputer\IONMaintenance]
GO
USE [ION_SystemLog]
GO
ALTER ROLE [db_backupoperator] ADD MEMBER [IONMaintenance]
GO
USE [ION_SystemLog]
GO
ALTER ROLE [db_ddladmin] ADD MEMBER [IONMaintenance]
GO
USE [ION_SystemLog]
GO
ALTER ROLE [Maintenance] ADD MEMBER [IONMaintenance]
GO