Mastering in SQLite

Views

Kishore Premkumar
IVYMobility TechBytes
2 min readApr 24, 2020

--

Before getting into SQLite- View, if you haven’t covered the previous topic- SQLite Function, then get into it.

To visit the introduction page to see all the available topics click here.

A number of superheroes are available in our DB, click here to download it.

What is view

  • In SQL, a view is a virtual table based on the result-set of an SQL statement.
  • A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.
  • The SQLite views like read-only tables that means it won’t allow to perform any operations like INSERT , UPDATE and DELETE on views.

Create View

CREATE VIEW statement is used to create view table.

Syntax

CREATE VIEW viewName AS
SELECT
statement1,
statement2
...
statementN
FROM
tableName
WHERE[CONDITION] // WHERE condition is optional

Example

CREATE VIEW marvelStudio AS
SELECT
*
FROM
characterList
WHERE
studio = "marvel"

Output

In the above program, We are creating a view table with WHERE condition. If you don’t need it, then you can skip it.

Drop view

To remove a view from a database, use the DROP VIEW statement.

Syntax

DROP VIEW viewTableName

Example

DROP VIEW marvelStudio

Output

table has been deleted.

To reach out the next topic- Index and Expression- based Index

--

--