Re: How to prevent DELETEs in a table

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Aaron [SQL Server MVP] (ten.xoc_at_dnartreb.noraa)
Date: 01/03/05


Date: Mon, 3 Jan 2005 17:12:56 -0500

You could create a trigger, e.g.

USE tempdb
GO

CREATE TABLE Employees (id INT, name CHAR(5))
GO

CREATE TRIGGER no_delete
ON Employees
FOR DELETE
AS
 ROLLBACK
 RAISERROR('No deletes!', 11, 1)
GO

INSERT Employees SELECT 1, 'Aaron'
INSERT Employees SELECT 2, 'Frank'
INSERT Employees SELECT 3, 'Henry'
GO

SELECT * FROM Employees
GO

DELETE Employees WHERE id=3
GO

SELECT * FROM Employees
GO

DROP TABLE Employees

-- 
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@nospam.ru> wrote in message
news:#korZ3d8EHA.1300@TK2MSFTNGP14.phx.gbl...
> What is the best way to prohibit deletes in a table?
>
> I thought this would work:
>
> DENY DELETE ON EMPLOYEES TO public
>
> But after executing the above statement I can still perform DELETEs in the
> table.
>
> What don't I understand?
>
>


Relevant Pages

  • Re: Update trigger works in SQL Server but NOT in Access adp datasheet
    ... The Access error ... Put a SET NOCOUNT ON as the first thing you do in the trigger and see if ... otherwise your Employees will no be updated correctly. ... I have a SQL Server database and an Access adp frontend. ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Can I Pass a Table Name as a Parameter?
    ... of sync so you will never require said trigger functionality??? ... To this end, we have an Employees table, and an Offices table. ... StartDate and EndDate. ... in that too, but given the design we have, I don't think I'm trying to do ...
    (microsoft.public.sqlserver.programming)
  • Re: Can I Pass a Table Name as a Parameter?
    ... Surely Updating the table where the startdate < now and then doing the ... of sync so you will never require said trigger functionality??? ... To this end, we have an Employees table, and an Offices table. ... StartDate and EndDate. ...
    (microsoft.public.sqlserver.programming)
  • Re: Can I Pass a Table Name as a Parameter?
    ... To this end, we have an Employees table, and an Offices table. ... The first three of these cannot be null, but EndDate may be ... that too, but given the design we have, I don't think I'm trying to do ... Surely any rule you create writing a trigger can be replicated within a SP ...
    (microsoft.public.sqlserver.programming)
  • Chain of triggers - how to break it?
    ... employees clock in and out at various locations. ... table is called tblTSRule. ... The table that stores this data is called tblTSEmpRules. ... to have an INSERT trigger on the tblTSRule, ...
    (comp.databases.ms-sqlserver)