SQL & Databases·Practice drills 4

Drill 6: Change a value — Views and materialized views

Describe what would change if you edited one value.

Beginner 5 min read Lesson 100 of 480 Challenge included
What you will be able to do
  • Describe what would change if you edited one value.

Practice task

Describe what would change if you edited one value.

views.sqlSQL
CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  price NUMERIC(10, 2) NOT NULL,
  stock INTEGER NOT NULL DEFAULT 0
);

CREATE VIEW low_stock AS
SELECT id, name, stock
FROM products
WHERE stock < 5;

CREATE MATERIALIZED VIEW product_count_by_name AS
SELECT name, COUNT(*) AS copies
FROM products
GROUP BY name;

REFRESH MATERIALIZED VIEW product_count_by_name;
Your turn

Write your answer

Easy

Describe what would change if you edited one value.

TEXT · starter
Your answer…
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 100 of 480 · 0% of course