No, the view should be temporary, otherwise an error will occur:
sqlite> create view view1 as select * from db2.foo union select * from main.foo;
Error: view view1 cannot reference objects in database db2
sqlite> create temp view view1 as select * from db2.foo union select * from main.foo;
sqlite> select * from view1;
...
This makes sense because the temporary view is part of an automatically created database tempthat exists only for the current process.
EDIT:
You can list temporary tables and views (all stored in an automatically created database temp) as follows:
sqlite> .headers on
sqlite> select * from sqlite_temp_master;
type|name|tbl_name|rootpage|sql
view|view1|view1|0|CREATE VIEW view1 as select * from db2.foo union select * from main.foo
To view only listings:
select * from sqlite_temp_master where type='view';
user610650
source
share