INSERT INTO语句期间的访问自动递增值 [英] Access Auto-Increment Value During INSERT INTO Statement

查看:517
本文介绍了INSERT INTO语句期间的访问自动递增值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用MySQL。我有一个表有一个auto_increment'id'字段和一个'imgname'字段包含一个字符串是一个图像的文件名。

I am currently using MySQL. I have a table that has an auto_increment 'id' field, and an 'imgname' field containing a string that is the file name of an image.

我需要生成'imgname'值使用由INSERT INTO语句创建的auto_increment值。问题是,我不知道这个值,直到我可以使用mysql_insert_id,插入查询运行后。我想知道是否可以访问这个值DURING插入查询某种程度,然后使用它来生成我的字符串在查询语句。

I need to generate the 'imgname' value using the auto_increment value that is create by an INSERT INTO statement. The problem is, I don't know this value until I can use mysql_insert_id, AFTER the insert query has run. I would like to know if it's possible to access this value DURING the insert query somehow and then use it to generate my string in the query statement.

提前感谢。 / p>

Thanks in advance.

推荐答案

我会保留 id imgname 彼此独立,并在需要时将 SELECT 组合起来。如果需要足够频繁,请创建视图

I would keep the id and imgname independent of each other and combine the two on SELECT when needed. If the need is frequent enough, create a view.

这篇关于INSERT INTO语句期间的访问自动递增值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