7. Database table design

  • 1. Database table ID

    The ID of the database table is generally the primary key of each table. The design of the ID generation rule should be determined according to the specific situation. The following is a good summary seen on the Internet:

For the ID generation problem of the mall system, the problems to be considered in designing ID generation rules are:
1) The database is incremented automatically, that is, it starts from 0 and increases by 1 each time. Generated when a record is inserted into a database table; this is the most popular choice for users of mysql databases. The disadvantage is that the value of a new record is not known before it is inserted into the database; the second disadvantage is that the id cannot be kept unique among multiple table records (some systems require this, which is difficult to understand.)
2) GUID string: Globally Unique Identifier (GUID, Globally Unique Identifier). A GUID is an algorithmically generated numerical identifier with a binary length of 128 bits. GUIDs are mainly used in networks or systems with multiple nodes and multiple computers. In an ideal world, no computer or cluster of computers would generate two identical GUIDs. The total number of GUIDs reaches 2^128 (3.4×10^38), so the possibility of randomly generating two identical GUIDs is very small, but not 0. The term GUID also sometimes refers specifically to Microsoft's implementation of the UUID standard. The disadvantage is that the field type must be a string, and the sorting and performance are not as good as the numeric type.
3) Timestamp: accurate to milliseconds, which means that when multiple records are generated in the same millisecond, the id may be repeated, resulting in the failure of new records to be inserted.
4) Custom function The generation of the id of some key tables in the
super table has the following requirements:
① High performance, preferably a numeric type, not a string;
② Generated in advance (rather than after inserting into the database), that is It is generated when the user enters the page;
③ This table is not only required to be unique, but also cannot be duplicated with the id recorded in other tables. Because some common tables will record the ids of records from different tables together.

    Here, our system is very simple, we use the number type for ID and increase it automatically.

 

  • 2. Form preliminary design
   1) User form
CREATE TABLE `user` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `email` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
       2) Commodity form
CREATE TABLE `commodity` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL COMMENT 'trade name',
  `descr` varchar(1000) DEFAULT NULL COMMENT 'Product description',
  `picurl` varchar(255) DEFAULT NULL COMMENT 'Home thumbnail',
  `price` double(10,0) DEFAULT NULL COMMENT '价格',
  `stock` int(10) DEFAULT NULL COMMENT 'stock',
  `category_id` int(255) DEFAULT NULL COMMENT 'category',
  `url1` varchar(255) DEFAULT NULL COMMENT 'Detail page picture 1',
  `url2` varchar(255) DEFAULT NULL COMMENT 'Detail page picture 2',
  `url3` varchar(255) DEFAULT NULL COMMENT 'Detail page picture 3',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8;
 
    3) shopping cart product form
CREATE TABLE `cartcom` (
  `id` int(255) NOT NULL AUTO_INCREMENT,
  `buy_num` int(10) DEFAULT NULL COMMENT 'Buy quantity',
  `user_id` int(255) DEFAULT NULL COMMENT 'Shopping cart ID',
  `com_id` int(255) DEFAULT NULL COMMENT '商品ID',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8;
 
    4) Product category table
CREATE TABLE `category` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `tmenu` varchar(255) DEFAULT NULL COMMENT 'type',
  `smenu` varchar(255) DEFAULT NULL COMMENT 'Classic',
  `fmenu` varchar(255) DEFAULT NULL COMMENT 'Navigation',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8;

 

    Initial data:

