日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

explicit_defaults_for_timestamp参数的专题报告

發(fā)布時(shí)間:2025/1/21 编程问答 91 豆豆
生活随笔 收集整理的這篇文章主要介紹了 explicit_defaults_for_timestamp参数的专题报告 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
專題描述

解釋explicit_defaults_for_timestamp參數(shù)的含義和explicit_defaults_for_timestamp參數(shù)

值設(shè)定對插入NULL值的影響

問題提出OMS系統(tǒng)測試時(shí)出現(xiàn)插入數(shù)據(jù)報(bào)錯(cuò)的問題:
時(shí)間字段無法寫入值(下單):
b2c1?????????10.202.198.200:3319??oms1/oms1
b2c2?????????10.202.198.201:3319??oms2/oms2
b2c3?????????10.202.198.202:3319??oms3/oms3
b2c4?????????10.202.198.203:3319??oms4/oms4
后續(xù)報(bào)錯(cuò)省略。
分析過程1關(guān)于定義字段為NOT?NULL,插入NULL值不成功的問題與sql_mode參數(shù)的設(shè)置沒有關(guān)系。

在MySQL中設(shè)置參數(shù)explicit_defaults_for_timestamp=off的情況下,

對于timestamp?類型列定義為not?null屬性的情況下,插入null值不報(bào)錯(cuò),

但MySQL會將null值處理為當(dāng)前時(shí)間。


舉例說明:
對于timestamp類型列定義為not?null,沒有default值的情況:

root@localhost?:?test?06:17:02>?show?variables?like?

'explicit_defaults_for_timestamp';

+---------------------------------+-------+
|?Variable_name???????????????????|?Value?|
+---------------------------------+-------+
|?explicit_defaults_for_timestamp?|?OFF????|
+---------------------------------+-------+
1?row?in?set?(0.01?sec)

test?06:21:33>?show?create?table?t;
|?Table?|?Create?Table???????????????????????????????????????????????????????????????????????????????????????????????????
|?t?????|?CREATE?TABLE?`t`?(
??`id`?int(11)?DEFAULT?NULL,
??`t1`?timestamp?NOT?NULL
)?ENGINE=InnoDB?DEFAULT?CHARSET=utf8?|
1?row?in?set?(0.00?sec)

?insert?into?t?values(1,null);
Query?OK,?1?row?affected?(0.03?sec)

root@localhost?:?test?06:22:20>?select?*?from?t;
+------+---------------------+
|?id???|?t1??????????????????|
+------+---------------------+
|????1?|?2015-06-23?18:22:20?|
+------+---------------------+
1?row?in?set?(0.00?sec)
對于定義timestamp類型列?not?null,有default值的情況:

root@localhost?:?test?06:31:16>?show?variables?like?

'explicit_defaults_for_timestamp';

+---------------------------------+-------+
|?Variable_name???????????????????|?Value?|
+---------------------------------+-------+
|?explicit_defaults_for_timestamp?|?OFF???|
+---------------------------------+-------+
1?row?in?set?(0.00?sec)
test?06:31:22>?show?create?table?tt;
|?Table?|?Create?Table??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????|

|?tt????|?CREATE?TABLE?`tt`?(
??`id`?int(11)?DEFAULT?NULL,
??`t1`?timestamp?NOT?NULL?DEFAULT?'0000-00-00?00:00:00'
)?ENGINE=InnoDB?DEFAULT?CHARSET=utf8?|
1?row?in?set?(0.00?sec)

test?06:31:29>?insert?into?tt?values(1,null);
Query?OK,?1?row?affected?(0.00?sec)

root@localhost?:?test?06:31:35>?select?*?from?tt;
+------+---------------------+
|?id???|?t1??????????????????|
+------+---------------------+
|????1?|?2015-06-23?18:31:35?|
+------+---------------------+
1?row?in?set?(0.01?sec)
解決方案

explicit_defaults_for_timestamp=off參數(shù)僅對于timestamp類型的列有效

,其它數(shù)據(jù)類型的列定義為not?null時(shí),

不要插入null值。
問題原因

explicit_defaults_for_timestamp=off參數(shù)僅對于timestamp類型的列有效

,其它類型的列定義為not?null,

是無法插入null值。
知識點(diǎn)

explicit_defaults_for_timestamp?=?off值時(shí)

,向定義為timestamp?NOT?NULL的列值中插入NULL值時(shí)允許的,且插入值為插入語句當(dāng)前時(shí)間。

當(dāng)explicit_defaults_for_timestamp?=?ON值時(shí),

不可向timestamp?NOT?NULL列中插入NULL值。


轉(zhuǎn)載于:https://blog.51cto.com/yixianwei/1902835

總結(jié)

以上是生活随笔為你收集整理的explicit_defaults_for_timestamp参数的专题报告的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。