title: How to check if a view exists and create if it does not
body: <p>I want to create a view if not exists in SQL Server 2016</p>
  
  <pre><code>IF EXISTS(SELECT 1 FROM sys.views 
       WHERE Name = 'VI_ALL_CITIES_AS_CATEGORY')
  BEGIN
  CREATE VIEW VI_ALL_CITIES_AS_CATEGORY AS
      SELECT PERSONS.FIRST_NAME AS 'Име', PERSONS.LAST_NAME AS 'Фамилия', CITIES.CITY_NAME AS 'Град'
      FROM CITIES
      LEFT JOIN PERSONS ON CITIES.ID = PERSONS.CITY_ID ;
  END
  </code></pre>
  
  <p>But it gives me error: </p>
  
  <blockquote>
    <p>Incorrect syntax: 'CREATE VIEW' must be the only statement in the
    batch.</p>
  </blockquote>