-
2023 - 07 - 15 쿼리문 Query - 테이블 생성, 수정, 삭제, 조회Today I Learned/TIL 07 2023. 7. 18. 09:39
로우쿼리로 데이터베이스 생성해보기.
CREATE TABLE Customers ( customerId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP );
CREATE TABLE Items ( itemId BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, optionId BIGINT NOT NULL DEFAULT 0, name VARCHAR(255) NOT NULL UNIQUE, price BIGINT NOT NULL, type ENUM('COFFEE', 'TEA', 'JUICE', 'DESSERT', 'SMOOTHIE') NOT NULL, amount BIGINT NOT NULL DEFAULT 0, createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (optionId) REFERENCES Options (optionId) );
CREATE TABLE Managers ( managerId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, email VARCHAR(255) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP );
CREATE TABLE Options ( optionId INT NOT NULL AUTO_INCREMENT PRIMARY KEY, extraPrice INT NOT NULL, shotPrice INT NOT NULL, is_hot BOOLEAN NOT NULL, createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP );
CREATE TABLE OrderItems ( orderItemId BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, itemId BIGINT NOT NULL, orderId BIGINT NOT NULL, amount BIGINT NOT NULL DEFAULT 0, price BIGINT NOT NULL, optionis JSON NOT NULL, createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP )
CREATE TABLE Orders ( orderId BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, userId BIGINT NOT NULL, is_User BOOLEAN NOT NULL, state ENUM('ORDERED', 'PENDING', 'COMPLETED', 'CANCELED') NOT NULL, createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP FOREIGN KEY (customerId) REFERENCES Customers (customerId) FOREIGN KEY (orderId) REFERENCES OrderItems (orderId) );
'Today I Learned > TIL 07' 카테고리의 다른 글
2023 - 07 - 17 AXIOS (0) 2023.07.20 2023 - 07 - 16 HTTP 프로토콜 (0) 2023.07.18 2023 - 07 - 14 쿼리문 Query - 데이터 생성, 수정, 삭제, 조회 (0) 2023.07.18 2023 - 07 - 13 쿼리문 Query 컬럼 (column, field) 생성, 추가, 수정, 삭제 (1) 2023.07.13 2023 - 07 - 12 레이어드 아키텍쳐 Layered Architecture Pattern (1) 2023.07.12