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
983 Views

Similar Articles

[PageSpeed] 44

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:

Newbie q: Can't modify a database
Hi, I've been handed an access database in order to modify it (in the programming sense), but when i open it it opens as an application, without any apparent means of modifying the database structure. All it will let me do is add or edit data. Is there a secret trick to opening the database for modification, or do I have to go to the owners of the database and have them save it in a different way? Thanks, Jon Hi Jon If you hold down the shift key while the database is opening it should bypass any startup options code and take you straight to the database window. If this doesn'...

autorecover doesn't work reliably during a forced reboot
Scenario: - Auto-recover is enabled in excel - An Unsaved Excel document is open - An SMS process for applying security or windows update patches causes a forced/unattended system reboot After the reboot is performed, the unsaved changes are lost in the excel document, because Autorecover doesn't think there is an autorecover document (apparently). I've had this happen a number of times, but it isn't 100% consistent. Is there anything I can do to increase the likelihood that autorecover will actually work (short of trying to disable SMS and windows update)? Is it possi...

insert new row doesn't add formula
I have a table A2->M100 In the M Column I have a sum to calculate the total of that row =SUM(A34:N34) for example Now if I want to add a row into that table, I click on the number o the left, that highlights the row then I go insert>>row and that keep the formatting of the cells. BUT it doesn't add the =SUM(A54:N54) in the M column, and so I have ha to edit each cell by hand to get the correct formula. Is there an easier way to add a row and keep fomulas within that row but obviously automatically change the numbers to suit the row -- Message posted from http://www.ExcelForu...

Export Excel file to SQL
I'm currently doing a project where it require client to export excel spreadsheets to SQL. the application that is using the excel spreadsheet exported is a web-based application. Is it possible to do that? Any suggestion or recommendation is greatly appreciated. thank you Go to Enterprise Manager. Browse to your database in the left pane (object browser). Right click your database. All Tasks --> Import Data. Next. Set your datasource to Microsoft Excel 97-2000 or whichever Excel version you have. Click the ... button next to the File Name text box and browse to your Excel sheet. M...

How do I create a drop down list in Excel 2003
How do I create a drop down list in Excel 2003. I've tried to use the help menu and I cannot figure it out. See: http://www.contextures.com/xlDataVal01.html -- Regards, Peo Sjoblom "Lenny" <Lenny@discussions.microsoft.com> wrote in message news:8F05DEA1-E264-4760-9DDE-3C97319AA1D4@microsoft.com... > How do I create a drop down list in Excel 2003. I've tried to use the help > menu and I cannot figure it out. ...

Won't print color
Savin 4540..checked all known areas..wont print color..just black and white. Preview is color..settings are color..hint..it once printed color..then stopped after saving the file. I have windows xp. Help? Check out a new driver, there is a driver with a time stamp of December 2007, maybe newer than yours. http://www.savin.com/downloads/Default.aspx?hbn=drivers -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "CraigO" <CraigO@discussions.microsoft.com> wrote in message news:E97BD54B-D9DA-40C0-9F0C-6F8CFD90EA1B@micros...

Outlook Express creates a File on my desktop
ok i dont know if anyone else is getting this problem but when ever i run outlook express it creates a file on my desktop named "~". it has done this since new, and ive seen it on one other computer as well. is there a way to stop this from happening?? cause deleting the file everytime is getting tiresome...if anyone knows how to fix this please let me know. ty Shawn <anonymous@discussions.microsoft.com> wrote: > ok i dont know if anyone else is getting this problem but > when ever i run outlook express it creates a file on my > desktop named "~". ...

searching for questions by login name
How can I search for all the questions that specifically I submitted? I tried to use my display name and nothing returned. "GailH" <GailH@discussions.microsoft.com> wrote in message news:830E4922-7352-4C30-8844-4EF72B0BD9C7@microsoft.com... > How can I search for all the questions that specifically I submitted? I > tried > to use my display name and nothing returned. Do yourself a BIG favour and ditch the horrible web interface. Use a news reader instead. Setting up Outlook Express/Windows Mail to access Microsoft newsgroups http://www.michaelsteve...

