<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Sample Code: A Procedure To Drop Views in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaa-p/13818631#M4849474</link>
    <description>&lt;P&gt;Adding the owner name as a 2nd param (with default "DBA"?) would be nice. E.g. our schemata are usually owned by "dbo" - primarily for historical purposes like compatibility with MS SQL.&lt;/P&gt;</description>
    <pubDate>Wed, 24 Feb 2010 08:24:50 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2010-02-24T08:24:50Z</dc:date>
    <item>
      <title>Sample Code: A Procedure To Drop Views</title>
      <link>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaq-p/13818629</link>
      <description>&lt;P&gt;If this sample was helpful to you, vote it up.&lt;/P&gt;

&lt;P&gt;If you have an improved version, or a closely related sample, post it as an answer.&lt;/P&gt;

&lt;P&gt;If you have a question or complaint, post it as a comment (or an answer, if you have a lot to say &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;    &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;STRONG&gt;Description:&lt;/STRONG&gt;&lt;BR /&gt;
Know the view you want to drop, but don't know how to check for existence?  Want to drop all views in the system, but have no automated way of doing it?  Specify the view name as the parameter to drop only that view (IF it exists).  Leave it empty to drop'em all. &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;STRONG&gt;Usage:&lt;/STRONG&gt;&lt;BR /&gt;
To drop a single view by name:  &lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;call sp_Drop_View('vw_People_Info');
&lt;/LI-CODE&gt;

&lt;P&gt;To drop all views in a database:&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;call sp_Drop_View();
&lt;/LI-CODE&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;STRONG&gt;Code:&lt;/STRONG&gt;  &lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;create procedure sp_Drop_View (IN @viewName varchar(128) DEFAULT 'NONE')
begin           
    IF @viewName = 'NONE' THEN
        FOR VIEW_NAME_FOR as VIEW_NAME_CURSOR dynamic scroll cursor for
                select st.table_name as VIEW_NAME
                  from systab st
                 where st.creator = 1 AND
                       st.table_type = 'VIEW'
              order by st.table_name asc do
            execute immediate 'DROP VIEW ' || VIEW_NAME;
        END FOR;
    ELSE
        if exists(select 1 from sys.systable where table_name=@viewName and table_type='VIEW') then
            EXECUTE IMMEDIATE 'DROP VIEW ' || @viewName;
        end if;
    END IF;
end;
&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 23 Feb 2010 22:02:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaq-p/13818629</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-02-23T22:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sample Code: A Procedure To Drop Views</title>
      <link>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaa-p/13818630#M4849473</link>
      <description>&lt;P&gt;I have used a similar proc in the past, but fortunately SA 11.0.1 introduced the following handy &lt;A href="http://dcx.sybase.com/1101en/dbreference_en11/drop-view-statement.html" rel="nofollow"&gt;syntax&lt;/A&gt;:&lt;/P&gt;

&lt;LI-CODE lang="sql"&gt;DROP VIEW IF EXISTS [owner].viewname
&lt;/LI-CODE&gt;

&lt;P&gt;(As it does for other database objects like triggers etc.)&lt;/P&gt;

&lt;P&gt;But of course it does not allow to drop all views:)&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2010 08:22:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaa-p/13818630#M4849473</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-02-24T08:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sample Code: A Procedure To Drop Views</title>
      <link>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaa-p/13818631#M4849474</link>
      <description>&lt;P&gt;Adding the owner name as a 2nd param (with default "DBA"?) would be nice. E.g. our schemata are usually owned by "dbo" - primarily for historical purposes like compatibility with MS SQL.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2010 08:24:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaa-p/13818631#M4849474</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2010-02-24T08:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sample Code: A Procedure To Drop Views</title>
      <link>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaa-p/13818632#M4849475</link>
      <description>&lt;P&gt;That's fantastic!  I wish we were on 11, but we only just went to 10 last year.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2010 22:05:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/sample-code-a-procedure-to-drop-views/qaa-p/13818632#M4849475</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-02-24T22:05:23Z</dc:date>
    </item>
  </channel>
</rss>

