{"id":3995,"date":"2025-06-07T09:22:37","date_gmt":"2025-06-07T09:22:37","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3995"},"modified":"2025-06-07T09:22:38","modified_gmt":"2025-06-07T09:22:38","slug":"sql-view","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/sql\/sql-view\/","title":{"rendered":"SQL VIEW"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A <strong>VIEW<\/strong> is a virtual table based on the result of a SQL query. It doesn\u2019t store data itself, but shows data dynamically from underlying tables \u2014 great for simplifying complex queries or restricting access.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd39 <strong>Basic Syntax<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Create a view\nCREATE VIEW active_employees AS\nSELECT id, name, department\nFROM employees\nWHERE status = 'active';\n\n-- Query the view like a table\nSELECT * FROM active_employees;\n\n-- Update a view (if supported)\nCREATE OR REPLACE VIEW active_employees AS\nSELECT id, name, department, hire_date\nFROM employees\nWHERE status = 'active';<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd39 <strong>Dropping a View<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>-- Drop the view\nDROP VIEW active_employees;<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udd39 <strong>Key Uses<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Simplify complex queries<\/li>\n\n\n\n<li>Abstract logic for reusability<\/li>\n\n\n\n<li>Restrict access to specific data<\/li>\n\n\n\n<li>Enhance readability in reporting<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\ud83d\uded1 <strong>Note:<\/strong> Not all views are <strong>updatable<\/strong>. A view can only be updated if it\u2019s based on a single table without group functions, DISTINCT, or joins.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83e\udde0 <strong>Quick Recap<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Key Point<\/th><th>Explanation<\/th><\/tr><\/thead><tbody><tr><td>Definition<\/td><td>Virtual table based on a SELECT query<\/td><\/tr><tr><td>Syntax<\/td><td><code>CREATE VIEW view_name AS SELECT...<\/code><\/td><\/tr><tr><td>Usage<\/td><td>Used like a table in queries<\/td><\/tr><tr><td>Benefits<\/td><td>Simplifies access, improves security<\/td><\/tr><tr><td>Limitation<\/td><td>Not always updatable<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\ud83d\udca1 Use views to expose only what\u2019s needed \u2014 perfect for clean, safe, reusable querying.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A VIEW is a virtual table based on the result of a SQL query. It doesn\u2019t store data itself, but shows data dynamically from underlying tables \u2014 great for simplifying complex queries or restricting access. \ud83d\udd39 Basic Syntax \ud83d\udd39 Dropping a View \ud83d\udd39 Key Uses \ud83d\uded1 Note: Not all views are updatable. A view can [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,979],"class_list":["post-3995","cposts","type-cposts","status-publish","hentry","category-notes","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/3995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}