Why doesn't a background cover the entire page?
When formatting a background, the background does not cover the entire 8.5" x 11" area. The area covered is only 8" x 10.5". jdntal <jdntal@discussions.microsoft.com> was very recently heard to utter: > When formatting a background, the background does not cover the > entire 8.5" x 11" area. The area covered is only 8" x 10.5". Because your printer can't print to the edge of the page, most likely. -- Ed Bennett - MVP Microsoft Publisher ...

can't save files in subfolders using Word #2
I'm running Word on a Mac running OS X. When I go to save a file in Word, it only gives me the option to save in the root files like "Documents" or "Applications." How do I save the file into a subfolder? On a PC, I would double click to open the folders until I got to the folder I needed. That doesn't work here. Can someone help? I'm sure this is something obvious I'm missing. Thanks - Taylor In article <1163740041.258317.226140@b28g2000cwb.googlegroups.com>, taylorgriffin@gmail.com wrote: > I'm sure this is something obvious I'...

Integration Manager 10
We are having multiple problems with IM10. When we are in a company in GP and select Run Integration, nothing happens. We can use open integration and then run it form there. Is here something we missed in the upgrade to GP10 and IM10 that would cause this? Additonal information. I am trying this running as administrator on the computer and sa in GP, so I don;t think security is the issue. Any help would be appreciated. "Bob Harrison" wrote: > We are having multiple problems with IM10. > > When we are in a company in GP and select Run Integration, nothing happens. ...

Went from GP_8 to GP_9 and SQL2000 to SQL2005 and SQL freezing
We have been live for 2 days after the conversion. Monday we had the CPU peg at 80% on the SQL Server process and had to reboot. Same thing happened 2x today. Cannot determine a pattern with users doing anything special to cause problem. Have run KB 898982 and 850996 without issue. Server has 4 Xeon's with 4gb of memory. Memory use at 1gb with GP client running on the server and one other user. Startup a third user with their Home Page and memory use goes to 4gb. CPU at 1%-4%. I just know sometime tomorrow something will cause the hang. Runn GP 9.00.0281 and W20003 64-bit SP1 on s...

Dropdown list doesn't open after click
Hello, problem: I have combo box (style is dropdown) inside the dialog. The size of dropdown window was changed inside the resource file and it has big size. The combo doesn't have any item and no item is inserted during initialization of dialog. When the dialog is displayed and I click on arrow of combo box then nothing happens (I cannot see empty dropdowned listbox). What's the reason of this behaviour ? On any PC I can see the empty list box and on the second PC I cannot see this. Thanks Jirka And what are the characteristics of these two machines? Same OS? Same service pack...

Protecting hidden columns so they can't be unhidden ?
Hi, Is there a way to hide columns so that no one else can unhide them ? Need to send a file with data in 2 hidden columns that I don't want to be unhidden and I don't want to have to delete them. Thanks ! Gary, easiest way is to hide the columns then protect the worksheet (Tools > Protection > Protect Sheet). If there are cells that the recipients will use for data entry, unlock them (Format > Cells > Protection > Locked) first. You can also remove the row and column headers (Tools > Options > View > Row & column headers) so it won't be immediate...

Outlook 03 won't send\receive at startup
When I start Outlook 2003, I have to click the send\receive button to receive email. I followed the bulletin that had me copy the current Send\Receive group, but that has had no affect. Any other suggestions to fix the problem? Thanks Your provided no information that would permit an answer. To what "bulletin" are you referring? What are your mail account types and connection types? -- Russ Valentine [MVP-Outlook] "Walt" <anonymous@discussions.microsoft.com> wrote in message news:167db01c44835$aaacbb90$a601280a@phx.gbl... > When I start Outlook 2003, I have ...

Creating mail usage / history report
Bear with me here. We're running Exchange 2000. I'm being asked to run a report showing a user's e-mail activity for an investigation. I'm able to access this person's mailbox administratively. Is there a way to run a report for each folder that would show the following fields: Date/Time - To - From - Subject - Message size I tried doing a recursive directory of the MBX folder for this person in DOS which will show the following, but they want more detail... Directory of M:\DOMAIN.COM\MBX\jsmith\Sent Items 01/15/2004 09:43a <DIR> . 01/15/2004 ...

