Drop view if exists
<p>I have script where I want to first drop view and then create it.
I know how to drop table:</p>

<pre><code>IF EXISTS (SELECT * FROM sys.tables WHERE name = 'table1' AND type = 'U') DROP TABLE table1;
</code></pre>

<p>so I did the same for views:</p>

<pre><code>IF EXISTS (SELECT * FROM sys.views WHERE name = 'view1' AND type = 'U') DROP VIEW view1;
create view1 as(......)
</code></pre>

<p>and then I got error:</p>

<blockquote>
  <p>'CREATE VIEW' must be the first statement in a query batch.</p>
</blockquote>