关键字'或'附近的语法不正确

时间:2022-07-26 22:45:49

Why do I get Incorrect syntax near the keyword 'or'?

为什么我在关键字'或'附近得到错误的语法?

create or replace view view_jab
as select * from jabatan
where kojab = 3
with check option constraint viewJab_ck

Msg 156, Level 15, State 1, Line 2 Incorrect syntax near the keyword 'or'.

消息156,级别15,状态1,行2关键字'或'附近的语法不正确。

Msg 102, Level 15, State 1, Line 5 Incorrect syntax near 'with'.

Msg 102,Level 15,State 1,Line 5'with'附近的语法不正确。

1 个解决方案

#1


3  

You can drop the view if it already exists, and then create it afterwards.

您可以删除视图(如果已存在),然后再创建它。

IF OBJECT_ID('view_jab') IS NOT NULL
BEGIN
    DROP VIEW view_jab
END

CREATE VIEW view_jab
AS
SELECT * FROM jabatan
WHERE kojab = 3
WITH CHECK OPTION

Note that I removed the CONSTRAINT from your view, because AFAIK a view cannot have any integrity constraints on it. Please read here and here for more information.

请注意,我从您的视图中删除了CONSTRAINT,因为AFAIK视图不能对其进行任何完整性约束。请阅读此处和此处了解更多信息。

#1


3  

You can drop the view if it already exists, and then create it afterwards.

您可以删除视图(如果已存在),然后再创建它。

IF OBJECT_ID('view_jab') IS NOT NULL
BEGIN
    DROP VIEW view_jab
END

CREATE VIEW view_jab
AS
SELECT * FROM jabatan
WHERE kojab = 3
WITH CHECK OPTION

Note that I removed the CONSTRAINT from your view, because AFAIK a view cannot have any integrity constraints on it. Please read here and here for more information.

请注意,我从您的视图中删除了CONSTRAINT,因为AFAIK视图不能对其进行任何完整性约束。请阅读此处和此处了解更多信息。