0% found this document useful (0 votes)
21 views2 pages

Run Royal Document

The document outlines the database design for an Order Service and User database. It includes the SQL commands to create tables for 'orders' and 'order_items' in the Order Service DB, as well as a 'users' table in the User DB, detailing their structure, data types, and relationships. Each table has primary keys, indexes, and constraints defined to ensure data integrity and efficient querying.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Run Royal Document

The document outlines the database design for an Order Service and User database. It includes the SQL commands to create tables for 'orders' and 'order_items' in the Order Service DB, as well as a 'users' table in the User DB, detailing their structure, data types, and relationships. Each table has primary keys, indexes, and constraints defined to ensure data integrity and efficient querying.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

DB- Design

1.Orders ,Order Items in Order Service DB


CREATE TABLE `orders` (
`id` BIGINT NOT NULL AUTO_INCREMENT,
`user_id` BIGINT NOT NULL,
`status` ENUM('PENDING','COMPLETED','CANCELLED') NULL DEFAULT
'PENDING' COLLATE 'utf8mb4_0900_ai_ci',
`order_date` TIMESTAMP NULL DEFAULT (CURRENT_TIMESTAMP),
`deleted` TINYINT(1) NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_user_id` (`user_id`) USING BTREE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
AUTO_INCREMENT=7

CREATE TABLE `order_items` (


`id` BIGINT NOT NULL AUTO_INCREMENT,
`order_id` BIGINT NOT NULL,
`product_name` VARCHAR(255) NOT NULL COLLATE
'utf8mb4_0900_ai_ci',
`quantity` INT NOT NULL,
`price` DECIMAL(38,2) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
INDEX `order_id` (`order_id`) USING BTREE,
CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`)
REFERENCES `orders` (`id`) ON UPDATE NO ACTION ON DELETE CASCADE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
AUTO_INCREMENT=10
2.User in User DB

CREATE TABLE `users` (


`id` BIGINT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_0900_ai_ci',
`status` ENUM('ACTIVE','BLOCKED','INACTIVE') NULL DEFAULT 'INACTIVE'
COLLATE 'utf8mb4_0900_ai_ci',
`deleted` TINYINT(1) NULL DEFAULT '0',
`created_at` TIMESTAMP NULL DEFAULT (CURRENT_TIMESTAMP),
`updated_at` TIMESTAMP NULL DEFAULT (CURRENT_TIMESTAMP) ON
UPDATE CURRENT_TIMESTAMP,
`email` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_0900_ai_ci',
`password` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_0900_ai_ci',
`tenant` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_0900_ai_ci',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `username` (`username`) USING BTREE,
UNIQUE INDEX `username_tenant` (`username`, `tenant`) USING BTREE
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
AUTO_INCREMENT=9
;

You might also like