gpt4 book ai didi

sql-server - SQL 服务器 : create view if not exists don't work

转载 作者:行者123 更新时间:2023-12-02 00:51:18 26 4
gpt4 key购买 nike

如果 View 不存在,我正在尝试使用:

IF OBJECT_ID('dbo.zestaw_zam_fak') IS NULL 
CREATE VIEW AS
SELECT ....
FROM ....
UNION
SELECT .....
FROM....
UNION
SELECT ...
FROM ...

但是我得到一个错误:

Unable to parse query text
Incorrect syntax near the keyword VIEW.

没有语句 'IF OBJECT_ID('dbo.zestaw_zam_fak') IS NULL, View 创建正确。

我做错了什么?

最佳答案

您必须将 CREATE 语句包装到 EXEC('your create statement') 中。否则它不会在 IF

中工作

示例:

IF OBJECT_ID('dbo.vwCity') IS NULL
BEGIN
EXECUTE('CREATE VIEW [dbo].[vwCity]
AS
SELECT *
FROM dbo.City')
END

关于sql-server - SQL 服务器 : create view if not exists don't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39608288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com