A
A
Amka2011-11-21 15:50:41
SQL
Amka, 2011-11-21 15:50:41

Database structure question

Actually, I would like to see some advice, maybe somehow optimize the following.

I have tables
Dishes:

CREATE  TABLE `Courses` (
  `id` INT NOT NULL ,
  `category` INT NOT NULL ,
  `title` VARCHAR(255) NOT NULL ,
  `description` TEXT NULL ,
  `price` DECIMAL(10,2) NULL ,
  `currency` INT NOT NULL )

and Ingredients :
CREATE  TABLE `Ingredients` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `title` VARCHAR(45) NOT NULL ,
  `count` INT NULL ,
  `unit` VARCHAR(45) NULL  ,
  `price` DECIMAL(10,2) NOT NULL ,
  `currency` INT NOT NULL )

Which are interconnected by the third table.

For orders, I assume the following structure:
Orders (description of the order itself):
CREATE  TABLE `Orders` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `restaurant` INT NOT NULL ,
  `client` INT NOT NULL ,
  `table` INT NOT NULL ,
  `status` TINYINT NOT NULL DEFAULT 0)


OrderCourses (ordered dishes and their quantity):
CREATE  TABLE `OrderCourses` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `order` INT NOT NULL ,
  `course` INT NOT NULL ,
  `count` INT NOT NULL)


OrderIngredients (additional ingredients for ordered dishes):
CREATE  TABLE `OrderCourses_copy1` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `order` INT NOT NULL ,
  `course` INT NOT NULL ,
  `ingredient` INT NOT NULL ,
  `count` INT NOT NULL)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arsen, 2011-11-21
@mekegi

In OrderIngredients, instead of two fields order and course, make one order_course where you will store the id from the OrderCourses table

S
sainnr, 2011-11-21
@sainnr

I agree with mekegi , I would also take out the fields separately price, currencyfrom dishes and ingredients (3 NF), it may come in handy in the future.

E
Eternalko, 2011-11-21
@Eternalko

Personally, I wouldn't mess around with the ingredients.
Even in the network of pizzerias throughout Ukraine (chelentano) they do not do this. As far as I can tell.
Custom pizzas (where the client himself chooses the ingredients) on the monitor are simply considered throwing "dishes" in your case.
It's easier to create a Course Group: Ingredients. And there are all sorts of double cheeses and sauces to write down.
That is, the order in your database, simplified according to my advice, would look like this:
Order 5
Table 3
Dishes: 2 water, 1 Pizza, 1 extra cheese, 1 garlic sauce, 1 dumplings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question