Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the CREATE LOGIN sql statement?

How to use the CREATE LOGIN statement on SQL Server 2005?

I've tried nearly everything: with commas, without them, with strings, without them, etc.

CREATE LOGIN @loginame WITH PASSWORD = 'pass', 
DEFAULT_DATABASE='dbname' DEFAULT_LANGUAGE='us_english', CHECK_POLICY= OFF;

I always get this error:

Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.

like image 578
truthseeker Avatar asked Oct 04 '10 11:10

truthseeker


People also ask

What is the use of create statement in SQL?

The SQL CREATE TABLE Statement. The CREATE TABLE statement is used to create a new table in a database.

What is the syntax for creating a new Login on the SQL Server?

CREATE LOGIN <loginname> WITH PASSWORD = '<Password>' MUST_CHANGE, CHECK_EXPIRATION = ON; Example to create a login for a user with password. The MUST_CHANGE option requires users to change this password the first time they connect to the server.

What is create a Login?

Description. The CREATE LOGIN statement creates an identity used to connect to a SQL Server instance. The Login is then mapped to a database user (so before creating a user in SQL Server, you must first create a Login).

How do I create a Login managed instance in SQL?

Add users to database-level roles Log into your managed instance using a sysadmin account using SQL Server Management Studio. In Object Explorer, right-click the server and choose New Query. Create a new connection to the managed instance with the user that has been added to the db_datareader role.


2 Answers

Do u want this Create login to be dynamic? Because u say @loginname?

I tried this code and it works for me..

CREATE LOGIN test WITH PASSWORD = 'pass', DEFAULT_DATABASE = [enter database here] , DEFAULT_LANGUAGE = us_english, CHECK_POLICY= OFF;
like image 153
Emerion Avatar answered Sep 28 '22 08:09

Emerion


The best way is to use above statements but as a string, and then evaluete/exe this string as a command.

like image 38
truthseeker Avatar answered Sep 28 '22 08:09

truthseeker