SQL DDL 地址必须包含
如何为地址编写约束,使其包含街道地址和号码?无需处理包含公寓号码或楼层的地址。谢谢。
How do i write a contraint for an address so it contains both a street address and a number? No need to handle addresses that contain apartment number or floor level. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哪里可以使用带有 RLIKE 的 CHECK 约束和正则表达式。
这里我们只是简单的说,必须是一个数字后跟一个或多个单词,允许使用连字符和下划线。
注意 mySQL 仅在较新的版本中强制执行此操作。检查您的版本中的此试用脚本,看看它是否有效。如果不强制执行,唯一的解决方案是触发ON INSERT
db<>fiddle 此处
Where can use a CHECK constraint with RLIKE and a regular expression.
Here we have simply said that there must be a number followed by one or more words with hyphens and underscores allowed.
NB mySQL only enforces this in more recent version. Check this trial script in your version to see whether it works. If it is not enforced the only solution is a trigger ON INSERT
db<>fiddle here
您可以在 CHECK 约束中使用正则表达式:
或者任何对您的列有意义的内容
You can use regex in a CHECK constraint:
Or whatever makes sense for your column