Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list all the available views of a particular table in SQLite?

I want to access all the particular views of any particular table in Sqlite . I know I can get the list of all the available tables in the database using sqlite_master

SELECT name from sqlite_master WHERE type='table'; 

And the list of all the available views using

SELECT name from sqlite_master WHERE type ='view';

But I want to find all the available views for a particular table . How do I do that ?

like image 222
rush00121 Avatar asked Oct 19 '09 22:10

rush00121


People also ask

How do I view the contents of a table in SQLite?

If you are running the sqlite3 command-line access program you can type ". tables" to get a list of all tables. Or you can type ". schema" to see the complete database schema including all tables and indices.

How do you find all the tables used in a view?

To find all of the SQL Server database views where a table is used, just apply a filter criteria on table_name column of the information schema view INFORMATION_SCHEMA. VIEW_TABLE_USAGE as seen below.

Does SQLite have views?

Views are read-only in SQLite. However, in many cases you can use an INSTEAD OF trigger on the view to accomplish the same thing. Views are removed with the DROP VIEW command. If a column-name list follows the view-name, then that list determines the names of the columns for the view.


1 Answers

No need to use extension-functions.c; just use the "LIKE" operator:

SELECT name FROM sqlite_master WHERE type = 'view' and sql LIKE "%_tablename_%";

You will get false matches, of course, if you have table names that contain other table names as substrings, or that are substrings of common SQL reserved words (like "here" or "rom"). You can eliminate the latter by the following:

SELECT name FROM sqlite_master WHERE type = 'view' AND sql LIKE "% FROM %tablename% WHERE %";

providing the views you're trying to find conform to the typical model.

like image 149
Gary H Avatar answered Oct 24 '22 11:10

Gary H