Dimitar23308

Домашна работа

Nov 19th, 2025
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.81 KB | None | 0 0
  1. не съм сигурен в форейн ключовете това с което се референсват
  2.  
  3. create database online_magazin_db;
  4. use online_magazin_db;
  5.  
  6. create table customers (
  7.     customer_id int auto_increment primary key,
  8.     name varchar(100) not null,
  9.     email varchar(100) unique not null,
  10.     address varchar(200),
  11.     phone varchar(20)
  12. );
  13.  
  14. create table categories (
  15.     category_id int auto_increment primary key,
  16.     category_name varchar(100) not null
  17. );
  18.  
  19. create table suppliers (
  20.     supplier_id int auto_increment primary key,
  21.     supplier_name varchar(100) not null,
  22.     contact varchar(100),
  23.     supplier_address varchar(200)
  24. );
  25.  
  26. create table products (
  27.     product_id int auto_increment primary key,
  28.     product_name varchar(100) not null,
  29.     price decimal(10,2) not null,
  30.     quantity int not null,
  31.     category_id int,
  32.     supplier_id int,
  33.     foreign key (category_id) references categories(category_id),
  34.     foreign key (supplier_id) references suppliers(supplier_id)
  35. );
  36.  
  37. create table orders (
  38.     order_id int auto_increment primary key,
  39.     customer_id int,
  40.     order_date date not null,
  41.     total_amount decimal(10,2),
  42.     foreign key (customer_id) references customers(customer_id)
  43. );
  44.  
  45. create table order_items (
  46.     order_item_id int auto_increment primary key,
  47.     order_id int,
  48.     product_id int,
  49.     quantity int not null,
  50.     price decimal(10,2) not null,
  51.     foreign key (order_id) references orders(order_id),
  52.     foreign key (product_id) references products(product_id)
  53. );
  54.  
  55. create table payments (
  56.     payment_id int auto_increment primary key,
  57.     order_id int,
  58.     payment_date date not null,
  59.     amount decimal(10,2) not null,
  60.     method enum('cash','card','online') not null,
  61.     foreign key (order_id) references orders(order_id)
  62. );
  63.  
Advertisement
Add Comment
Please, Sign In to add comment