1

下面是我想删除变量中的视图的代码

declare @tbName nvarchar(max)
    set @tbName ='Vw_QueryBuilder_22viewcheckedmergedagain'
    exec('IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(' + @tbName + '))
    DROP VIEW ' + @tbName)

上面的代码说视图不存在,但它存在我能够显示视图的所有记录

4

1 回答 1

1

我找到了答案,我正在分享它缺少引号它可能是任何人都可以发现它有用

declare @tbName nvarchar(max)
    set @tbName =N'Vw_QueryBuilder_22viewcheckedmergedagain'

    exec('IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(''' + @tbName + '''))
    DROP VIEW dbo. ' + @tbName)
于 2013-08-19T12:22:02.087 回答