Design of database tables

Source: Internet
Author: User

It's not a database table design, big God.

Recently made order system, there is a problem with this,

Have Customer table, order form, set table.

The order form is generated by placing orders. Change Order status code to 1 after payment (indicates payment has been made)

(1) If a order 2 parts of braised chicken rice, 1 bottles of mineral water, then how this order to save this data?

Analysis:

Will the entire order system also be able to modify the order content that has been placed but not paid by the user? (Maybe it's better to cancel the order directly)

The number of each package to be placed in a food_numbers field, where is this field appropriate? Not foods this food plan, because the foods table is purely food package information.

To have a table that can hold the food_id and Food_numbers of the selected packages (but if, for example, using string fields, storing food_name,food_numbers, and the price of a single pen * quantity)

(2) The field through varchar (2) can not be re-checked, not too flexible.

If there is a shopping cart table, (actually can think of as order_id, order form)

Each small order holds the order sequence ID, user ID, and food package ID, and the order quantity for this package.

This allows you to modify the number of food_id through the cart_id, and to save different food_id and quantities through this.

The cart_id is then added to the order table as a foreign key, but the cart_id must remain the same rather than the sequence generated.

(3) A person shopping, usually with a shopping cart, shopping basket.

The user buys a variety of food and quantity at the same time. Press the [order] button, at which time only one cart_id is generated, but the tuple for this purchase order in the table has several different rows of tuples.

The DAO layer can get the value of the next sequence to be inserted, while conducting two of DAO's SQL connection to the database (because you want to insert data customer_id,food_id and Food_numbers)

In other words, this Insertnewcart service layer receives a data like this:

Importjava.util.ArrayList; Public classCarts {Private Longcart_id;//Shopping Cart ID    Private Longcustomer_id;//User ID    PrivateArraylist<long> food_id;//Food (product) ID    PrivateArraylist<integer> food_numbers;//Food Quantity Value    /////* Create this object after the customer orders new carts (receive a shopping cart data)     PublicCarts (LongCART_ID,Longcustomer_id, arraylist<long> food_id, arraylist<integer>food_numbers) {         This. cart_id =cart_id;  This. customer_id =customer_id;  This. food_id =food_id;  This. Food_numbers =food_numbers; }}

But the transmitted data should be multiple, that is, the set of food_id and Food_numbers.

And cart_id is one, the user ID (customer_id) is one, and the two IDs are just the same at a time,

The food and quantity in the shopping cart is not fixed, so use ArrayList to store them.

(4) Using Cartsservice

Design of database tables

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.