我想在我的Vendor表中添加新行时显示触发器。我到目前为止所写的查询是:
CREATE TRIGGER tVendorAdded
ON Vendors
AFTER UPDATE
AS
BEGIN
INSERT INTO AlertTable
SELECT
VendorID, VendorName, GETDATE(),
'Vendor Added', 'New vendor, ' + VendorName + ', added'
FROM
inserted
WHERE --
END
GO
我要在where子句中添加什么才能实现此目的?我应该尝试一些不同/更好的东西吗?
答案 0 :(得分:1)
您不需要WHERE
条款:
CREATE TRIGGER tVendorAdded ON Vendors
AFTER UPDATE AS
BEGIN
INSERT INTO AlertTable (VendorId, VendorName, ?, ?, ?)
SELECT VendorID, VendorName, getdate(), 'Vendor Added',
'New vendor, ' + VendorName + ', added'
FROM inserted;
END;
您应该在INSERT
语句中包含列名。 ?
用于表示相应列的名称。