I am getting an error and can't figure out what I am doing wrong. I am creating a trigger on a table to archive this table daily. The table is truncated and new data is inserted in the morning every day. I want to archive it once this happens.
This is my code to create the trigger:
IF OBJECT_ID('trg_archive_inventory_table') IS NOT NULL
DROP TRIGGER trg_archive_inventory_table
GO
CREATE TRIGGER trg_archive_inventory_table
ON inventory
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
/* delete data from one year ago */
DELETE FROM [cadc].[dbo].[inventory_archive]
WHERE entry_date = CAST((DATEADD(yy, -1, GetDate())) as DATE);
/* insert todays inventory */
INSERT INTO [cadc].[dbo].[inventory_archive] (sku, tag_id , load_id, batch, status, qc_status, location, eaches, units, cartons, r_date, e_date, zone_1, zone_2, loc_type, loc_pick, mod_time, receiver_no, mfg_code, each_unit, unit_carton)
SELECT
sku, tag_id , load_id, batch, status, qc_status, location, eaches,
units, cartons, r_date, e_date, zone_1, zone_2, loc_type, loc_pick,
mod_time, receiver_no, mfg_code, each_unit, unit_carton
FROM
[cadc].[dbo].[inventory];
END
I keep getting the following error:
'CREATE/ALTER TRIGGER' does not allow specifying the database name as a prefix to the object name.
I have also tried prefixing the inventory table with [cadc].[dbo].[inventory] but I receive the same error.
Googling has help understand the problem.
Any help would be great.
[cadc].[dbo].[inventory]- you must restrict yourself to a two-part name (schema + object name) only -[dbo].[inventory]