WmZilla - Webmaster and Marketplace

The Next Generation Webmaster and Trade Forum

Automatic Email Sending Issue When Data is Added to the Table

ABgamesXO

New member

0

0%

Status

Offline

Posts

41

Likes

0

Rep

0

Bits

215

3

Months of Service

0%
To create a trigger that sends an email notification when an order is placed in the database, regardless of the details, you can use the following SQL code:

```sql
CREATE TRIGGER orderTrigger ON orders FOR INSERT AS
BEGIN
DECLARE @OrderQuantity BIGINT, @msg VARCHAR(255)
SELECT @OrderQuantity = inserted.OrderQuantity FROM inserted
SET @msg = CAST(@OrderQuantity AS VARCHAR(16)) + ' orders have been placed.'
EXEC master..xp_sendmail '[email protected]', @msg
END
```

This trigger will send an email notification whenever an order is inserted into the "orders" table. The focus is on informing you when an order is received, without specific details about the order itself.
 

249

6,622

6,642

Top