Add database schema SQL

This commit is contained in:
Augusto Gunsch 2022-07-27 20:34:39 +02:00
parent fffd25c454
commit 8988bf02c0
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
1 changed files with 42 additions and 0 deletions

42
database/schema.sql Normal file
View File

@ -0,0 +1,42 @@
CREATE DATABASE `products`;
USE `products`;
CREATE TABLE `product` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`price` float NOT NULL,
`sku` varchar(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `sku` (`sku`)
)
CREATE TABLE `book` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`weight` float NOT NULL,
`product_id` int unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `book_UN` (`product_id`),
CONSTRAINT `book_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`)
)
CREATE TABLE `dvd` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`product_id` int unsigned NOT NULL,
`size` int unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `dvd_UN` (`product_id`),
CONSTRAINT `dvd_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`)
)
CREATE TABLE `furniture` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`product_id` int unsigned NOT NULL,
`width` float NOT NULL,
`height` float NOT NULL,
`length` float NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `furniture_UN` (`product_id`),
CONSTRAINT `furniture_FK` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`)
)