tencent cloud

TDSQL Boundless

Release Notes
Product Introduction
Overview
Scenarios
Product Architecture
Instance Types
Compatibility Notes
Kernel Features
Kernel Overview
Kernel Version Release Notes
Functionality Features
Performance Features
Billing
Billing Overview
Purchase Method
Pricing Details
Renewal
Overdue Payments
Refund
Getting Started
Creating an Instance
Connect to Instances
User Guide
Data Migration
Data Subscription
Instance Management
Configuration Change
Parameter Configuration
Account Management
Security Group
Backup and Restoration
Database Auditing
Tag Management
Use Cases
Technical Evolution and Usage Practices of Online DDL
Lock Mechanism Analysis and Troubleshooting Practices
Data Intelligent Scheduling and Related Practices for Performance Optimization
TDSQL Boundless Selection Guide and Practical Tutorial
Developer Guide
Developer Guide (MySQL Compatibility Mode)
Developer Guide (HBase Compatibility Mode)
Performance Tuning
Performance Tuning Overview
SQL Tuning
DDL Tuning
Performance White Paper
Performance Overview
TPC-C Test
Sysbench Test
API Documentation
History
Introduction
API Category
Making API Requests
Instance APIs
Security Group APIs
Task APIs
Backup APIs
Rollback APIs
Parameter APIs
Database APIs
Data Types
Error Codes
General Reference
System Architecture
SQL Reference
Database Parameter Description
TPC-H benchmark data model reference
Error Code Information
Security and Compliance
FAQs
Agreements
Service Level Agreement
Terms of Service
Privacy Policy
Data Processing And Security Agreement
Contact Us
Glossary

Views

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-03-26 14:57:05
You can use EXPLAIN to view the execution plan of a query. TDSQL Boundless, like MySQL, supports three formats for displaying execution plans: TRADITIONAL, TREE, and JSON.
The main purpose of views:
Simplifying complex queries: Encapsulate complex queries such as multi-table joins and aggregations into virtual tables, allowing subsequent usage to be as concise as querying regular tables.
Data Security: Expose only specific fields to users while hiding underlying sensitive data.
Logic Reuse: Define commonly used query logic as views to avoid rewriting the same SQL statements at multiple locations.

Creating a View

Use the CREATE VIEW statement to create a view.
Create a customer order summary view including the number of orders and total amount for each customer:
CREATE VIEW customer_order_summary AS
SELECT
c.c_custkey,
c.c_name,
c.c_mktsegment,
COUNT(o.o_orderkey) AS order_count,
COALESCE(SUM(o.o_totalprice), 0) AS total_spent
FROM customer c
LEFT JOIN orders o ON c.c_custkey = o.o_custkey
GROUP BY c.c_custkey, c.c_name, c.c_mktsegment;
Create a regional suppliers view displaying supplier information for each region:
CREATE VIEW regional_suppliers AS
SELECT
r.r_name AS region_name,
n.n_name AS nation_name,
s.s_suppkey,
s.s_name AS supplier_name,
s.s_phone
FROM region r
INNER JOIN nation n ON r.r_regionkey = n.n_regionkey
INNER JOIN supplier s ON n.n_nationkey = s.s_nationkey;
Note:
When a view is created, the view name must not duplicate existing table or view names.

Query view

After the view is created, you can query it using the SELECT statement just like querying regular tables.
Query the top 10 customers with the most orders:
SELECT c_name, c_mktsegment, order_count, total_spent
FROM customer_order_summary
ORDER BY order_count DESC
LIMIT 10;
Applying filter conditions on views:
SELECT c_name, order_count, total_spent
FROM customer_order_summary
WHERE c_mktsegment = 'BUILDING'
AND order_count > 10
ORDER BY total_spent DESC;
Joining views with other tables:
SELECT
rs.region_name,
rs.supplier_name,
ps.ps_partkey,
ps.ps_supplycost
FROM regional_suppliers rs
INNER JOIN partsupp ps ON rs.s_suppkey = ps.ps_suppkey
WHERE rs.region_name = 'ASIA'
ORDER BY ps.ps_supplycost
LIMIT 20;
When a view is queried, TDSQL Boundless internally expands the view into the original SQL statement defined during its creation. For example, when customer_order_summary is queried, the system actually executes its underlying SELECT ... FROM customer LEFT JOIN orders ... statement combined with the outer filter and sorting conditions.

Update the view

When a view definition is modified, you can use the CREATE OR REPLACE VIEW statement efficiently without needing to delete and recreate it.
Add an average order amount field to the customer order summary view:
CREATE OR REPLACE VIEW customer_order_summary AS
SELECT
c.c_custkey,
c.c_name,
c.c_mktsegment,
COUNT(o.o_orderkey) AS order_count,
COALESCE(SUM(o.o_totalprice), 0) AS total_spent,
COALESCE(AVG(o.o_totalprice), 0) AS avg_order_amount
FROM customer c
LEFT JOIN orders o ON c.c_custkey = o.o_custkey
GROUP BY c.c_custkey, c.c_name, c.c_mktsegment;
Views can also be updated by deleting and recreating them:
DROP VIEW IF EXISTS customer_order_summary;
CREATE VIEW customer_order_summary AS
SELECT ...;

Obtain view-related information

Use SHOW CREATE VIEW

View the complete CREATE VIEW statement:
SHOW CREATE VIEW customer_order_summary\\G

Query INFORMATION_SCHEMA

View metadata information via the system table information_schema.views:
SELECT
TABLE_NAME,
VIEW_DEFINITION,
CHECK_OPTION,
IS_UPDATABLE
FROM information_schema.views
WHERE TABLE_SCHEMA = 'your_database_name'
AND TABLE_NAME = 'customer_order_summary'\\G

Deleting a View

To delete a view, use the DROP VIEW statement. It is recommended to include IF EXISTS to prevent errors when the view does not exist.
DROP VIEW IF EXISTS customer_order_summary;
Delete multiple views in one operation:
DROP VIEW IF EXISTS customer_order_summary, regional_suppliers;

Limitation

When using views in TDSQL Boundless, note the following limitations:
Materialized views are not supported—only standard views without precomputed results.
Read-only views—UPDATE/INSERT/DELETE/TRUNCATE write operations are not supported.
DDL limitations—only DROP VIEW/TABLE is supported; ALTER VIEW is not supported.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백