Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


questions about CREATE LOGIN


questions about CREATE LOGIN

Author
Message
vxhughes
vxhughes
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 3
I know I can create a login as follows:

CREATE LOGIN test_login
WITH PASSWORD = 'some_password',
DEFAULT_DATABASE = AdventureWorksDW, -- or whatever database
DEFAULT_LANGUAGE = us_english,
CHECK_POLICY = OFF;

I also know that, if I'm in SQL Server Management Studio and I enable Query | SQLCMD Mode, instead of

CREATE LOGIN test_login

I can use

:setvar LoginName "test_login"
CREATE LOGIN $(LoginName)

in the above SQL code.

• What is the advantage of using the latter method?

• Is there a way I can use the latter method from outside of SQL Server Management Studio (like when I'm using SQL commands in some app)?

• In SQL Server Management Studio, I don't see any indication when SQLCMD Mode is enabled or it's not, so if I forget whether I’ve enabled it, I just have to play with it to find out for myself. Am I missing something? How can I tell?

• I know that in the above example, AdventureWorksDW can be enclosed in square brackets as follows:

DEFAULT_DATABASE = [AdventureWorksDW],

and the command will still work. But what effect, if any, does this have on the CREATE LOGIN command?
Nick_UK
Nick_UK
UDP Broadcaster
UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)UDP Broadcaster (1.5K reputation)

Group: General Forum Members
Points: 1465 Visits: 1181
in the above SQL code.

• What is the advantage of using the latter method?

This allows the script to be called from the cmd line tool sqlcmd.exe with variables passed in e.g.
sqlcmd -S localhost -d Master -q "SELECT '$(var1)' as [$(var2)]" -v var1="Mooooo" var2="Cows Say"
and also allows you to use a script against multiple instances using the :connect option

:setvar word "now"
:SETVAR server1 "SERVERNAME01"
:SETVAR server2 "SERVERNAME02"

:connect $(server1)
SELECT @@servername,'$(Word)' as [Word]
GO

:connect $(server2)
SELECT @@servername,'$(Word)' as [Word]
GO


• Is there a way I can use the latter method from outside of SQL Server Management Studio (like when I'm using SQL commands in some app)?
yes using the sqlcmd line as above

• In SQL Server Management Studio, I don't see any indication when SQLCMD Mode is enabled or it's not, so if I forget whether I’ve enabled it, I just have to play with it to find out for myself. Am I missing something? How can I tell?

the :setvar will go grey when enabled
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search