Search
 
SCRIPT & CODE EXAMPLE
 

SQL

trigger After

CREATE DATABASE productdb;
GO
--create a table called Products
USE productdb;
CREATE TABLE Products
(
    Id INT IDENTITY PRIMARY KEY,
    ProductName NVARCHAR(30) NOT NULL,
    Manufacturer NVARCHAR(20) NOT NULL,
    ProductCount INT DEFAULT 0,
    Price MONEY NOT NULL
);

--create a trigger called Products_INSERT_UPDATE
CREATE TRIGGER Products_INSERT_UPDATE
ON Products
AFTER INSERT, UPDATE
AS
UPDATE Products
SET Price = Price + Price * 0.38
WHERE Id = (SELECT Id FROM inserted)

--one example
ISERT INTO Products(ProductName,Manufacturer,ProductCount,Price)
VALUES ('IPhone X',2,'Apple',68000)
SELECT * FROM Products
--answer will be Price = 9384000

--Turn off trigger
DISABLE TRIGGER Products_INSERT_UPDATE ON Products

--Turn on trigger
ENABLE TRIGGER Products_INSERT_UPDATE ON Products

--Delete trigger
DROP TRIGGER Products_INSERT_UPDATE
Comment

PREVIOUS NEXT
Code Example
Sql :: how to add new column with default value in sql server 
Sql :: sql float 3 decimal places 
Sql :: SQL AVG() Function 
Sql :: como hacer un select entre fechas mysql 
Sql :: sql get actual fiscal year 
Sql :: sql not equal to operator 
Sql :: get last record deluge 
Sql :: select year from dual oracle 
Sql :: c# sql conennection string 
Sql :: oracle cast boolean to varchar2 
Sql :: sql server fn_dblog 
Sql :: postgres between dates 
Sql :: datetrunc month sql 
Sql :: how to show current database in mysql 
Sql :: bigquery information_schema schema all columns 
Sql :: alter database datafile maxsize 32g 
Sql :: how to verify sequence result in oracle SQL 
Sql :: SQL COMO ALTERA NOME DE TABELA 
Sql :: create column that already exists mysql 
Sql :: sql select inside select sub query 
Sql :: mysql select smaller of two values 
Sql :: postgres create trigger if not exists 
Sql :: SQL CREATE INDEX Constraint 
Sql :: clone row from another table mysql 
Sql :: how to install mysql workbench in ubuntu 20.04 
Sql :: how to use join with 3 tables in sql server 
Sql :: sqlstate[hy000] [2006] mysql server has gone away laravel 
Sql :: oracle sql procedure return value 
Sql :: SQL JOIN and Aliases 
Sql :: sql transaction 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =