Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Assign user Rights
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
How To Assign user Rights
Miscellaneous
Thread ID:
01376047
Message ID:
01376047
Views:
43
I am creating SQL 2005 databases for students for a class I'm teaching. I write this script which takes a student's Id and creates a Login, Database and DB user. So far this all works fine, except for rights. How do I assign rights for users?
USE [master]
GO

DECLARE @UserName VARCHAR(5)
DECLARE @SqlStatement nvarchar(MAX);

SET @UserName = '75080'

SET @SqlStatement = 'CREATE LOGIN [NC-Coleman\' + @UserName + '] FROM WINDOWS'
EXECUTE (@SqlStatement);

EXECUTE ('CREATE DATABASE [' + @UserName + ']')

SET @SqlStatement = N'USE [' + @UserName + '];CREATE USER [' + @UserName + '] FOR LOGIN [NC-Coleman\' + @UserName + ']'
EXECUTE (@SqlStatement);
GO
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform