Creating views  Using the select statement with create view

Chapter 11: Views: Limiting Access to Data

create view syntax

The full syntax for create view is in the Reference Manual.

As illustrated in the create view example in “View examples”, you need not specify any column names in the create clause of a view definition statement. Adaptive Server gives the columns of the view the same names and datatypes as the columns referred to in the select list of the select statement. The select list can be designated by the asterisk (*), as in the example, or it can be a full or partial list of the column names in the base tables.

To build views that do not contain duplicate rows, use the distinct keyword of the select statement to ensure that each row in the view is unique. However, you cannot update distinct views.

You can always specify column names. However, if any of the following are true, you must specify column names in the create clause for every column in the view:

Here is a view definition statement that makes the name of a column in the view different from its name in the underlying table:

create view pub_view1 (Publisher, City, State) 
as select pub_name, city, state 
from publishers 

Here is an alternate method of creating the same view but renaming the columns in the select statement:

create view pub_view2 
as select Publisher = pub_name, 
City = city, State = state 
from publishers 

The examples of view definition statements in the next section illustrate the rest of the rules for including column names in the create clause.

NoteYou cannot use local variables in view definitions.





Copyright © 2005. Sybase Inc. All rights reserved. Using the select statement with create view

View this book as PDF