ABC of Views
  Home FAQ Contact Sign in
microsoft.public.sqlserver.programming only
 
Advanced search
POPULAR GROUPS

more...

microsoft ... programming Profile…
 Up
ABC of Views         


Author: LUIS
Date: May 6, 2008 17:41

I have used MSSQL Server for 10 years.
I just have used Tables(obvious), Diagrams an Stored Procedures.
Yesterday I learn how to use UDF, they are easy.
Now I want to use Views.
I have an idea(logical) how they work, but I want to ask some questions to
begin with:

1. When you CREATE a VIEW, information in it is not UPDATED automatically if
TABLES related with are UPDATED, it means, VIEWS are independent from TABLES.

2. If information in VIEWS is temporary, correct use of them is.
a) CREATE it.
b) USE it inmediately
c) CLEAR it or DROP it.

3. If all my work is done in SP's, a good way to use VIEWS is to CREATE, to
USE and to DROP inside SP's.

Beforehand, thank you very much.

--
Luis Garcia
IT Consultant
4 Comments
Re: ABC of Views         


Author: Aaron Bertrand [SQL Server MVP]
Date: May 6, 2008 18:00

> 1. When you CREATE a VIEW, information in it is not UPDATED automatically if
> TABLES related with are UPDATED, it means, VIEWS are independent from TABLES.

Actually, quite the opposite is true. A view does not store any
information; it is simply a saved copy of the query. When you say SELECT
col_list FROM dbo.view_name; SQL Server actually goes out and fetches the
data from the table (assuming the view references a table; you can create a
view that doesn't, but this is rather rare).

Well, there is an exception: indexed views. An indexed view actually does
save a copy of the data, but it is automatically updated when you update the
base table(s).

In both cases, the data "in the view" is always up to date.
> 2. If information in VIEWS is temporary, correct use of them is.
> a) CREATE it.
> b) USE it inmediately
> c) CLEAR it or DROP it.

I think you are thinking of #temp tables here, not views.
>
> 3. If all my work is done in SP's, a good way to use VIEWS is to CREATE, to
> USE and to DROP inside SP's.
Show full article (1.19Kb)
no comments
Re: ABC of Views         


Author: Dan Guzman
Date: May 6, 2008 18:15

> 1. When you CREATE a VIEW, information in it is not UPDATED automatically
> if
> TABLES related with are UPDATED, it means, VIEWS are independent from
> TABLES.

A view is simply a query over the table(s) so any modifications will be
immediately reflected in the base table(s). There are restrictions on
updateable views, however. see the Books Online for details.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"LUIS" discussions.microsoft.com> wrote in message
news:988E4CB2-9BED-4CE8-ACD2-131F951FFA85@microsoft.com...
>I have used MSSQL Server for 10 years.
> I just have used Tables(obvious), Diagrams...
Show full article (1.33Kb)
no comments
Re: ABC of Views         


Author: LUIS
Date: May 7, 2008 10:01

Dan:

Thank you very much. By the way, your last name tells Spanish roots. Es es
bueno.

--
Luis Garcia
IT Consultant

"Dan Guzman" wrote:
>> 1. When you CREATE a VIEW, information in it is not UPDATED automatically
>> if
>> TABLES related with are UPDATED, it means, VIEWS are independent from
>> TABLES.
>
> A view is simply a query...
Show full article (1.57Kb)
no comments
Re: ABC of Views         


Author: LUIS
Date: May 7, 2008 10:47

Aaron

Thank you very much. You avoid to me the biggest misunderstanding that I do
for living.

--
Luis Garcia
IT Consultant

"Aaron Bertrand [SQL Server MVP]" wrote:
>> 1. When you CREATE a VIEW, information in it is not UPDATED automatically if
>> TABLES related with are UPDATED, it means, VIEWS are independent from TABLES.
>
> Actually, quite the opposite is true...
Show full article (1.44Kb)
no comments