TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst · 76.7K subscribers
Post #2802 566
This avoids having slightly different definitions of "High Value Customer" across reports.

7️⃣ View vs Table

This is an important distinction.

Table

A table physically stores data.

Customers Table → Data is stored

View

A normal View stores the query definition rather than a separate copy of the underlying data.

Customers Table → View → Query result

So if the underlying data changes, querying the View generally reflects the current underlying data.

8️⃣ View vs Temporary Table

These are also different.

View

Usually created for reusable logic:

CREATE VIEW customer_summary AS
SELECT ...


It can be used by multiple queries and users, subject to permissions.

Temporary Table

Used to store intermediate results temporarily.

For example:

CREATE TEMPORARY TABLE temp_customer_data AS
SELECT *
FROM customers
WHERE status = 'Active';


The exact temporary-table syntax varies by database.

Simple distinction:

VIEW → Reusable saved query

TEMP TABLE → Temporary stored result

9️⃣ Can You Update Data Through a View?

Sometimes.

Certain simple Views may be updatable.

For example:

CREATE VIEW active_customers AS
SELECT
customer_id,
customer_name,
status
FROM customers
WHERE status = 'Active';


Depending on the database and View definition, an operation such as:

UPDATE active_customers
SET customer_name = 'New Name'
WHERE customer_id = 101;


may update the underlying table.

However, Views containing things such as:

• Aggregations

• GROUP BY

• DISTINCT

• Set operators

• Certain JOINs

• Window functions

may not be directly updatable, depending on the database.

Therefore, don't assume every View can be modified.

🔟 CREATE OR REPLACE VIEW

If your database supports it, you can modify a View definition using:

CREATE OR REPLACE VIEW active_customers AS
SELECT
customer_id,
customer_name,
country,
status
FROM customers
WHERE status = 'Active';


This allows you to change the query behind the View without creating a completely new View.

The exact syntax varies between database systems.

1️⃣1️⃣ Dropping a View

If you no longer need a View:

DROP VIEW active_customers;


This removes the View definition.

It does not normally mean that the underlying table data is deleted.

For example:

DROP VIEW customer_orders;


doesn't mean:

DELETE FROM customers;
DELETE FROM orders;


The underlying tables remain.

1️⃣2️⃣ Views for Data Security

Views can also help control which columns users can access.

Suppose your employee table contains:

employee_id

employee_name

department

salary

bank_account

You may not want every analyst to access sensitive columns.

You could create:

CREATE VIEW employee_directory AS
SELECT
employee_id,
employee_name,
department
FROM employees;


Users can query:

SELECT *
FROM employee_directory;


without directly accessing columns that aren't included in the View.

Important: a View is not automatically a complete security solution. Proper database permissions are still required.

1️⃣3️⃣ Views for Business Logic

Suppose the business defines:

High Value Customer = Customer with sales >= 100,000

You can encode this definition in a View:

CREATE VIEW customer_classification AS
SELECT
customer_id,
customer_name,
total_sales,
CASE
WHEN total_sales >= 100000
THEN 'High Value'
ELSE 'Standard'
END AS customer_type
FROM customers;


Now different reports can use:
More from @sqlanalyst
  1. Oct 7, 2026SQL Interview Series — Part 4 📌 Question 4: Find the Highest Salary in Each Department Su…
  2. Oct 7, 2026𝗠𝗮𝘀𝘁𝗲𝗿 𝗣𝗼𝘄𝗲𝗿 𝗕𝗜 𝗳𝗼𝗿 𝗙𝗥𝗘𝗘! 🔥 Learn Power BI through these FREE learnin…
  3. Sep 29, 2026SQL Interview Series — Part 2 📌 Question 2: Find Duplicate Records Suppose you have an Em…
  4. Sep 29, 2026𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗟𝗲𝗮𝗿𝗻 𝗔𝗜 𝗶𝗻 𝟮𝟬𝟮𝟲🚀 ​ Explore 6 free resource…
  5. Sep 29, 2026SQL Interview Series — Part 1 Hi guys, let's start a SQL interview series covering frequen…
  6. Sep 28, 2026🧠 Real-World SQL Scenario-Based Questions & Answers 1. Get the 2nd highest salary from th…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →