VIEW

SQL VIEW Keyword

In SQL, a view is a virtual table based on the result set of an SQL statement. A view does not store data itself — it dynamically pulls data from the underlying table(s).

Tutorials dojo strip

SQL CREATE VIEW Syntax

CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

SQL CREATE VIEW Example

This query creates a view named FemalePatients that returns a list of female patients from the Patients table.

CREATE VIEW FemalePatients AS
SELECT patient_id, first_name, last_name
FROM Patients
WHERE gender = 'F';

SQL Query The View Example

This query selects all records from the FemalePatients view.

SELECT *
FROM FemalePatients;

SQL CREATE OR REPLACE VIEW Syntax

CREATE OR REPLACE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;

SQL CREATE OR REPLACE VIEW Example

This query updates the FemalePatients view to include the gender column.

CREATE OR REPLACE VIEW FemalePatients AS
SELECT patient_id, first_name, last_name, gender
FROM Patients
WHERE gender = 'F';

Note: This code does not work in TechKubo playground. SQLite does not support CREATE OR REPLACE VIEW. You must use DROP VIEW first and then CREATE VIEW again to simulate replacing a view.

SQL DROP VIEW Syntax

DROP VIEW view_name;

SQL DROP VIEW Example

This query deletes the FemalePatients view from the database.

DROP VIEW FemalePatients;

SQL VIEW Labs

Tutorials dojo strip
Scroll to Top