What is the benefit of inserting in a view vs. in tables directly? e.g. Scenario #1
What if the view has only a few columns from a table, are you still able to insert successfully? e.g. Scenario #2
Scenario #1:
CREATE TABLE dbo.tbl1
(
ID INT NOT NULL,
NAME VARCHAR(32) NOT NULL
);
CREATE VIEW dbo.vw_x
AS
SELECT ID, Name
FROM dbo.tbl1
WHERE ID = 2
INSERT INTO dbo.vw_x
SELECT 2, 'Name';
Scenario #2:
CREATE TABLE dbo.tbl1
(
ID INT NOT NULL,
NAME VARCHAR(32) NOT NULL
);
CREATE TABLE dbo.tbl2
(
ID INT NOT NULL,
VALUE VARCHAR(32) NOT NULL
);
CREATE VIEW dbo.vw_x
AS
SELECT t1.ID, t2.Value
FROM dbo.tbl1 t1
INNER JOIN dbo.tbl2 t2
ON t1.ID = t2.ID
WHERE t1.ID = 2
INSERT INTO dbo.vw_x
SELECT 2, 'Name';