使用 IF 和 ERROR 创建视图
CREATE VIEW with IF and ERROR
CREATE VIEW nextClass AS
SELECT date,id
FROM class
WHERE date >= CURDATE()
AND IF (
date < CURDATE(),
ERROR_MESSAGE('You cannot update previous classs'),
CLOSE()
)
有人可以帮助 SQL 中的 CREATE VIEW 语句吗?
我需要显示所有未来的 类 并拒绝更新之前的 类 的尝试。
我在这段代码中有一个语法错误。
请参考mysql关于creating views的文档:
The WITH CHECK OPTION clause can be given for an updatable view to
prevent inserts or updates to rows except those for which the WHERE
clause in the select_statement is true.
因此,您需要做的就是将 WITH CHECK OPTION
添加到 CREATE VIEW
语句的末尾。
CREATE VIEW nextClass AS
SELECT date,id
FROM class
WHERE date >= CURDATE()
AND IF (
date < CURDATE(),
ERROR_MESSAGE('You cannot update previous classs'),
CLOSE()
)
有人可以帮助 SQL 中的 CREATE VIEW 语句吗? 我需要显示所有未来的 类 并拒绝更新之前的 类 的尝试。 我在这段代码中有一个语法错误。
请参考mysql关于creating views的文档:
The WITH CHECK OPTION clause can be given for an updatable view to prevent inserts or updates to rows except those for which the WHERE clause in the select_statement is true.
因此,您需要做的就是将 WITH CHECK OPTION
添加到 CREATE VIEW
语句的末尾。