INSERT INTO `category` VALUES ('4', 'Shirts', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('5', 'Sports Wear', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('6', 'Shorts', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('7', 'Suits & Blazers', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('8', 'Formal Shirts', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('9', 'Sweatpants', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('10', 'Swimwear', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('11', 'Trousers & Chinos', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('12', 'T-Shirts', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('13', 'Underwear & Socks', 'All Clothing', 'men');
INSERT INTO `category` VALUES ('14', 'Formal Shoes', 'Footwear', 'men');
INSERT INTO `category` VALUES ('15', 'Boots', 'Footwear', 'men');
INSERT INTO `category` VALUES ('16', 'Sports Shoes', 'Footwear', 'men');
INSERT INTO `category` VALUES ('17', 'Casual Shoes', 'Footwear', 'men');
INSERT INTO `category` VALUES ('18', 'Running Shoes', 'Footwear', 'men');
INSERT INTO `category` VALUES ('19', 'Sneakers', 'Footwear', 'men');
INSERT INTO `category` VALUES ('20', 'Loafers', 'Footwear', 'men');
INSERT INTO `category` VALUES ('21', 'Slippers', 'Footwear', 'men');
INSERT INTO `category` VALUES ('22', 'Sandals', 'Footwear', 'men');
INSERT INTO `category` VALUES ('23', 'Flip-flops', 'Footwear', 'men');
INSERT INTO `category` VALUES ('24', 'Levis', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('25', 'Persol', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('26', 'Nike', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('27', 'Edwin', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('28', 'New Balance', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('29', 'Jack & Jones', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('30', 'Paul Smith', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('31', 'Ray-Ban', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('32', 'Wood Wood', 'Popular Brands', 'men');
INSERT INTO `category` VALUES ('33', 'Shirts & Tops', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('34', 'Sports Wear', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('35', 'Kurtas & Kurties', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('36', 'Suits & Blazers', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('37', 'Sarees', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('38', 'Sweatpants', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('39', 'Swimwear', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('40', 'Night-Suits', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('41', 'T-Shirts', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('42', 'Jeans', 'All Clothing', 'women');
INSERT INTO `category` VALUES ('43', 'Heels', 'Footwear', 'women');
INSERT INTO `category` VALUES ('44', 'Flats', 'Footwear', 'women');
INSERT INTO `category` VALUES ('45', 'Sports Shoes', 'Footwear', 'women');
INSERT INTO `category` VALUES ('46', 'Casual Shoes', 'Footwear', 'women');
INSERT INTO `category` VALUES ('47', 'Running Shoes', 'Footwear', 'women');
INSERT INTO `category` VALUES ('48', 'Wedges', 'Footwear', 'women');
INSERT INTO `category` VALUES ('49', 'Boots', 'Footwear', 'women');
INSERT INTO `category` VALUES ('50', 'Pumps', 'Footwear', 'women');
INSERT INTO `category` VALUES ('51', 'Slippers', 'Footwear', 'women');
INSERT INTO `category` VALUES ('52', 'Flip-flops', 'Footwear', 'women');
INSERT INTO `category` VALUES ('53', 'Levis', 'Popular Brands', 'women');
INSERT INTO `category` VALUES ('54', 'Persol', 'Popular Brands', 'women');
INSERT INTO `category` VALUES ('55', 'Nike', 'Popular Brands', 'women');
INSERT INTO `category` VALUES ('56', 'Edwin', 'Popular Brands', 'women');
INSERT INTO `category` VALUES ('57', 'New Balance', 'Popular Brands', 'women');
INSERT INTO `category` VALUES ('58', 'Jack & Jones', 'Popular Brands', 'women');
INSERT INTO `category` VALUES ('59', 'Paul Smith', 'Popular Brands', 'women');
INSERT INTO `category` VALUES ('60', 'Ray-Ban', 'Popular Brands', 'women');
INSERT INTO `category` VALUES ('61', 'Wood Wood', 'Popular Brands', 'women');

 

    The data of the commodity table can also be initialized:

INSERT INTO `commodity` VALUES ('1', 't-shirt1', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/1.jpg', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('2', 't-shirt2', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/2.jpg', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('3', 't-shirt3', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/1.jpg', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('4', 't-shirt4', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/2.jpg', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('5', 't-shirt5', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/1.jpg', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('6', 't-shirt6', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('7', 't-shirt7', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('8', 't-shirt8', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('9', 't-shirt9', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('10', 't-shirt10', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('11', 't-shirt11', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('12', 't-shirt12', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('13', 't-shirt13', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('14', 't-shirt14', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('15', 't-shirt15', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('16', 't-shirt16', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('17', 't-shirt17', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('18', 't-shirt18', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('19', 't-shirt19', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');
INSERT INTO `commodity` VALUES ('20', 't-shirt20', 'Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old.', '/images/pi.png', '100', '20000', '4', '/images/si.jpg', '/images/si1.jpg', '/images/si2.jpg');

 

    

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326516359&siteId=291194637