Hey all, I've got a question.
While I'm new to SQL Server, I'm an old hat at SQL in general with specific experience in Access and MySQL. Because of that, I figured it would be relatively easy for me to just jump in to a live environment and get started. Most of it has been editing/updating basic SQL queries...
Unfortunately, I'm NOT familiar with the way Logins and Users are created in SQL Server and am running into some trouble with my current task.
I need to create a SQL query that creates a Login and User and adds it to the 'public' and 'db_datareader' groups for a specific database.
From what I understand from the MSDN pages, the SQL query should be something like below:
CREATE LOGIN MyUser WITH PASSWORD = 'MyPassword' CHECK_EXPIRATION = NO CHECK_POLICY = NO; USE MyDatabase; CREATE USER MyUser FOR LOGIN MyUser WITH PASSWORD = 'MyPassword'; EXEC sp_addrolemember db_datareader MyDatabase; GO
Is this correct?
The server this is going to be run on is running SQL Server 2008 which is why I used sp_addrolemember instead of ALTER ROLE in the query. If ALTER ROLE works in SQL Server 2008, I'd prefer to use it for forward compatibility.