Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
shekhar_dba
Starting Member
39 Posts |
Posted - 2007-01-09 : 12:33:01
|
| Hi gurus i am new to sql server.... so plz help me out ... i need script to create new database user and login.i know how to create by enterprise manager but have no idea to create it by QA.please help me out thanks in advanceshekhar |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-01-09 : 12:46:32
|
do you know about BOL? you can find syntax for all T-SQL statements there.http://msdn2.microsoft.com/en-us/library/ms173463.aspxhttp://msdn2.microsoft.com/en-us/library/ms189751.aspxEDIT: also, if you are that new to sql server you don't know how to create users, it might be a bit early for you to have the acronym "dba" in your user name.  www.elsasoft.org |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2007-01-09 : 12:52:59
|
| [code]EXEC sp_addlogin 'MyUserName', 'MyPassword', 'MyDefaultDB'EXEC sp_grantdbaccess @loginame = 'MyUserName' , @name_in_db = 'AliasNameForThisDatabaseIfDifferent' -- Optional[/code]If the user has Windows NT permissions (rather than a SQL Server login) you should do:[code]EXEC sp_grantdbaccess 'DomainName\Username', 'Username'orEXEC sp_grantdbaccess 'DomainName\Username', 'SomeOtherAliasName'[/code]then you can add to Roles:[code]EXEC sp_addrolemember @rolename = 'RoleToAddTo', @membername = 'MyUserName'e.g.EXEC sp_addrolemember @rolename = 'db_datareader', @membername = 'MyUserName'EXEC sp_addrolemember @rolename = 'db_datawriter', @membername = 'MyUserName'[/code]alternatively you can allocate permissions directly (bad idea though, better to grant the permissions to a Role, and then add the User to that Role)[code]GRANT SELECT, INSERT, UPDATE, DELETE ON MyTable TO UserNameGRANT SELECT, INSERT, UPDATE, DELETE ON MyTable TO MyRoleName[/code]Kristen |
 |
|
|
shekhar_dba
Starting Member
39 Posts |
Posted - 2007-01-09 : 15:12:20
|
| thanks alot to all of u :)bye until next time |
 |
|
|
|
|
|
|
|