mysql商品表数据
时间: 2023-10-09 19:15:34 浏览: 94
根据提供的引用内容,可以创建一个名为t_product的商品表,该表包含以下字段:商品编号id(主键,自动增长)、商品名称name(非空)、生产厂家factory、商品重量weight。该表的创建语句如下:
```
create table t_product (
id int primary key auto_increment,
name varchar(20) not null,
factory varchar(100),
weight double
) charset utf8;
```
在插入商品数据时,可以使用last_insert_id()函数来获取上一条插入的商品编号id,然后将该id赋值给其他相关表的外键字段,以实现产品表和库存表的关联。例如,可以使用以下语句来插入商品数据并获取商品编号id:
```
INSERT INTO t_product (name, factory, weight) VALUES ('商品名称', '生产厂家', 1.5);
SET @product_id = LAST_INSERT_ID();
```
这样,@product_id变量就可以获取到上一条插入的商品编号id,然后可以将该id用于其他表的插入操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [mysql存储过程实现同时多表写入,构造创建商品数据](https://blog.csdn.net/weixin_43865008/article/details/119685058)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [常用mysql数据库配置文件](https://download.csdn.net/download/zslsh44/88278582)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [Mysql 创建数据库、表以及数据表基本管理](https://blog.csdn.net/weixin_48558824/article/details/124064325)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文