Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一张有两列的桌子。如何设置一个仅允许其中一列恰好为空的行的约束?
我当然会在应用层做一些预检查,但我也想直接在数据库层设置这个约束。
谢谢!
尝试 mysql 运算符AND OR 运算符
SELECT * FROM `table1` WHERE (col1 IS NULL AND col2 IS NOT NULL) OR (col2 IS NULL AND col1 IS NOT NULL)