We can not insert data into view instead we can insert data into the underline table of view. SQL Server will
allow you to insert data into the underlying table through a view with a condition:
*The insert columns must be limited to columns of a single underlying table:- This means if a view is composed of 2 or more tables then insert should be made to column of one table at time.
For example
SELECT tb1.tab1_id, tb2.tab2_id, tb1.value tab1_value, tb2.value
tab2_value
FROM table1 tb1
INNER JOIN table2 tb2
Where tb1.tab1_id=tb2.tab1_id
This is a view "vTest" made from two table table1 and table2 inner joined on
tab1_id field
Now if you insert data from view to underlying table of table1 and Table2 you
need to do this in this way:
INSERT INTO vTest (tab1_id, tab1_value) VALUES (3, 30);
INSERT INTO vTest (tab2_id, tab1_id, tab2_value) VALUES (1,3, 30);
Post Reference: Vikram Aristocratic Elfin Share
No comments:
Post a Comment