473,236 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

A few simple questions about SQL Server 'Views'

Hello,

I am building an application for Windows Forms using. I am new to SQL
Server 'Views'. Are the following correct understanding of their use?

1.) I believe a view can be referenced in a stored procedure something
like this;
Select * from View1
Is that true?

2.) I believe I can update to a view even when it includes two tables.
I intend to build a dataAdapter to a view for select and update. I
believe it can keep track of how to perform the update? Do I understand
its use correctly?

3.) Is it necessary to include both the the PK and FK when two tables
are part of the view or does it know the relationship established in
the database in the 'diagrams' area take care of that?

Thank you,
dbuchanan

Nov 23 '05 #1
2 1927
1) Yes
2) As long as you update only one of the member tables. That said, some
views are not updateable.
3) No

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com

<db*********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hello,

I am building an application for Windows Forms using. I am new to SQL
Server 'Views'. Are the following correct understanding of their use?

1.) I believe a view can be referenced in a stored procedure something
like this;
Select * from View1
Is that true?

2.) I believe I can update to a view even when it includes two tables.
I intend to build a dataAdapter to a view for select and update. I
believe it can keep track of how to perform the update? Do I understand
its use correctly?

3.) Is it necessary to include both the the PK and FK when two tables
are part of the view or does it know the relationship established in
the database in the 'diagrams' area take care of that?

Thank you,
dbuchanan

Nov 23 '05 #2
db*********@hotmail.com wrote:
Hello,

I am building an application for Windows Forms using. I am new to SQL
Server 'Views'. Are the following correct understanding of their use?

1.) I believe a view can be referenced in a stored procedure something
like this;
Select * from View1
Is that true?
Yes

2.) I believe I can update to a view even when it includes two tables.
I intend to build a dataAdapter to a view for select and update. I
believe it can keep track of how to perform the update? Do I understand
its use correctly?
Copy&Pasted from SQLServer Documentation:

Updatable Views
You can modify the data of an underlying base table through a view, as
long as the following conditions are true:

Any modifications, including UPDATE, INSERT, and DELETE statements, must
reference columns from only one base table.
The columns being modified in the view must directly reference the
underlying data in the table columns. The columns cannot be derived in
any other way, such as through the following:
An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV,
STDEVP, VAR, and VARP.
A computation. The column cannot be computed from an expression that
uses other columns. Columns that are formed by using the set operators
UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT amount to a
computation and are also not updatable.
The columns being modified are not affected by GROUP BY, HAVING, or
DISTINCT clauses.
The previous restrictions apply to any subqueries in the FROM clause of
the view, just as they apply to the view itself. Generally, the Database
Engine must be able to unambiguously trace modifications from the view
definition to one base table. For more information, see Modifying Data
Through a View.

If the previous restrictions prevent you from modifying data directly
through a view, consider the following options:

INSTEAD OF Triggers

INSTEAD OF triggers can be created on a view to make a view updatable.
The INSTEAD OF trigger is executed instead of the data modification
statement on which the trigger is defined. This trigger lets the user
specify the set of actions that must happen to process the data
modification statement. Therefore, if an INSTEAD OF trigger exists for a
view on a specific data modification statement (INSERT, UPDATE, or
DELETE), the corresponding view is updatable through that statement. For
more information about INSTEAD OF triggers, see Designing INSTEAD OF
Triggers.
Partitioned Views

If the view is a partitioned view, the view is updatable, subject to
certain restrictions. When it is needed, the Database Engine
distinguishes local partitioned views as the views in which all
participating tables and the view are on the same instance of SQL
Server, and distributed partitioned views as the views in which at least
one of the tables in the view resides on a different or remote server.

For more information about partitioned views, see Creating Partitioned
Views.


3.) Is it necessary to include both the the PK and FK when two tables
are part of the view or does it know the relationship established in
the database in the 'diagrams' area take care of that?
You define Views in SQL... so you have to define the "join" that you
want to use.
Thank you,
dbuchanan

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kofi | last post by:
I need just the names of tables, views and sprocs within a SQL Server database. What's the easiest way to do this?
5
by: pete | last post by:
Today I need to copy 8 records in a table. I have to use Access 200 because of the limitation of Enterprise Manager's inability to cope with field with more than 900 characters. Selected records,...
1
by: John | last post by:
Hi I have a fairly complex access frontend/backend app which I need to upsize to SQL Server. At this stage I would prefer to use access as frontend. I have the following questions; 1. Should...
8
by: Old VB6 Guy | last post by:
First of all, sorry if crossposting bothers you -- I don't normally do it, but both of these groups seem relavant to my questions. Alright, the time has finally come to make an investment in time...
4
by: datapro01 | last post by:
Running DB28.2 on AIX 5.2. I have two questions if its possible for anyone to assist. 1. Is it possible to make use of a 'Shadow Catalog' on DB2 UDB v8.2 on AIX? If so, how? Can anyone give...
5
by: Newbie | last post by:
Hi all, Just want to comment on this thread. Seems like every discussion about this matter (setting up DB provider for membership) and all the samples/references given by some MVPs always...
30
by: James Conrad StJohn Foreman | last post by:
After 3 years of using DB2 on Linux, I'm leaving my current employers to go work for a SQL Server shop instead. In order to find my replacement, they're trying to put together a set of questions...
0
by: Andy S. | last post by:
I'm not very knowledgeable using Visual Studio deployment projects, but I have 2 questions. 1. Can you perform SQL server database functions (i.e. Add views, stored procedures)? I overcame...
1
by: TGEAR | last post by:
I am using MS SQL Server management studio. I treid to see some system tables which are sysobjects, syscolumns, systypes, etc.., but i don't see the list under the system tables folder. There is...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.