SQLite Forum

DROP VIEW IF EXISTS failure
Login
There is a way to separate the drop statements construction from running them. To wit:

```
create table ta (x);
create view v as select x as x from ta;
create index i on ta(x);
create trigger tr instead of insert on v begin insert into ta(x) values(new.x); end;

.load eval

create view if not exists ZapAll as select group_concat(zap,';')
 from ( select 'drop '||sm.type||' '||sm.name as zap from sqlite_master sm
   where sm.type in ('table','view','trigger','index') 
    and sm.name in ('ta','v','i','tr','giblets')
   order by sm.type='table',sm.type='view',sm.type='index',sm.type='trigger'
 );

.parameter set $zaps 'select * from ZapAll'
select eval(eval($zaps));
```

The named objects that are created first are gone after running all of that in the SQLite shell.