June 23, 2010 at 9:59 am
Hello room,
How to create SQL Server 2008 Policy that prevent a table to be deleted?
I am not sure when I created a new Condition...which Facet should I select to prevent a table
to be deleted.
Can someone give me hint and help?
Thanks,
Edwin
June 23, 2010 at 10:06 am
you want to prevent one specific table or all tables from being dropped?
i assume you mean some people have the rights/roles to drop the tables, you are not going to change their rights, but you want to prevent the drop anyway?
in that case you'll want to create a database trigger to prevent the drop from happening.
CREATE TRIGGER [TRDB_PreventTableDrop]
on DATABASE
FOR
DROP_TABLE
AS
BEGIN
--prevent and and all drop table commands in this database, even if done by sysadmins.
ROLLBACK
END
Lowell
June 23, 2010 at 10:39 am
Thanks for your time and help.
I tested your TRIGGER and it worked on AdventureWorks database.
My scenario is like this:
I created a “Marketing” database.
Then, I created several login and granted one of the user with dbowner privileges.
The user with dbowner should able to create and delete a table.
I wanted to have a notice when he is going to delete a table.
June 23, 2010 at 10:47 am
instead of having a rollback command as the body of the trigger, you can send an email instead....so you can get notification that it ALREADY happened and not rollback the command, or you can do both: send an email that says susername() tried to drop a table, and then roll back...
there's a couple of active threads right now on how to send an email that you can use as a model.
Lowell
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply