SQL Server “AFTER INSERT” trigger doesn't see the just-inserted row

后端 未结 12 1995
庸人自扰
庸人自扰 2020-12-23 14:05

Consider this trigger:

ALTER TRIGGER myTrigger 
   ON someTable 
   AFTER INSERT
AS BEGIN
  DELETE FROM someTable
         WHERE ISNUMERIC(someField) = 1
END         


        
12条回答
  •  情深已故
    2020-12-23 14:26

    Your "trigger" is doing something that a "trigger" is not suppose to be doing. You can simple have your Sql Server Agent run

    DELETE FROM someTable
    WHERE ISNUMERIC(someField) = 1
    

    every 1 second or so. While you're at it, how about writing a nice little SP to stop the programming folk from inserting errors into your table. One good thing about SP's is that the parameters are type safe.

提交回复
热议问题