add batch
remove batch
split batch
comment selection
show hidden batches
hide batch
highlight batch
db<>fiddle
Db2
Firebird
MariaDB
MySQL
Node.js
Oracle
Postgres
SQLite
SQL Server
TimescaleDB
YugabyteDB
Developer-C 11.1
3.0
4.0
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
5.5
5.6
5.7
8.0
18
11g Release 2
18c
21c
23c
8.4
9.3
9.4
9.5
9.6
10
11
12
13
14
15
16
3.8
3.16
3.27
3.39
2012
2014
2016
2017
2017 (Linux)
2019
2019 (Linux)
2022
2.11
2.6
2.8
2.18
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
Sakila
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
AdventureWorks
no sample DB
no sample DB
AdventureWorks
no sample DB
no sample DB
no sample DB
no sample DB
run
markdown
donate
feedback
about
By using db<>fiddle, you agree to license everything you submit by
Creative Commons CC0
.
CREATE TABLE `Employees` ( `Worker_Id` Int NOT NULL AUTO_INCREMENT, `Worker_Name` Char(150) NOT NULL, `Job` Varchar(100), `Salary` Decimal(10,2), PRIMARY KEY (`Worker_Id`) ); CREATE TABLE `Salary_Transaction` ( `Salary_Transaction_Id` Int NOT NULL AUTO_INCREMENT, `money_amount` Decimal(10,2) NOT NULL, `Worker_Id` Int, PRIMARY KEY (`Salary_Transaction_Id`) ); CREATE TABLE `debt_alerts` ( `Debt_alert_id` Int NOT NULL AUTO_INCREMENT, `Salary_Transaction_Id` Int, `Remaining_money` Decimal(10,2), PRIMARY KEY (`Debt_alert_id`) ) ENGINE = InnoDB AUTO_INCREMENT = 1 ; ALTER TABLE `debt_alerts` ADD CONSTRAINT `Relationship23` FOREIGN KEY (`Salary_Transaction_Id`) REFERENCES `Salary_Transaction` (`Salary_Transaction_Id`) ON DELETE CASCADE ON UPDATE CASCADE; ALTER TABLE `Salary_Transaction` ADD CONSTRAINT `Relationship11` FOREIGN KEY (`Worker_Id`) REFERENCES `Employees` (`Worker_Id`) ON DELETE CASCADE ON UPDATE CASCADE;
-- INSERT INTO Employees VALUES (...); -- SELECT * FROM Employees;
CREATE trigger Remainig_money_calc AFTER INSERT ON Salary_Transaction FOR EACH ROW INSERT INTO debt_alerts(Remaining_money) SELECT y.y-x.x FROM ( SELECT SUM(money_amount) x FROM Salary_Transaction WHERE Salary_Transaction_Id = NEW.Salary_Transaction_Id ) x JOIN ( SELECT Employees.Salary y FROM Employees WHERE NEW.Worker_Id=Employees.Worker_Id LIMIT 1 ) y;
-- transaction 1 -- INSERT INTO Salary_Transaction VALUES (...) -- SELECT * FROM Salary_Transaction; -- SELECT * FROM debt_alerts; -- transaction 2 -- INSERT INTO Salary_Transaction VALUES (...) -- SELECT * FROM Salary_Transaction; -- SELECT * FROM debt_alerts;