Skip to content
Quantoros

What is a view?

SQLLevel: FoundationFundamentals (Easy)

What is a view?

Hints
  • Define one output row and the source-table keys.
  • Check duplicates, NULLs and the order of filtering and aggregation.

Answer

Обычное представление хранит определение запроса, а не отдельную копию его результата. Оно позволяет дать имя повторяемому запросу и ограничить набор доступных столбцов. Запрашивать можно только столбцы, включённые в определение представления. Например:

CREATE VIEW active_customers AS
SELECT customer_id, name, country
FROM customers
WHERE active = true;

SELECT customer_id, name
FROM active_customers
WHERE country = 'US';

Материализованное представление, в отличие от обычного, хранит результат физически и требует обновления.

Source and licence: SQL Interview Questions — Arda Kocadoru · MIT · answer: Quantoros editorial

Related questions