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

Filtered Indexes in SQL Server 2008
Importance of Database Backups and Recovery Plan
Data Compression in SQL Server 2008
SQL Server 2008 MERGE Statement

More     
 
Latest FAQ's

ALTER TABLE SWITCH statement failed because the object '%.*ls' is not ...
ALTER TABLE SWITCH statement failed because column '%.*ls' at ordinal %d ...
ALTER TABLE SWITCH statement failed because table '%.*ls' has %d columns ...
SQL Server Reporting Server (SSRS) service is failing to start ...

More     
   
Latest Software Reviews

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

More     

articles >> general dba >> SQL Server 2000: View Basics ...

SQL Server 2000: View Basics

By : Navneeth Diwaker Naik
Jan 16, 2004

Page 2 / 3

Indexed Views

SQL SERVER 2000 allows an index to be created on a View. Wow! Previous versions of SQL SERVER will not allow you to do this. But one important point to be noted here is that the first index on the View should be a UNIQUE CLUSTERED INDEX only. SQL SERVER 2000 will not allow you to create any other INDEX unless you have an UNIQUE CLUSTERED INDEX defined on the view.

Let’s check out a sample example for an Indexed View:

CREATE VIEW vwSample

As

SELECT

          CustomerID,

          CompanyName,

          ContactName

FROM DBO.CUSTOMERS

GO

CREATE UNIQUE CLUSTERED INDEX indClustered

ON NORTHWIND.DBO.VWSAMPLE (CUSTOMERID)

GO

The above statement will create a unique clustered index on the View.

Remember to drop the view.

DROP VIEW vwSample

 

Different Uses of Views

Views can be used to insert/update and delete data from a table. Let’s have a detailed look how to do this. First of all we shall see how to insert data in the table using a view.

The below T-SQL will create a table named TEST and a View with the name vwSample.

USE NORTHWIND

GO

CREATE TABLE [Test]

(

TestID INT,

TestName VARCHAR (100)

)

GO

CREATE VIEW vwTest

As

SELECT

          TestID, TestName

FROM Test

GO

Now we shall insert the data into the table Test using the view. How?

Execute the below T-SQL statement. This will insert the data into the table Test.

INSERT INTO vwTest

VALUES (1, 'Test 1')

SELECT * from Test

TestID           TestName
-------------------------------
1                Test 1

Now we shall see how to Update the data using the same View.

UPDATE vwTest

SET TestName = 'New Value'

WHERE TestID = 1

SELECT * from Test

TestID           TestName
--------------------------------
1                New Value

Similarly we can also delete the data from table using the same view.

Remember to drop the view.

DELETE FROM vwTest


<< 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