douqian5920 2014-10-24 19:37
浏览 20

将id的值赋给insert查询中的任何列

Description :

I have an insert query that inserts data perfectly..

Now to keep track of record I have a product_id which is same as the id of the table which is auto increment

the method I am using is I get the last id in the table , increment it and assign the value to product_id.. It works perfectly but there is a bug in my code and that is when the table is empty there is no last id to fetch and increment ...

So by default it gets 0 , increments it to 1 and assigns the value to product id ...

this starts to work perfectly when the query is run again because the second time there actually is last id to fetch

So table looks something like this

what I want is

id | post_id

231 | 1

232 | 232

what I want is

id | post_id

231 | 231

232 | 232

So is there any way that I upon inserting the data could assign the value of id to product_id so they both are equal as if there were two auto increments ... Anyone ??

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度