Create Login with T-SQL

Hello,

I am creating, using T-SQL, a database with its file groups, tables,
constraints, etc.

Can I also create, using T-SQL, a Login with Username and Password to
access that database?

Usually, I go to Security > Logins of SSMS to manually create the
login.

However, if I could do the same using T-SQL I would have it all made
automatically.

Thanks,
Miguel
0
shapper
11/26/2009 12:52:35 PM
sqlserver.programming 1873 articles. 0 followers. Follow

3 Replies
876 Views

Similar Articles

[PageSpeed] 4

EVERYTHING that the GUI does winds up as tsql executions on the server. :-) 
Most of them you can generate a script for using the Script menu in the 
upper left of the current dialog window.  This is a great way to learn 
functionality.

See CREATE LOGIN in Books Online.

-- 
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net


"shapper" <mdmoura@gmail.com> wrote in message 
news:6034063a-b304-4f5f-876d-9c1b49f8c2ae@c3g2000yqd.googlegroups.com...
> Hello,
>
> I am creating, using T-SQL, a database with its file groups, tables,
> constraints, etc.
>
> Can I also create, using T-SQL, a Login with Username and Password to
> access that database?
>
> Usually, I go to Security > Logins of SSMS to manually create the
> login.
>
> However, if I could do the same using T-SQL I would have it all made
> automatically.
>
> Thanks,
> Miguel 


0
TheSQLGuru
11/26/2009 3:18:03 PM
If you are using MSSQL 2005 and up, you can generate the login's creation 
script by clicking on the "Script" button at the top of the "Login - New" 
dialog window.

Alain Quesnel

"shapper" wrote:

> Hello,
> 
> I am creating, using T-SQL, a database with its file groups, tables,
> constraints, etc.
> 
> Can I also create, using T-SQL, a Login with Username and Password to
> access that database?
> 
> Usually, I go to Security > Logins of SSMS to manually create the
> login.
> 
> However, if I could do the same using T-SQL I would have it all made
> automatically.
> 
> Thanks,
> Miguel
> .
> 
0
Utf
11/26/2009 3:36:02 PM
On Nov 26, 3:36=A0pm, Alain Quesnel
<AlainQues...@discussions.microsoft.com> wrote:
> If you are using MSSQL 2005 and up, you can generate the login's creation
> script by clicking on the "Script" button at the top of the "Login - New"
> dialog window.
>
> Alain Quesnel
>
> "shapper" wrote:
> > Hello,
>
> > I am creating, using T-SQL, a database with its file groups, tables,
> > constraints, etc.
>
> > Can I also create, using T-SQL, a Login with Username and Password to
> > access that database?
>
> > Usually, I go to Security > Logins of SSMS to manually create the
> > login.
>
> > However, if I could do the same using T-SQL I would have it all made
> > automatically.
>
> > Thanks,
> > Miguel
> > .
>
>

I am using SQL 2008 and this works:

if exists (select * from sys.server_principals where name =3D N'WCA')
drop login WCA
go

create login WCA
  with password =3D 'pass',
  default_database =3D WCA,
  default_language =3D english;
go
exec sys.sp_addsrvrolemember @loginame =3D N'WCA', @rolename =3D
N'sysadmin'

I think I am doing it right.
0
shapper
11/26/2009 3:44:42 PM
Reply:

Similar Artilces:

create a roster
How can you create a weekly roster in which functions can be assigned to more than 10 people. The roster should be updatable, so that when holidays and days off are marked on the weekly roster they will be taken account of it future rosters. ...

I can't type all the symbols
Version: 2008 Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I wanted to type the letter e with a symbol indicating the long vowel sound. In the Symbols menu I find some vowels with symbols over them (but not the one I want), and other pronunciation symbols with no letter under them. One of them seems to be the long-vowel symbol. How can I type the symbol so that it appears over the letter? In article <59bb7ddc.-1@webcrossing.JaKIaxP2ac0>, <andreajackson123@charter.net@officeformac.com> wrote: >I wanted to >type the letter e with a symbol indicating...

importing or creating reference footnotes
I am trying to import a word document into publisher and it has reference footnotes within the document. The reference footnotes are not coming into the publisher document with the reference footnotes. Correct, they will not up to Publisher 2003. In Publisher 2003 depending on which version of Word you are using if they will or not. -- "If you don't know where you are going, any road will take you there!" ...

e-mail alerts don't work,setup but don't work-
I have a pop 3 acct , but e-mail notification doesn't work any answers?, Thanks Studmn1. Studmn1 <Studmn1@discussions.microsoft.com> wrote: > I have a pop 3 acct , but e-mail notification doesn't work any > answers?, Thanks Studmn1. More details and symptoms needed. For example, what version of Outlook? -- Brian Tillman office student and teacher edition 2003 for outlook, the pop up notification window doesn't pop up or change my mouse to the little mail icon or transperency window "Brian Tillman" wrote: > Studmn1 <Studmn1@discussions.microsof...