Creating a new excel template like SFO quote mailmerge template
I want to create an excel template for calculation purposes on quote form. Print Quote for customer on SFO lets you create a word mailmerge template. Just like that I want to create a custom menu item which will let me bring up an excel template, on which I can do calculations and pass that calculation back to quote. Any pointers on how do do this ? Thanks in advance for the help. ...

Can't install Windows Updates on Vista
I'm running Windows Vista Home Premium with Service Pack 2. I have 15 "Important" Windows Updates that won't install: 9 security updates, 3 windows updates for Vista, etc. One dates back to 12/8/09 and the most recent 4/13/10. They're starting to add up. When I try to install them, some will fail due to a 8007371C error and the rest will say pending (until restart), but then after the restart they fail to install (but no error code). I've tried installing them with UAC, anti-virus, and firewall off, but the result is the same. When I try to install any of them ...

How to create an error message
I've created a drop-down menu. To the right of this menu are five cells in a row in which data should be entered. But, data is not needed in all five cells. Which cells need data depends on what choice is made in the drop-down menu. Was that clear enough...? If someone can give me a hint as to how I can make an error message appear if data is entered in a cell which is not relevant to that particular menu choice, I'd really appreciate it! -- Siberian ------------------------------------------------------------------------ Siberian's Profile: http://www.excelforum.com/member.ph...

Change SQL Sort Order
Is it possible to change the sort order from binary to doci using Rebuild Master Utility in SQL2000sp4? I am trying to conolidate 2 SQL servers to 1 box and GP 7.5 is running on binary sort order. I have tried using the master utility in SQL2000, but I ended up crashing a test sever doing this. Here are the steps we followed to change from binary to doci: 1) Create a new instance of SQL Server on the same server 2) Install GP again, but when creating the database setting the sort order to doci 3) Install all the service packs and hot fixes that were previously installed. 4) Create a...

I cannot create or reply to an email message
As of yesterday, I can no longer create, reply or send a message with forward emails. As soon as I start to type in the body of the email, my outlook freezes and then crashes. I still recieve emails but cannot respond. Help Krista Is this a trial version of Outlook? "Kjardy" <Kjardy@discussions.microsoft.com> wrote in message news:A9A08D38-3C2E-433C-8CEA-5E090C7835A9@microsoft.com... > As of yesterday, I can no longer create, reply or send a message with forward > emails. As soon as I start to type in the body of the email, my outlook > freezes and t...

Creating a custom reply Rule
I have about 2000 read messages in a folder that I want to reply to with the same message. Is it possible to created a rule that would do this? I appreciate the help. ...

Help! EXMERGE Doesn't work
Could someone help me get ExMerge working please? I carefully followed Jim McBee's recipe for setting up ExMerge permissions (http://mostlyexchange.blogspot.com/2005/07/recipe-for-setting-up-permissions-to.html). However, I still couldn't get it working. I turned on the maximum logging and the logs show me that there is a permission problem as the following: [14:53:37] OpenStores: Start [14:53:37] GetMsgStoresTable successful. [14:53:37] Checking service 'Microsoft Exchange Message Store' [14:53:37] Found service 'MSEMS' in current profile. [14:53:37] Error opening...

How do I create an Excel worksheet with a limited no. of rows?
I need to create a small worksheet in Excel 2002 with say 20 rows & 20 columns. Is this possible? yes -- Gary''s Student "WarTech" wrote: > I need to create a small worksheet in Excel 2002 with say 20 rows & 20 columns. > Is this possible? OK - what I should have said was: How? "Gary''s Student" wrote: > yes > -- > Gary''s Student > > > "WarTech" wrote: > > > I need to create a small worksheet in Excel 2002 with say 20 rows & 20 columns. > > Is this possible? Hi The sheet will...

Creating New Worksheets & Sorting Order of Worksheets
I have a file with tracking information. One worksheet has the names of all the people I am tracking, each with their own worksheet. I also have a UserForm that is used to add people. I would like the following 2 things to happen (more than likely in my cmdOK_Click event): 1 - Copy a worksheet from one of my existing people, blank out the info, and rename it the value in my Name field in my UserForm (I used to know how to do this, but it was last year when I last had the code); 2 - Sort the placement of the worksheets with the people I'm tracking so it is in the same order as...