在线免费观看国产福利_A级毛片免费全部播放无码软件_fc国产日韩精品综合在线_一级毛片成人免费看完整版_久久亚洲热线2021精品_国产99视频精品免视看91_亚洲 欧美 制服 国产_男人的天堂最新网址_国产精品免费AV探花_中文字幕无码第1页

小助手科技_小程序定制開發(fā)圖片

小助手科技_小程序定制開發(fā)圖片

小助手科技_小程序定制開發(fā)圖片

小助手科技_小程序定制開發(fā)圖片

小助手科技_小程序定制開發(fā)圖片

關于將表中自增長字段賦值給另外一個字段的方法

作者: 梧桐下細語
來源: http://spemc.cn
時間: Aug 19, 2020
當前位置:  小助手科技 > 資訊 > 關于將表中自增長字段賦值給另外一個字段的方法

示列代碼背景:

數(shù)據(jù)庫名:998pu_test

表名:t_ad_info

需要賦值為自動的列:info_code


關于將表中自增長字段賦值給另外一個字段的方法主要可采用以下三種方式:

1 利用mysql系統(tǒng)表

關鍵SQ如下:

SELECT  Auto_increment            FROM    information_schema.`TABLES`         WHERE    Table_Schema= '998pu_test'        AND table_name = 't_ad_info'

此處關鍵在于SQL用戶具有information_schema庫查詢權限。

示例:

INSERT INTO t_ad_info (

         info_title,

         supply_demand_type,

         store_subclass_id,

         acreage_scope,

         acreage,

         rent,

         rent_unit,

         house_address,

         map_label,

         linkman,

         telphone,

         administrator_password,

         decoration,

         property_right,

         suit_business_scope,

         info_code,

         ad_info_state,

         sys_user_id,

         area_id,

         city_id,

         district_id,

         store_describe

)

VALUES

         (

                   '12',

                   '1',

                   '92',

                   '1',

                   '12',

                   12,

                   '1',

                   '',

                   '',

                   '111111',

                   '18682025165',

                   '',

                   '1',

                   '1',

                   '121111',

                   (

                            SELECT

                                     Auto_increment

                            FROM

                                     information_schema.`TABLES`

                            WHERE

                                     Table_Schema= '998pu_test'

                            ANDtable_name = 't_ad_info'

                   ),

                   0,

                   '16A1E251!ED31052544E84C668CBBE057437284F3',

                   '259',

                   257,

                   278,

                   '22222222222'

         );

2 @@IDENTITY

使用@@IDENTITY變量,在同一個會話中需要分2步

1)  執(zhí)行insert語句

2)  查詢@@IDENTITY

實例代碼:

INSERT INTO t_ad_info (

         info_title,

         supply_demand_type,

         store_subclass_id,

         acreage_scope,

         acreage,

         rent,

         rent_unit,

         house_address,

         map_label,

         linkman,

         telphone,

         administrator_password,

         decoration,

         property_right,

         suit_business_scope,

         info_code,

         ad_info_state,

         sys_user_id,

         area_id,

         city_id,

         district_id,

         store_describe

)

VALUES

         (

                   '12',

                   '1',

                   '92',

                   '1',

                   '12',

                   12,

                   '1',

                   '',

                   '',

                   '111111',

                   '18682025165',

                   '',

                   '1',

                   '1',

                   '121111',

                   (

                            SELECT

                                     Auto_increment

                            FROM

                                     information_schema.`TABLES`

                            WHERE

                                     Table_Schema= '998pu_test'

                            ANDtable_name = 't_ad_info'

                   ),

                   0,

                   '16A1E251!ED31052544E84C668CBBE057437284F3',

                   '259',

                   257,

                   278,

                   '22222222222'

         );


SELECT

         @@IDENTITY;

3 LAST_INSERT_ID()

LAST_INSERT_ID()方法是在同一個會話中連續(xù)插入使用才有意義,在創(chuàng)建會話的第一條插入語句,插入到info_code的值為1,LAST_INSERT_ID()返回的值為0。

示列代碼:

INSERT INTO t_ad_info (

         info_title,

         supply_demand_type,

         store_subclass_id,

         acreage_scope,

         acreage,

         rent,

         rent_unit,

         house_address,

         map_label,

         linkman,

         telphone,

         administrator_password,

         decoration,

         property_right,

         suit_business_scope,

         info_code,

         ad_info_state,

         sys_user_id,

         area_id,

         city_id,

         district_id,

         store_describe

)

VALUES

         (

                   '12',

                   '1',

                   '92',

                   '1',

                   '12',

                   12,

                   '1',

                   '',

                   '',

                   '111111',

                   '18682025165',

                   '',

                   '1',

                   '1',

                   '121111',

                   LAST_INSERT_ID()+1,

                   0,

                   '16A1E251!ED31052544E84C668CBBE057437284F3',

                   '259',

                   257,

                   278,

                   '22222222222'

         );

在本文中,方法2(@@IDENTITY)、3(LAST_INSERT_ID())在同一個會話中具有實際意義。對一條記錄的某一列要賦值為自增長相同的值,則需要分2步操作。


上一篇: IE瀏覽器中文檔模式Quirks Model改為IE標準模式

想了解更多?現(xiàn)在就開始免費體驗

請您留言
深圳市小助手科技有限公司
0755-82494862
小助手科技_姓名圖片
小助手科技_電話圖片
小助手科技_郵箱圖片
類型咨詢類型
小助手科技_類型圖片
0755-8249 4862
QQ交談 QQ交談
友情鏈接:
網(wǎng)站地圖
Copyright 2014-2020 深圳市小助手科技有限公司-版權所有
ICP備案號:粵ICP備15072167號-1