· 9 years ago · Dec 21, 2016, 06:00 AM
1CREATE TABLE IF NOT EXISTS `transaction` (
2 `TrCode` int(11) NOT NULL primary key auto_increament,
3 `SrNo` int(11) NOT NULL,
4 `Bill_TrCode` int(11) NOT NULL,
5 `book_type` text NOT NULL,
6 `Debit_id` int(11) NOT NULL,
7 `Credit_id` int(11) NOT NULL,
8 `year_id` int(11) NOT NULL);
9
10CREATE TABLE IF NOT EXISTS `year_master` (
11 `year_id` int(11) NOT NULL,
12 `year_name` text NOT NULL,
13 `year_start_date` date NOT NULL,
14 `year_end_date` date NOT NULL,
15 `year_active` enum('0','1') NOT NULL DEFAULT '0'
16)
17
18CREATE TRIGGER `trigger_after_insert` AFTER INSERT ON `transaction`
19 FOR EACH ROW BEGIN
20
21update transaction
22set year_id=(select year_id from year_master where year_active=1)
23where TrCode=NEW.TrCode;
24END