Sybase Views

Sybase Views is used to get the data from one or more tables. A view is simply named select statement that is stored in a database as an object. It allows you to view a subset of rows or columns in one or more tables.

Why Views:

  • Security: Using a view, we can query and modify only the data we can see. The rest of the database is neither visible nor accessible.
  • Views can shield users from changes in the structure of the real tables if such changes become necessary.
  • Define frequently used joins, projections, and selections as views so that users do not have to specify all the conditions and qualifications each time an operation is performed on that data.
  • Display different data for different users, even when they are using the same data at the same time. This advantage is particularly important when
    users of many different interests and skill levels share the same database.

Views Create Syntax:

create view [owner .]view_name
[(column_name [, column_name ]…)]
as select [distinct] select_statement
[with check option]

Examples:
Create view on table titles where price is greater than 20 dollars and advance is more than 6000 dollars of pubs2 database.

create view highprice
as select * from titles
where price > $16 and advance > $6000

To get information about created view

sp_helpobject view_name

Example:

To rename view

sp_rename objname , newname

Example:

1> sp_rename highprice, highprice1
2> go
Object name has been changed.
Warning: Changing an object or column name could break existing stored procedures, cached statements or other compiled objects.
(return status = 0)

Display view information: We can get create view syntax of existing view by using sp_helptext command.

sp_helptext object_name

Dropping Sybase Views:

drop view [owner.]view_name [, [owner.]view_name]…

Powered by k2schools