Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Script Database Roles, Application Roles, Server Roles

 
   Database Help (Home) -> Security RSS
Next:  general security ?  
Author Message
Tim Patterson

External


Since: Dec 14, 2008
Posts: 1



(Msg. 1) Posted: Sun Dec 14, 2008 7:08 pm
Post subject: Script Database Roles, Application Roles, Server Roles
Archived from groups: microsoft>public>sqlserver>security (more info?)

I would like a tsql script to script out the already created database roles,
application roles, and server roles for a SQL Server 2005 database.

Please help me create tsql script to complete task using the adventureworks
database.

Thanks,

 >> Stay informed about: Script Database Roles, Application Roles, Server Roles 
Back to top
Login to vote
Uri Dimant

External


Since: Aug 24, 2003
Posts: 1744



(Msg. 2) Posted: Mon Dec 15, 2008 2:26 am
Post subject: Re: Script Database Roles, Application Roles, Server Roles [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

I think Aaron wrote this script
DECLARE @db sysname,
@role sysname,
@rolecur nvarchar(MAX),
@addusr nvarchar(MAX),
@addrolemember nvarchar(257),
@oldusr sysname,
@newusr sysname

SELECT @oldusr = 'frits',
@newusr = 'neufrits'

DECLARE dbcur CURSOR STATIC LOCAL FOR
SELECT quotename(name) FROM sys.databases
OPEN dbcur

WHILE 1 = 1
BEGIN
FETCH dbcur INTO @db
IF @@fetch_status <> 0
BREAK

SELECT @addrolemember = @db + '..sp_addrolemember'

SELECT @rolecur =
'DECLARE rolecur CURSOR STATIC GLOBAL FOR
SELECT rol.name
FROM ' + @db + ' .sys.database_principals rol
JOIN ' + @db + ' .sys.database_role_members rm
ON rm.role_principal_id = rol.principal_id
JOIN ' + @db + ' .sys.database_principals usr
ON rm.member_principal_id = usr.principal_id
JOIN master.sys.server_principals sp
ON usr.sid = sp.sid
WHERE sp.name = @templateusr'

EXEC sp_executesql @rolecur, N'@templateusr sysname', @oldusr
OPEN rolecur

WHILE 1 = 1
BEGIN
FETCH rolecur INTO @role
IF @@fetch_status <> 0
BREAK

SELECT @addusr = 'USE ' + @db + '
IF USER_ID(@newusr) IS NULL
CREATE USER ' + quotename(@newusr)
EXEC sp_executesql @addusr, N'@newusr sysname', @newusr

EXEC @addrolemember @role, @newusr
END

DEALLOCATE rolecur
END

DEALLOCATE dbcur

"Tim Patterson" wrote in message

>
> I would like a tsql script to script out the already created database
> roles,
> application roles, and server roles for a SQL Server 2005 database.
>
> Please help me create tsql script to complete task using the
> adventureworks
> database.
>
> Thanks,

 >> Stay informed about: Script Database Roles, Application Roles, Server Roles 
Back to top
Login to vote
sql_noob

External


Since: Dec 12, 2008
Posts: 9



(Msg. 3) Posted: Mon Dec 15, 2008 7:30 am
Post subject: Re: Script Database Roles, Application Roles, Server Roles [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Dec 14, 10:08 pm, Tim Patterson <Tim
Patter....RemoveThis@discussions.microsoft.com> wrote:
> I would like a tsql script to script out the already created database roles,
> application roles, and server roles for a SQL Server 2005 database.
>
> Please help me create tsql script to complete task using the adventureworks
> database.
>
> Thanks,  

right click on the DB and there should be a Generate Script option
somewhere there, not sure if it will do everything you want. you might
have to break this up into a few steps and transfer things like logins
via SSIS
 >> Stay informed about: Script Database Roles, Application Roles, Server Roles 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
permission issues with database roles - Hello, Does somebody knows or have a complete solution, for resolving the following issues when moving or copying a database to another sql server? - when attaching the moved database, i have orphan users. I can use the sp_help_revlogin to re-create..

sql 2008 and database roles are they ok to use - I read in a document from sql 2005 that database roles were going to be done away with in future reelases of sql but sql 2008 still has database roles. I like the idea of using a database role and assiging usrers to the role for security setup. But...

SQL Server Login and CRM Roles - I'm trying to link to SQLServer instance that is hosting CRM database. I need a login that allows me to access the 'filtered' CRM views. CRM needs to be able to associate the SQL Login with an Active Directory entry for a CRM user with appropriate..

What type of Server Roles to assign for Backup and Recovery - Hi there, I have a question , what is the best practice to create a login to perform backup and recovery, Can I just have DB role as DB_backupoperator or I have to assign a sysadmin role to the user ( in SQL authentication/ windows).Coming up with a....

Access to database through application only - I need to restrict my users to accessing the application to using Cognos only. Anyway I can get that done?
   Database Help (Home) -> Security All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]