Script for login in SQL Server

Posted by Nishithraj under Sql Server on 2/3/2010 | Views : 1839 | Status : [Member] | Replies : 5
How do we generate script through a tsql statement for existing logins in SQL Server?

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan



Responses

Posted by: Abhi2434 on: 2/3/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
What do you mean by Generate script through tsql statement ?

TSQL means Transact sql. It is actually a script. So how could you generate?

I didnt get your problem. Please explain

www.abhisheksur.com

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 2/3/2010 [Member] Bronze

Up
0
Down
See the problem is like as follows.

I need to generate scripts for every objects of databases in a server using an asp.net application.

I'm already done with tables(Create & alter table statements) also stored procedures(using sp_helptext statement).

Now I need to do the same with logins and constraints. i.e, I need to take scripts for existing logins and constraints from front end(Asp.NET). Do you know any query to do that??

I hope you are clear with the requirement now.

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: RtpHarry on: 2/3/2010 [Member] [MVP] Bronze

Up
0
Down
this thread seems to have a script that might meet your needs:

http://www.sqlservercentral.com/Forums/Topic508244-359-1.aspx#bm838976

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 2/4/2010 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
A little modification :

SELECT 'EXEC sp_addsrvrolemember @loginame= '+ SPACE(1) + QUOTENAME(SYSTEM_USER) + ' + @rolename ='
+ SPACE(1) + QUOTENAME(USER_NAME(rm.role_principal_id), '''')
FROM sys.database_role_members AS rm
ORDER BY rm.role_principal_id


www.abhisheksur.com

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 2/4/2010 [Member] Bronze

Up
0
Down
http://blog.sqlauthority.com/2007/11/16/sql-server-2005-generate-script-with-data-from-database-database-publishing-wizard/

If you are not satisfied with the answer please let me know.

Nishithraj, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response