About 50,900 results
Open links in new tab
  1. How to delete trigger in SQL Server? - Stack Overflow

    Jul 12, 2015 · You can remove a trigger by dropping it or by dropping the trigger table. When a table is dropped, all associated triggers are also dropped. When a trigger is dropped, information about the trigger is removed from the sysobjects and syscomments system tables. Use DROP TRIGGER and CREATE TRIGGER to rename a trigger.

  2. SQL Server ON DELETE Trigger - Stack Overflow

    Apr 3, 2012 · CREATE TRIGGER sampleTrigger ON database1.dbo.table1 FOR DELETE AS DELETE FROM database2.dbo.table2 childTable WHERE bar = 4 AND exists (SELECT id FROM deleted where deleted.id = childTable.id) GO Share

  3. sql - drop trigger if exists and create - Stack Overflow

    Jun 6, 2017 · AND, you don't specify the table name for DROP TRIGGER since the trigger is an object by itself (unlike indexes). So you need to remove the ON clause (which is only used with DDL and Logon triggers). IF EXISTS (SELECT * FROM sys.objects WHERE [name] = N'trg' AND [type] = 'TR') BEGIN DROP TRIGGER [dbo].[trg]; END;

  4. insert/delete/update trigger in SQL server - Stack Overflow

    ALTER TRIGGER Update_StockQuantity ON dbo.[Order Details] AFTER INSERT, UPDATE, DELETE AS BEGIN declare @productId int declare @quantity smallint declare @quantityBefore smallint --Read Table Before Update SELECT ProductID, ProductName, UnitsInStock FROM Products WHERE ProductID = @productId -- UPDATE IF EXISTS (SELECT * FROM inserted) …

  5. How to create a before delete trigger in SQL Server?

    May 4, 2012 · What will happen is, when a record (or records!) are deleted from your table, the deleted row will be inserted into my_audit_table The DELETED table is a virtual table that contains the record(s) as they were immediately prior to the delete. Also, note that the trigger runs as part of the implicit transaction on the delete statement, so if your ...

  6. t sql - How do I cancel a Delete in SQL - Stack Overflow

    Aug 10, 2014 · The solution used the Instead of Delete trigger. The Rollback tran stopped the delete. I was afraid that I would have a cascade issue when I did the delete but that did'nt seem to happen. Maybe a trigger cannot trigger itself. Anyhow, thanks all for your help.

  7. sql server 2008 - Delete trigger on multiple rows - Stack Overflow

    Jul 19, 2012 · ALTER TRIGGER [dbo].[trgPaxeDeleted] ON [dbo].[paxe] AFTER DELETE AS declare @HFflightID int, @RFflightID int BEGIN Select @HFflightID = hfFlightID, @RFflightID = rfFlightID from deleted -- Hinflug: flugKontingent hochsetzen -- UPDATE flightdata SET flightQuota = flightQuota + 1 WHERE (flightID = @HFflightID) -- Rückflug: flugKontingent ...

  8. sql - Trigger to prevent Any Deleting from Table - Stack Overflow

    Jan 31, 2017 · a trigger for this new rental history table that prevents deletions from the table. CREATE OR REPLACE TRIGGER RENTALHIS_DEL BEFORE DELETE ON RENTALHISTORY BEGIN dbms_output.put_line( 'Records can not be deleted'); END; DELETE FROM RENTALHISTORY WHERE RENTALID = 1; -- It is deleting before it says it can not delete 1 …

  9. SQL Server trigger: Delete From Table AFTER DELETE

    Ideally, your trigger would be an after-statement trigger, but SQL Server does not support this. Unlike defined in the SQL standard, every trigger in SQL Server is a FOR EACH ROW trigger implicitly. In a FOR EACH ROW trigger you can access the deleted car row. But this is not done via car.aid, but with (select aid from deleted) in SQL Server.

  10. sql - Delete records within Instead Of Delete trigger - Stack Overflow

    Jul 8, 2015 · None of the answers above worked for me, I am assuming people were using SQL 2008 so this answer works for SQL 2012. CREATE TRIGGER People_LogTriggerDelete ON People INSTEAD OF DELETE AS SET NOCOUNT ON; INSERT INTO People_AuditLog (Event, Date, Id, Name, LastName, SqlUser) SELECT 'DELETE', GETDATE(), d.Id, d.Name, …

Refresh