Showing posts with label itis. Show all posts
Showing posts with label itis. Show all posts

Tuesday, February 14, 2012

Concept for View

Hi,
Could someone please explain to me when the view is updatable and when it
is not? I am under the impression that if the two tables are joined togethe
r
in the view, then the view is not updatable... is it correct?
ThanksSee the CREATE VIEW in the Books Online <tsqlref.chm::/ts_create2_30hj.htm>
for a detailed description of when a view is updatable.
For an updatable view containing joins, INSERT/UPDATE/DELETE statements are
allowed as long as only one underlying base table is affected. For example:
CREATE TABLE Table1
(
Col1a int NOT NULL
CONSTRAINT PK_Table1 PRIMARY KEY,
Col1b int NOT NULL
)
GO
CREATE TABLE Table2
(
Col2a int NOT NULL
CONSTRAINT PK_Table2 PRIMARY KEY,
Col2b int NOT NULL
)
GO
CREATE VIEW MyView
AS
SELECT Col1a, Col1b, Col2a, Col2b
FROM Table1 AS t1
JOIN Table2 AS t2 ON
t2.Col2a = t1.Col1a
GO
--succeeds
UPDATE MyView
SET Col1b = 1
GO
--fails
UPDATE MyView
SET Col1b = 1, Col2b = 1
Hope this helps.
Dan Guzman
SQL Server MVP
"Ed" <Ed@.discussions.microsoft.com> wrote in message
news:864C5D55-3A5D-4F97-ABF1-9DAE7B057B33@.microsoft.com...
> Hi,
> Could someone please explain to me when the view is updatable and when it
> is not? I am under the impression that if the two tables are joined
> together
> in the view, then the view is not updatable... is it correct?
> Thanks