23 lines
2.7 KiB
MySQL
Raw Normal View History

2019-04-16 16:06:26 +02:00
CREATE TABLE IF NOT EXISTS test(id bigint primary key auto_increment, hello varchar(25));
2019-04-15 18:36:03 +02:00
INSERT IGNORE INTO test(hello) values ('Welt');
2019-04-16 16:06:26 +02:00
CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, title varchar(50), description varchar(500), price int, year year, publisher bigint, category bigint, image varchar(11) unique);
2019-04-15 18:36:03 +02:00
CREATE TABLE IF NOT EXISTS publisher(id bigint primary key auto_increment, name varchar(50) unique);
CREATE TABLE IF NOT EXISTS author(id bigint primary key auto_increment, name varchar(50) unique);
CREATE TABLE IF NOT EXISTS author_book(author bigint, book bigint, primary key(author, book), foreign key (author) REFERENCES author(id), foreign key (book) references book(id));
CREATE TABLE IF NOT EXISTS category(id bigint primary key auto_increment, name varchar(25), image varchar(11));
CREATE TABLE IF NOT EXISTS user(id bigint primary key auto_increment, name varchar(50), email varchar(255), password binary(40), type tinyint);
CREATE TABLE IF NOT EXISTS address(id bigint primary key auto_increment, street varchar(100), number smallint, zipCode smallint, city varchar(50));
CREATE TABLE IF NOT EXISTS user_address(id bigint primary key auto_increment, user bigint, address bigint, foreign key (user) REFERENCES user(id), foreign key (address) references address(id));
CREATE TABLE IF NOT EXISTS payment_type(id bigint primary key auto_increment, name varchar(25) unique);
INSERT IGNORE INTO payment_type (name) values ('CreditCard');
INSERT IGNORE INTO payment_type (name) values ('DebitCard');
INSERT IGNORE INTO payment_type (name) values ('Invoice');
INSERT IGNORE INTO payment_type (name) values ('PayPal');
CREATE TABLE IF NOT EXISTS payment_debit(id bigint primary key auto_increment, iban varchar(34), bic varchar(8), owner varchar(50));
CREATE TABLE IF NOT EXISTS payment_credit(id bigint primary key auto_increment, number varchar(19), owner varchar(50), expiration DATE, checksum tinyint);
CREATE TABLE IF NOT EXISTS payment_invoice(id bigint primary key auto_increment);
CREATE TABLE IF NOT EXISTS payment_paypal(id bigint primary key auto_increment, mail varchar(255), auth varchar(255));
CREATE TABLE IF NOT EXISTS `order`(id bigint primary key auto_increment, user bigint, price bigint);
CREATE TABLE IF NOT EXISTS order_book(`order` bigint, book bigint, count tinyint, primary key (`order`, book, count), foreign key (`order`) references `order`(id), foreign key (book) references `order`(id));
CREATE TABLE IF NOT EXISTS shopping_cart(id bigint primary key auto_increment);
CREATE TABLE IF NOT EXISTS cart_books(user bigint, book bigint, count tinyint, primary key(book, user), foreign key (book) REFERENCES book(id), foreign key (user) REFERENCES user(id));