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
Miscellaneous
Thread ID:
01376047
Message ID:
01376049
Views:
8
You assign permissions using GRANT statement.

>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
>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform