检查约束以确保日期中的日期值是特定值 SQL
正如问题所示,我想知道如何向 DATE 类型值添加检查约束以确保日期仅等于 01。例如,“2021-05-01”是可以接受的,但“2021-05-12”则不可以,因为日期是 12 而不是 01。
As the question suggests, I am wondering how I can add a check constraint to a DATE type value to ensure the day is equal to 01 only. E.g. '2021-05-01' is acceptable but '2021-05-12' is not since day is 12 and not 01.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MySQL 有一个用于此类工作的 DAY() 函数。它从 DATE 或 DATETIME 字段返回日期(1 到 31)。例子 :
MySQL has a DAY() function for this kind of job. It returns the day (1 to 31) from a DATE or DATETIME field. Example :