Home >Database >Mysql Tutorial >Establishing a product brand table for the grocery shopping system in MySQL
Title: Establishment of commodity brand table in MySQL grocery shopping system
Introduction:
With the development of e-commerce, more and more people choose to buy online Grocery shopping system is one of the popular ways to buy food and groceries needed for daily life. When building a database for a grocery shopping system, establishing a product brand table is an essential step. This article will introduce how to use MySQL to build the product brand table of the grocery shopping system, and provide specific code examples.
1. Create database and product brand table
First, open the MySQL database terminal or other MySQL client and create a new database for the vegetable shopping system, such as "buy_vegetables".
CREATE DATABASE buy_vegetables;
Then, set the database as the currently used database.
USE buy_vegetables;
Next, create a product brand table and define the data types and attributes of each field.
CREATE TABLE `brand` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '品牌ID', `name` VARCHAR(100) NOT NULL COMMENT '品牌名称', `logo` VARCHAR(200) DEFAULT NULL COMMENT '品牌Logo图片链接', `description` TEXT COMMENT '品牌描述', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品品牌表';
In the above code, we define a table named "brand", which contains the following fields:
2. Insert sample data
After creating the product brand table, we can insert some sample data into the table for subsequent operations and queries.
INSERT INTO `brand` (`name`, `logo`, `description`) VALUES ('品牌A', 'http://example.com/logoA.png', '品牌A的描述信息'), ('品牌B', 'http://example.com/logoB.png', '品牌B的描述信息'), ('品牌C', 'http://example.com/logoC.png', '品牌C的描述信息');
The above code inserts three sample data into the brand table, namely brand A, brand B and brand C, including brand name, logo image link and brand description.
3. Practical Application
In practical applications, more fields can be added to the product brand table according to specific needs to meet different business needs. For example, you can add fields such as creation time and modification time, and can also be associated with other tables to implement more complex functions.
ALTER TABLE `brand` ADD COLUMN `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', ADD COLUMN `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间';
The above code adds "created_at" (creation time) and "updated_at" (modification time) fields to the product brand table, which are used to record the creation time and latest modification time of the brand respectively.
Summary:
Through the introduction of this article, we have learned how to use MySQL to build the product brand table of the grocery shopping system, and provided relevant code examples. In practical applications, the table structure can be expanded and optimized according to business needs to meet system requirements. Establishing a product brand table is an important part of the database design of the grocery shopping system. It provides basic support for subsequent product management and query.
The above is the detailed content of Establishing a product brand table for the grocery shopping system in MySQL. For more information, please follow other related articles on the PHP Chinese website!