| 1 |
create table product ( |
| 2 |
category int not null, |
| 3 |
id int not null, |
| 4 |
price decimal, |
| 5 |
primary key(category, id)) |
| 6 |
engine=ndb; |
| 7 |
create table customer ( |
| 8 |
id int not null, |
| 9 |
primary key (id)) |
| 10 |
engine=ndb; |
| 11 |
create table product_order ( |
| 12 |
no int not null auto_increment, |
| 13 |
product_category int not null, |
| 14 |
product_id int not null, |
| 15 |
customer_id int not null, |
| 16 |
primary key(no), |
| 17 |
index (product_category, product_id), |
| 18 |
constraint fk1 |
| 19 |
foreign key (product_category, product_id) references product(category, id) |
| 20 |
on update restrict on delete cascade, |
| 21 |
index (customer_id), |
| 22 |
constraint fk2 |
| 23 |
foreign key (customer_id) references customer(id)) |
| 24 |
engine=ndb; |
| 25 |
show create table product; |
| 26 |
Table Create Table |
| 27 |
product CREATE TABLE `product` ( |
| 28 |
`category` int NOT NULL, |
| 29 |
`id` int NOT NULL, |
| 30 |
`price` decimal(10,0) DEFAULT NULL, |
| 31 |
PRIMARY KEY (`category`,`id`) |
| 32 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 33 |
show create table customer; |
| 34 |
Table Create Table |
| 35 |
customer CREATE TABLE `customer` ( |
| 36 |
`id` int NOT NULL, |
| 37 |
PRIMARY KEY (`id`) |
| 38 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 39 |
show create table product_order; |
| 40 |
Table Create Table |
| 41 |
product_order CREATE TABLE `product_order` ( |
| 42 |
`no` int NOT NULL AUTO_INCREMENT, |
| 43 |
`product_category` int NOT NULL, |
| 44 |
`product_id` int NOT NULL, |
| 45 |
`customer_id` int NOT NULL, |
| 46 |
PRIMARY KEY (`no`), |
| 47 |
KEY `product_category` (`product_category`,`product_id`), |
| 48 |
KEY `customer_id` (`customer_id`), |
| 49 |
CONSTRAINT `fk1` FOREIGN KEY (`product_category`, `product_id`) REFERENCES `product` (`category`, `id`) ON DELETE CASCADE ON UPDATE RESTRICT, |
| 50 |
CONSTRAINT `fk2` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) |
| 51 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 52 |
insert into product values (1,1,5); |
| 53 |
insert into customer value (1); |
| 54 |
insert into product_order value (1,1,1,1); |
| 55 |
drop table product_order, customer, product; |
| 56 |
show create table product; |
| 57 |
Table Create Table |
| 58 |
product CREATE TABLE `product` ( |
| 59 |
`category` int NOT NULL, |
| 60 |
`id` int NOT NULL, |
| 61 |
`price` decimal(10,0) DEFAULT NULL, |
| 62 |
PRIMARY KEY (`category`,`id`) |
| 63 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 64 |
show create table customer; |
| 65 |
Table Create Table |
| 66 |
customer CREATE TABLE `customer` ( |
| 67 |
`id` int NOT NULL, |
| 68 |
PRIMARY KEY (`id`) |
| 69 |
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 70 |
show create table product_order; |
| 71 |
Table Create Table |
| 72 |
product_order CREATE TABLE `product_order` ( |
| 73 |
`no` int NOT NULL AUTO_INCREMENT, |
| 74 |
`product_category` int NOT NULL, |
| 75 |
`product_id` int NOT NULL, |
| 76 |
`customer_id` int NOT NULL, |
| 77 |
PRIMARY KEY (`no`), |
| 78 |
KEY `product_category` (`product_category`,`product_id`), |
| 79 |
KEY `customer_id` (`customer_id`), |
| 80 |
CONSTRAINT `fk1` FOREIGN KEY (`product_category`, `product_id`) REFERENCES `product` (`category`, `id`) ON DELETE CASCADE ON UPDATE RESTRICT, |
| 81 |
CONSTRAINT `fk2` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`) |
| 82 |
) ENGINE=ndbcluster AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
| 83 |
drop table product_order, customer, product; |