When you browse data, a SELECT statement operates on one or more tables and produces a result set that is also a table. Just like a base table, a result set from a SELECT query has columns and rows. A view gives a name to a particular query, and holds the definition in the database system tables.
Suppose you frequently need to list the number of employees in each department. You can get this list with the following statement:
SELECT DepartmentID, COUNT(*) FROM Employees GROUP BY DepartmentID;
You can create a view containing the results of this statement using either Sybase Central or Interactive SQL.
When you create a view, the database server stores the view definition in the database; no data is stored for the view. Instead, the view definition is executed only when it is referenced, and only for the duration of time that the view is in use. This means that creating a view does not require storing duplicate data in the database.
Connect to a database.
Open the Views folder for that database.
From the File menu, choose New > View.
The Create View wizard appears.
Follow the instructions in the wizard.
The new view appears in the Views folder.
When the wizard exits, you can edit the view definition in the SQL tab in the right pane. If you do so, you must save the changes. From the File menu, choose Save.
Connect to a database.
Execute a CREATE VIEW statement.
Create a view called DepartmentSize that contains the results of the SELECT statement given earlier in this section:
CREATE VIEW DepartmentSize AS SELECT DepartmentID, COUNT(*) FROM Employees GROUP BY DepartmentID;
For more information, see CREATE VIEW statement.