Outlook 2003 and ActiveSync 3.1 won't talk
I have an old Cassiopeia E-100 which, as I understand it, requires using the older ActiveSync 3.1. I just upgraded my PC to Office 2003 and now ActiveSync can't communicate with Outlook. Is there a newer ActiveSync that would work with both my E-100 and with Outlook 2003, or is it time to get a new PocketPC? ...

why won't my automobile loan payments show as a transaction?
I have a automobile account and a wachovia bank account. My auto loan company automatically takes $245 from my bank account each month. i can see the $245 transaction in my bank account register in MS Money but it doesnt update in my auto loan register. How can I have it automatically update my auto loan register? Thanks, Brad Nelson Have you set up an automatic bill payment? -- Neil "Brad Nelson" <BradNelson@discussions.microsoft.com> wrote in message news:71678D94-6B93-4C41-84BB-F980827B51D8@microsoft.com... >I have a automobile account and a wachovia bank acco...

Mailbox not created when AD account created
A couple of days ago I noticed that I created a user account but the 'Email Addresses' tab of the user properies did not list any email addresses. Subsequent new user accounts have all experienced the same. I researched the knowledge and tried the recommended solutions to either manaully start the recipient update service or rebuild te recipient update service. Neither recommendation has resulted in a mailbox being created for this particular user or any additional user that I have created since this error first showed up. I performed a Windows update last Thursday and so I bel...

Task Create - Status
I'm trying to make a simple task, when a user owner is assigned a task in CRM, it receives an email letting it know it has one. I have the following below, but it is not generating one when i assign one manually in the CRM. What to do? I've tried both the following: When task is created E-Mail to:[owner];Subject test As well as: When task is created if Task activity status = Open then E-Mail to:[owner];Subject test I've checked the mailserver many times over, and I can send emails manually from the CRM so you can rule that out Tested out ok on our end. Some ideas:...

Help Creating XmlNode / XmlAttribute Elegantly
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation. I am looking to see if there is a better way to add a new node / attribute than using XmlDocument.InnerXml. I would consider this to be a hack but couldn't really see another way of doing this without definin...

Create external database
Hi all. I need to create an external database (file). On a site I found this code: ------------------------------------------------------ Function CreateLinkedExternalTable(strTargetDB As String, strProviderString As String, strSourceTbl As String, strLinkTblName As String) As String 'strTargetDB = Source Database Name 'strProviderString = Not used, currently hard coded 'strSourceTbl = Source Table name in the database we are linking too. 'strLinkTblName = Table name we would like to see in the Access Database. Dim catDB As ADOX.Catalog Dim tblLink As...

Why can't I see clipart on word or publisher.
I have just bought a new desktop computer and loaded microsoft office 2003. When i insert clipart onto a page in publisher or word, I cannot see the picture. the handles are on the page put picture isn't what can I do? Read the third FAQ here Q: Why can I not see images/shapes/lines when editing my publication? http://ed.mvps.org/Static.aspx?=Publisher/FAQs -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com http://officebeta.iponet.net/en-us/publisher/FX100649111033.aspx "punch" <punch@discussions.microsoft.com> wro...

How to create pie chart with %
I have got a problem that I don't if excel could help me to calculate the % within a column and draw a pie chart. My case is I have a column containing a series of numbers. e.g. 1,4,8,1,3,9,11,2,4,5,6,.........etc I want to draw a pie chart that showing 1-3 , 4-6, 7-9, >9 with the corresponding % inside that column. Can anyone tell me how can I make it ? Ray - You need to calculate the frequencies in your data. Let's assume your data is in A1:A12. In B1:B3 enter these numbers, the upper limits on the groupings: 3 6 9 You can enter ">9" into B4 witho...

Email address not created when a new user is created
All, This issue recently happened in my company. Upon creating a new user, the policy was set to create the smtp and X400 address automaticaly. Now when we create a user the smtp and x400 addresses are not created, and when attempting to setup the new user in outlook, the address cant be found. We are using exchange 2003 SP1 on Win2k3 servers. On Wed, 13 Jul 2005 06:49:07 -0700, "Bryan" <Bryan@discussions.microsoft.com> wrote: >All, >This issue recently happened in my company. Upon creating a new user, the >policy was set to create the smtp and X400 addres...

IE CRM closes after login
Immediately after the login screen the browser dissapears. I have this problem on only 1 PC (windows XP & IE 6 SP1). After I completely reinstalled it, it worked for a while, but now it is doing it again. Please help! I cannot reinstall the everything on this PC every week.. We have seen browser problems when you have added tools into the browser like the google search bar etc make sure the browser is runnng with no addiitonal addins "Michael Szabo" <mihaisz@bondweb.com> wrote in message news:0b5301c3893c$32d94a10$a401280a@phx.gbl... > Immediately after the login ...

Can't hide sound icon display during slide show
I've tried checking the box to hide the sound icon in the slide show (under Custom Animations; Effect Options; Sound Settings) and I've also tried moving the sound icon off the slide in the "Normal" view, and neither work to remove the sound icon. (The sound file is set to play automatically when the slide is displayed, and it does play, but the icon is right there in the middle of the slide.) Does anyone have a suggestion on how else I might be able to hide the sound icon? Thank you. Hi Can you confirm that the sound icon appears in slide show view? I...

