SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Create table permission


Create table permission

Author
Message
SKYBVI
SKYBVI
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2999 Visits: 3239
Hi,
I am trying to give a user (ccr) to create table permission in 1 of db's.

I ran this:-
grant create table to ccr

it says command done successfully
BUT
ccr cant create table now also.

Then, i ran:-
grant create table on schema::dbo to ccr

Then, it says

Msg 102, Level 15, State 1, Line 0
Incorrect syntax near 'CREATE TABLE..'.

How shld i give permissions :

Regards,
Sushant
K. Brian Kelley
K. Brian Kelley
Keeper of the Duck
Keeper of the Duck (24K reputation)

Group: Moderators
Points: 24592 Visits: 1917
Since CCR does not own the dbo schema, you must give permission to ALTER it, too.

GRANT ALTER ON SCHEMA::dbo TO ccr;



However, you probably want to create a role, given the permissions to the role, and make ccr a member of the role. For instance:

CREATE ROLE ModifyTable;
GO

GRANT CREATE TABLE TO ModifyTable;
GRANT ALTER ON SCHEMA::dbo TO ModifyTable;
GO

EXEC sp_addrolemember 'ModifyTable', 'ccr';
GO

REVOKE CREATE TABLE FROM ccr;



Now, because a user has ALTER permissions on the schema, he/she can affect existing objects. So you'll have to build a DDL trigger to restrict the role to just being able to touch tables. There are examples of this in the forums and the scripts if you do a search.

K. Brian Kelley
@‌kbriankelley
SKYBVI
SKYBVI
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2999 Visits: 3239
@ k brian

Thanks a lot

Regards.
Sushant
wangxc16
wangxc16
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 42
Did you test it? It looked like not working
jlp3630
jlp3630
Say Hey Kid
Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)Say Hey Kid (693 reputation)

Group: General Forum Members
Points: 693 Visits: 704
K. Brian Kelley (5/12/2011)
Since CCR does not own the dbo schema, you must give permission to ALTER it, too.

GRANT ALTER ON SCHEMA::dbo TO ccr;



However, you probably want to create a role, given the permissions to the role, and make ccr a member of the role. For instance:

CREATE ROLE ModifyTable;
GO

GRANT CREATE TABLE TO ModifyTable;
GRANT ALTER ON SCHEMA::dbo TO ModifyTable;
GO

EXEC sp_addrolemember 'ModifyTable', 'ccr';
GO

REVOKE CREATE TABLE FROM ccr;



Now, because a user has ALTER permissions on the schema, he/she can affect existing objects. So you'll have to build a DDL trigger to restrict the role to just being able to touch tables. There are examples of this in the forums and the scripts if you do a search.



Here's some code for the DDL trigger referenced above:


-- This trigger fires on all DDL database level events (https://technet.microsoft.com/en-US/library/ms191441(v=SQL.90).aspx)
-- If the login is a member of the 'ModifyTable' role,
-- execute their DDL statement only if it is one of the following SQL statements:
-- 1. CREATE TABLE
-- 2. DROP TABLE
-- 3. ALTER TABLE
-- 4. SELECT INTO

CREATE TRIGGER db_trigger_BlockNonTableDDL
ON DATABASE
FOR DDL_DATABASE_LEVEL_EVENTS
AS
BEGIN
IF IS_MEMBER('ModifyTable') = 1
BEGIN

DECLARE @TriggerEventText nvarchar(max);
SET @TriggerEventText = EVENTDATA().value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]','nvarchar(max)')
IF NOT ((@TriggerEventText LIKE 'CREATE TABLE%') OR
(@TriggerEventText LIKE 'DROP TABLE%') OR
(@TriggerEventText LIKE 'ALTER TABLE%') OR
(@TriggerEventText LIKE 'SELECT % INTO %'))
BEGIN
RAISERROR (@TriggerEventText, 16, 1)
ROLLBACK TRANSACTION;
END
END;
END;
GO

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search