I am on SQL Server 2014 Standard edition. I am developing a Supply Chain DW and I am currently in the process of building a Landing schema which will be used to Land data coming out of the source system and then move that data into a Staging schema to begin the ETL process. I am truncating the landing tables after I have moved that days data into Staging. I am using Hashbytes in a Trigger which will add a hash value to each record for comparison while being moved upstream.
CREATE TRIGGER trgr_hashval_mara ON land.mara
FOR UPDATE, INSERT AS
UPDATE land.mara
SET HashVal = (SELECT hashbytes('md5', (SELECT material, MaterialDesc FOR xml raw)));
I can create these all day long, but I am unable to Drop them using conventional syntax as below. Executing the DROP statement produces an error.
DROP TRIGGER trgr_hashval_mara;
"Can't find trigger or you don't have permission to drop trigger."
However the following statement comes back with a list of Triggers I have created.
select * from ibscm01.sys.triggers
I also can't seem to find them in the DB Tree. I see the Database Triggers child, but there are no Items/triggers shown. I am using Toad for SQL server 6.7 which should be the current release. also using Windows Authentication with AD and I have dbo privileges.
Thanks,
Pat
Best Answer
Triggers will be in the same Schema as the Table that they are created on. This is either handled automatically if the Schema is not specified in the
CREATE TRIGGER
statement, or it is enforced if it is specified but not the same as the Schema of the Table. The MSDN documentation for CREATE TRIGGER states:And a simple test confirms the enforcement of this rule:
produces the following error:
The syntax for dropping a Trigger, according to the SQL Server 2012 & 2014 MSDN page for DROP TRIGGER, is (essentially):
So, if you want to know what Schema a particular Trigger (and its parent Table) is in, use the following query:
Also:
CREATE TRIGGER land.trgr_hashval_mara ON land.mara...
INSERT
andUPDATE
statement. Is that really what is desired? You need to be joining to theINSERTED
pseudo-table so that you only update rows that are actually changing.SET NOCOUNT ON;
at the top of each Trigger.