久久久久久久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?什么時候不能投射為日期?)
主站蜘蛛池模板: 性欧美精品一区二区三区在线播放 | 91欧美| av资源中文在线天堂 | 中文字幕在线第一页 | 毛片免费看 | 美日韩精品 | 色综合欧美 | 午夜在线小视频 | 男女下面一进一出网站 | 一区二区三区在线观看视频 | 国产精品成人一区二区三区 | 欧美日韩在线观看一区 | 日韩精品久久一区二区三区 | 国产高清视频一区二区 | 午夜欧美| 日日噜噜噜夜夜爽爽狠狠视频, | 亚洲第一成人av | 国产精品美女在线观看 | 中文字幕视频免费 | 在线播放中文字幕 | 精品一区二区三区免费视频 | 黄色免费三级 | 日韩三级在线观看 | 亚洲高清在线观看 | 欧美视频第二页 | 污视频在线免费观看 | 亚洲一区二区三区在线 | 97日日碰人人模人人澡分享吧 | 91国内精精品久久久久久婷婷 | 午夜男人的天堂 | 91视频中文 | 中国人pornoxxx麻豆 | 日韩欧美成人精品 | 91在线视频免费观看 | 久久精品一级 | 人人99 | 欧美一极视频 | 高清黄色网址 | 国产日产精品一区二区三区四区 | 羞羞网站在线观看 | 久久精品亚洲一区 |