How can I check if a View exists in a Database?

前端 未结 10 1673
无人共我
无人共我 2021-01-31 07:00

I have some SQL code that needs to be executed if a certain View exists in a database. How would I go about checking if the View exists?

EDIT: The DBMS being used is Mic

10条回答
  •  一生所求
    2021-01-31 07:34

    IN SQL Server ,

    declare @ViewName nvarchar(20)='ViewNameExample'
    
    if exists(SELECT 1 from sys.objects where object_Id=object_Id(@ViewName) and Type_Desc='VIEW')
    begin
        -- Your SQL Code goes here ...
    
    end
    

提交回复
热议问题