久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

MySql 復合鍵和空值

MySql compound keys and null values(MySql 復合鍵和空值)
本文介紹了MySql 復合鍵和空值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我注意到,如果我有兩列的唯一復合鍵,column_a 和 column_b,那么如果一列為空,我的 sql 將忽略此約??束.

I have noticed that if I have a unique compound keys for two columns, column_a and column_b, then my sql ignores this constraint if one column is null.

例如

如果 column_a=1 和 column_b = null 我可以隨意插入 column_a=1 和 column_b=null

if column_a=1 and column_b = null I can insert column_a=1 and column_b=null as much as I like

如果 column_a=1 和 column_b = 2 我只能插入一次這個值.

if column_a=1 and column_b = 2 I can only insert this value once.

除了將列更改為 Not Null 并設置默認值之外,還有其他方法可以應用此約束嗎?

Is there a way to apply this constraint, other than maybe changing the columns to Not Null and setting default values?

推薦答案

http://dev.mysql.com/doc/refman/5.0/en/create-index.html

"UNIQUE 索引創建了一個約束,使得索引中的所有值都必須是不同的.如果您嘗試添加具有與現有行匹配的鍵值的新行,則會發生錯誤.此約束不適用于 NULL 值BDB 存儲引擎除外.對于其他引擎,對于可以包含 NULL 的列,UNIQUE 索引允許多個 NULL 值."

"A UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. This constraint does not apply to NULL values except for the BDB storage engine. For other engines, a UNIQUE index allows multiple NULL values for columns that can contain NULL."

所以,不,您不能讓 MySQL 將 NULL 視為唯一值.我想你有幾個選擇:你可以按照你在問題中的建議并存儲一個特殊值"而不是空值,或者你可以對表使用 BDB 引擎.不過,我不認為這種細微的行為差異值得對存儲引擎做出不同尋常的選擇.

So, no, you can't get MySQL to treat NULL as a unique value. I guess you have a couple of choices: you could do what you suggested in your question and store a "special value" instead of null, or you could use the BDB engine for the table. I don't think this minor difference in behaviour warrants making an unusual choice of storage engine, though.

這篇關于MySql 復合鍵和空值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: av激情在线 | 女人夜夜春 | 日日摸夜夜添夜夜添精品视频 | 99日韩| 国产激情综合五月久久 | 久久伊| 欧美中文字幕一区 | 欧美啊v在线观看 | 天堂av在线影院 | 日韩中文在线视频 | 国产精品夜夜夜一区二区三区尤 | 在线视频一区二区三区 | 国产成人99久久亚洲综合精品 | 国产精品久久久久久久久久久免费看 | 成人小视频在线观看 | 亚洲成人第一页 | 国产一区二区久久久 | 国产精品久久久久久久久久久久 | 欧美日韩电影免费观看 | 免费日本视频 | 久久综合国产精品 | 日韩三级在线 | 国产精品一区视频 | 亚洲国产精品视频一区 | 黄网站免费在线观看 | 精品伦精品一区二区三区视频 | 一区二区三区日韩精品 | 日韩精品久久久久久 | 日韩成人在线播放 | 色婷婷精品国产一区二区三区 | 美女在线观看国产 | 国产精品视频一区二区三区四蜜臂 | 久久婷婷国产香蕉 | 日本福利在线观看 | 91免费版在线 | 日韩久久久一区二区 | 国产成人精品网站 | 日韩精品在线看 | 欧美一区永久视频免费观看 | 成人国产一区二区三区精品麻豆 | 欧美成人黄色小说 |