· 4 years ago · May 24, 2021, 04:46 PM
1private static final String CREATE_TABLE_COUPONS = "CREATE TABLE if not exists `Coupons`.`coupons` " +
2 "(`id` INT NOT NULL AUTO_INCREMENT," +
3 "`company_id` INT NOT NULL," +
4 "`category_id` INT NOT NULL," +
5 "`title` VARCHAR(50) NOT NULL," +
6 "`description` VARCHAR(200) NOT NULL," +
7 "`start_date` DATE NOT NULL," +
8 "`end_date` DATE NOT NULL," +
9 "`amount` INT NOT NULL," +
10 "`price` DOUBLE NOT NULL," +
11 "`image` VARCHAR(150) NOT NULL," +
12 "PRIMARY KEY (`id`)," +
13 "FOREIGN KEY(company_id) REFERENCES companies(id) ON DELETE CASCADE," +
14 "FOREIGN KEY(category_id) REFERENCES categories(id) ON DELETE CASCADE);";
15
16 private static final String CREATE_TABLE_CUSTOMERS_VS_COUPONS = "CREATE TABLE if not exists `Coupons`.`categories_vs_coupons` " +
17 "(`id` INT NOT NULL AUTO_INCREMENT," +
18 "`customer_id` INT NOT NULL," +
19 "`coupon_id` INT NOT NULL," +
20 "PRIMARY KEY (`customer_id`)," +
21 "PRIMARY KEY (`coupon_id`)," +
22 "FOREIGN KEY(customer_id) REFERENCES customers(id) ON DELETE CASCADE," +
23 "FOREIGN KEY(coupon_id) REFERENCES coupons(id) ON DELETE CASCADE);";
24