Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create user logins using script 1

Status
Not open for further replies.

cpitc

IS-IT--Management
Dec 20, 2009
77
GB
Hi

I used this example to add a user log in. it worked ok on my SQL epxpress query analyser, but on some colleagues it didnt and would nt allow the script. It appears there can be script for Windows log in and SQL log in. Could someone please explain what the N is and also explain (perhaps with example using below) on one for window and one for sql log in. Thanks

CREATE LOGIN [cp] WITH PASSWORD=N'leeds',
CHECK_EXPIRATION=ON, CHECK_POLICY=ON,
DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[English];


 
There should be a login to connect to the database instance (via nt or sql authentication).

In order to access a particular database that login is then mapped to a database user.

The N merely lets you/sqlserver now that the string is a unicode type.

Code:
USE [master]
GO

--First Create the login
CREATE LOGIN [cp] WITH PASSWORD=N'leeds', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON
GO
USE [Northwind]
GO
--Second Create the User that this login maps to
CREATE USER [cp] FOR LOGIN [cp]
GO
--Third Add some permissions to that user
USE [Northwind]
GO
EXEC sp_addrolemember N'db_datareader', N'cp'
GO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top