Exchange 2010 MRM, no log files being created
I'm hoping someone can help me with this issue....it has been driving me crazy for days. I have enabled MRM logging on our exchange server, and I can see that some of the policies are working when I run start-managedfolderassistant. We have a retention policy tag on the deleteditems folder, and this does work. The problem is I am not getting any files in the MRM log directory. C:\Program Files\Microsoft\Exchange Server\V14\Logging\Managed Folder Assistant Events 9021 and 9022 are logged in the Application log, but where are the files? Below is the output of my mai...

when form created
I have a form which was created by someone else (not a form template) which is like a questionnaire with empty boxes to be completed. When the boxes are typed in all the margins move to accommodate the words being typed. Is there a way to fix/lock the original form and then just fill in the blank boxes? I suspect this is set up as a table with auto resizing enabled. Displaying table gridlines (Table | Show Gridlines) will help you see what you're dealing with. Then select the table, go to the Table tab of Table Properties, click Options, and clear the check box for "A...

SQL help needed please
greetings gurus I am having trouble with the syntax of a query I'm trying to write. Here is the situation, simpified to its essence: C:/DB/A.mdb has tblNames with relevant fields CustID, CustName, CustEMail. C:/DB/B.mdb has the same table and fields. C:/DB/C.mdb also has the same table and fields. Many of the names appear in 2 or 3 of the databases, but most names appear in only one of the three databases. Here's what I am trying to do (so far without success)... I want the values of CustID, CustName, CustEMail that are in A.mdb UNION the values of CustID, Cus...

Creating a Brochure
How do you create a 3-column brochure from scratch for Publisher 2002? I can only find the directions for the 2003 version. Quick help would be appreciated, project is due Monday. Create a three-panel or four-panel folded publication http://office.microsoft.com/en-us/assistance/HP011646681033.aspx Scroll down to the section that says "Build a three-panel or four-panel publications from scratch." -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Derek" <Derek@discussions.microsoft.com> wrote in message news...

Can't open excel documents
When I try to open an excel doc is 'stalls' ... getting stuck on 'virus scan' dialouge at the bottom of the sheet. I can open excel w/o a file and save one, but when I try opening an existing one, Excel simply won't do it and I eventually have to contl.alt.del. it in order to continue. Any ideas? ...

How to create Access macro shortcut
I'm still using Access 97 and saw something the other day that I would like to use that was in Access 2000. In an Access 2000 database, there was a .mam file in a directory that launched the Access 2000 program and ran a macro. How do you set this up? Can it be done in Access 97? If so, how? Hi. > How do you set this up? Select the macro in the Database Window and right click with your mouse, then select "Create Shortcut..." in the pop-up menu. Follow the prompts for where to place the shortcut and what to name it. The default is: <PathToDeskTopDir>\Shortcut ...

can't open this item with password protected files
Hello, I can't open an email in Outlook 2003 with an attachement that is password-protected. The email is placed in the folder Server failures and if I try to open it, I get the following message : Can't open this item. The operation failed. Does anyone know how to fix this. Thanks in advance. Raimond Does it work when you save the attachment first? -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Service Pack 1 ----- "Raimond van der Meer" <raimond_cdmi@hotmai...

Users mailboxes not created when user created
I have a problem that recently just started happening on my exchange 2003 server. When i create a new user account and create the mailbox for exchange, once im done, the mailbox isnt created, adn if you go into the properties of the user account adn go to the exchange email address tab, there isnt an smtp or an x.400 address listed. I am having to manually create and add these, adn then go delete the exchange mailbox and recreate it. This is really annoying and would love to know if anyone has any ideas of how to fix it. Thanks Jason In news:9F836A43-98BF-435A-AA43-AFF10124BE3F@micro...

POP3 server doesn't work
I recently changed the network topology, moving the SBS 2003 server from a 2 NIC setup to a single NIC. There is now a SmoothWall box acting as the network gateway (Internet access is very speedy now). I am having a problem in that one particular process uses POP3 to get mail from an Exchange mailbox. POP has stopped working. I have checked the service; it is up. If I telnet to port 110, I get a connection that is dropped when I press return. Normal (non-POP) Exchange operation is fine. Running the best practices analyzer did not reveal anything unusual. Any ideas or suggestions...

Upgrade to W7 64 from Vista 64 now can't record TV
I have a Hauppage 950Q USB tuner. Worked great in Vista watching and recording OTA local HD channels. In TV setup the tuner is discovered, however on first play the wheel spins forever and generates an error that the tuner is already in use, a small box appears that is supposed to have the name of a program in it, as if I was recording or an extender was watching and I was trying to change the channel. No name in the box, there is in fact no previous task for the tuner. Clicking the box then starts the TV. This will not occur again until a system reboot. Media center can be ex...