Script for Altering Roles in SSMS

What I do manually using available tools in SSMS:

  1. Alter ROLE [dbo_owner] to [dbo]
  2. Drop a User
  3. Drop LOGIN for that User
  4. Create LOGIN WITH PASSWORD
  5. Create User for LOGIN
  6. Alter ROLE [dbo_owner] ADD Member
  7. Alter AUTHORIZATION ON SCHEMA to [dbo_owner]

Wondering how I can put this script together to make my job easier.

Tha

July 8th, 2015 12:01pm

Hope it helps

USE[Database_Name]
GO
ALTER AUTHORIZATION ON ROLE::[db_owner] TO [dbo]
GO
DROP USER <User_Name>
GO
DROP LOGIN <Login_Name>
GO
CREATE LOGIN [Login_Name] WITH PASSWORD = '<Password>', DEFAULT_DATABASE = [master], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF
GO
USE [Database_Name]
GO
CREATE USER [User_Name] FOR LOGIN [Login_Name] WITH DEFAULT_SCHEMA=[Schema_Name]
GO
EXEC sp_addrolemember 'DB_Owner', '[User_Name]'
GO
Alter AUTHORIZATION ON SCHEMA:: dbo to db_owner
GO


Mak
  • Edited by Mak51 11 hours 7 minutes ago
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 4:04pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics