The Data Management Center

SQL CREATE VIEW


Google
 
Web infogoal.com
HOME | SQL OVERVIEW | SQL BASICS | SQL ADMINISTRATION | SQL ADVANCED | SQL SYNTAX


SQL Book Picks

SQL Cookbook
SQL Cookbook by Anthony Molinaro


SQL Visual Quick Start
SQL: Visual QuickStart Guide (2nd Edition) by Chris Fehily

SQL Bible
SQL Bible by Alex Kriegel, Boris M. Trukhnov

SQL Complete Reference
SQL: The Complete Reference, Second Edition by James R Groff, Paul N. Weinberg

SQL for Smarties
Joe Celko's SQL for Smarties: Advanced SQL Programming Third Edition by Joe Celko

Murach SQL Server
Murach's SQL for SQL Server by Bryan Syverson

Previous | Next

SQL > SQL Administration > SQL CREATE VIEW Statement


What is the SQL CREATE VIEW Statement?

A SQL view is a virtual table and the SQL CRERATE VIEW statement is the SQL command that adds a new view to a SQL database.

A view can be accessed using the SQL SELECT statement like a table. A view is built by selecting data from one or more tables.

Some views can also support the SQL INSERT, SQL UPDATE and SQL DELETE statements. In that case, the view must refer to a single table and include all NOT NULL columns of that table.

Why Use the SQL CREATE VIEW Statement?

SQL views are used because they can provide the following benefits / functions:

  • Database queries are simplified
  • Database complexity is hidden
  • Flexibility is increased - queries of views may not change when underlying tables chagne
  • Security is increased - sensitive information can be excluded from a view

How To Use the SQL CREATE VIEW Statement

The SQL CREATE VIEW command is used as follows.

SQL CREATE VIEW Statement Syntax

 
CREATE VIEW <view_name> (
<column_name1>,
<column_name2>
) AS
<sql_select_statement>
 

The number of characters that can make up SQL names for tables, columns and views varies by DBMS. In many cases the limit is 30 characters. The leading character of the name must be alphabetic - not a number or special character. The name of a new view can not duplicate the name of an existing view or table and should not be the same as a SQL reserved word. The underscore character can be used to improve readability. List elements are seperated by commas.

SQL CREATE VIEW Statement Example - Data Filtering

The following example creates a view named V_TOP_CUSTOMER on table CUSTOMER with the following columns:

  • customer_id
  • customer_name
  • ytd_sales_amt
  • zip_code

Here are the contents of the table:

Column NameDatatype Nullability
customer_id INT NOT NULL
customer_name VARCHAR(20) NOT NULL
ytd_sales_amt MONEY NOT NULL
line_1_addr VARCHAR(50) NULL
city_name VARCHAR(50) NOT NULL
state_code CHAR(2) NOT NULL
zip_code CHAR(9) NOT NULL

This SQL CREATE VIEW Statement is executed:

 
CREATE VIEW V_TOP_CUSTOMER (
customer_id,
customer_name,
ytd_sales_amt,
zip_code)
AS SELECT customer_id,
customer_name,
ytd_sales_amt,
zip_code
FROM CUSTOMER
WHERE ytd_sales_amt > 1200.00
 

infogoal.com HOME
SQL OVERVIEW

SQL BASICS
SQL SELECT
SQL WHERE
SQL INSERT
SQL UPDATE
SQL DELETE

SQL ADMINISTRATION
SQL CREATE DATABASE
SQL DROP DATABASE
SQL CREATE TABLE
SQL ALTER TABLE
SQL DROP TABLE
SQL CREATE INDEX
SQL DROP INDEX
SQL ADD FOREIGN KEY
SQL DROP FOREIGN KEY
SQL CREATE VIEW
SQL DROP VIEW

SQL ADVANCED
SQL CONCAT
SQL SUBSTRING
SQL TRIM
SQL AND & OR
SQL IN
SQL BETWEEN
SQL LIKE
SQL DISTINCT
SQL GROUP BY
SQL AGGREGATE
SQL HAVING
SQL ORDER BY
SQL JOIN
SQL OUTER JOIN

SQL SYNTAX

Data Model Resource Book Vol 1
Data Model Resource Book Vol 2
HOME | SQL OVERVIEW | SQL BASICS | SQL ADMINISTRATION | SQL ADVANCED | SQL SYNTAX
Copyright© 1999-2006, First Place Software, Inc.