Site sponsored by: Idera Try Idera’s new SQL admin toolset
SQL Server Performance

  • Home
  • Articles
  • Forums
  • Tips
  • Quiz
  • FAQ's
  • Blogs
  • Software
  • Books
  • About Us
RSS Feeds
Sign in | Join


Article Topics

All Articles
Performance Tuning
Audit
Business Intelligence
Clustering
Reporting Services
Developer
General DBA
ASP.NET / ADO.NET

Write for Us

Share you SQL Server knowledge with others and raise your profile in the community More...
Latest Articles

Capture DDL Changes using Change Data Capture with SQL Server 2008 ...
Business Intelligence in Collaborative Planning, Forecasting and Replenishment
Inside SQL Server Cluster Setup and Troubleshooting Techniques - Part I ...
Configure and Manage Policy Based Management in SQL Server 2008 ...

More     
 
Latest FAQ's

Cannot Start SQL Server Service
Users are able to connect to report manager but not able ...
Errors when SQL Server Snapshot Replication is Running
How to Display Server Name or IP Address in a Reporting ...

More     
   
Latest Software Reviews

Spotlight on ApexSQL Doc 2008
ApexSQL Enforce
Embarcadero Change Manager
SQL Server DBA Dashboard

More     

articles >> developer >> Views in SQL Server

Views in SQL Server

By : Steve Manik
May 17, 2004

Page 2 / 3



Getting Information on a View

SQL Server stores information on the view in the following system tables:

  • SYSOBJECTS — stores the name of the view.
  • SYSCOLUMNS — stores the names of the columns defined in the view.
  • SYSDEPENDS — stores information on the view dependencies.
  • SYSCOMMENTS — stores the text of the view definition.

There are also certain system-stored procedures that help retrieve information on views. The sp_help system-stored procedure displays view-related information. It displays the view definition, provided the name of the view is given as its parameter.

Example

Sp_helptext vwCustomer

Displays the definition of the vwCustomer view.

Note

If a view is created with the WITH ENCRYPTION option, it cannot view the sp_helptext system-stored procedure.



Altering Views

You can modify a view without dropping it. This ensures that the permission on the view is also not lost. You can modify a view without affecting its dependent objects, such as triggers and stored procedures.

You modify a view using the ALTER VIEW statement.

Syntax

ALTER VIEW view _name [column_ name)]
[WITH ENCRYPTION]
AS select_statement
[WITH CHECK OPTION]

Where:

view_name is the view to be altered.

column_name specifies the name of the column to be used in the view. If the column_name option is not specified then the view is created with the same column as specified in the select_statement.

WITH ENCRYPTION encrypts the text for the view in the SYSCOMMENTS tables.

AS specifies the action that will be performed by the view.

select_statement specifies the SELECT statement that defines a view. The view could use other views and tables.

WITH CHECK OPTION forces the data modification statements to follow the criteria given in the SELECT statement definition.

Example

ALTER VIEW vwCustomer
AS
SELECT CustomerId, Company Name, Phone, Fax
FROM Customers

Alters the vwCustomers view to add the Fax column of the Customers table.

When you query on the view using

SELECT *FROM vwCustomer

You see the following output:

CutomerId

Company Name

Phone, Fax

ALFKI

Alfreds Futterkiste

030-0074321, 030-0076545

ANTON

Antonio Moreno Taqueria

(5)555-3932 NULL

AROUT

Around the Horn

(171)555-7788, (171)555-6750

(991 rows affected)

Note

If you define a view, a SELECT* statement, and then the structure of the underlying tables by adding columns, the new columns do not appear in the view. When all columns are selected in a CREATE VIEW statement, the column list is interpreted only when you first create a view. To see the new columns in the view, you must alter the view.


<< Prev Page     Next Page>>    








Home | Peformance Articles | Audit Articles | Business Intelligence Articles | Clustering Articles | Developer Articles | Reporting Services Articles | DBA Articles | ASP.NET / ADO.NET Articles | DBA FAQ's | Developer Peformance FAQ's | DBA Peformance FAQ's | Developer FAQ's | Clustering FAQ's | Error Messages | Audit Tool Reviews | Backup Tool Reviews | Coding Tool Reviews | Compare Tool Reviews | Documentation Tool Reviews | Design Tool Reviews | Monitoring Tool Reviews | Log Tool Reviews | Reporting Tool Reviews | Clustering Tool Reviews | Security Tool Reviews | Change Management Tool Reviews | Remote Access Tool Reviews | Book Reviews | Security Tool Reviews | QDPMA Performance Tuning | ADO.NET / ASP.NET | Administration | Analysis/OLAP Services | Application Development | Configuration | Components | ETL | Hardware | High Availability | Hints | Index | Misc | Operating Systems | Performance Tuning | Replication | T-SQL | Views


              © 1999-2008 by T10 Media. All rights reserved