Sample Header Ad - 728x90

Insert into indexed view?

1 vote
1 answer
268 views
I give an example to show my problem. I create 2 table as the following:
CREATE TABLE a
(
	id INT
)

CREATE TABLE b
(
	name NVARCHAR(10),
	id INT
)
Then insert data into these tables
INSERT INTO a VALUES(1),(2)
INSERT INTO b VALUES('Kan',1),('Michael',2)
Next,I create indexed view that join these tables via id
CREATE VIEW a_b
WITH SCHEMABINDING
AS
(
SELECT a.id,b.name FROM a INNER JOIN b ON a.id=b.id
)

CREATE UNIQUE CLUSTERED INDEX ix_a_b
ON a_b(id)

INSERT INTO a_b VALUES (3,'Joe') will be wrong
As I know about view: + views do not store data,just saved queries + but indexed view that stored data physically like table in the database.So why I don't insert,delete from a_b? And what I know about VIEW is right or wrong?Help me improve?
Asked by Dunguyen (51 rep)
Apr 9, 2020, 02:11 PM
Last activity: May 21, 2025, 09:09 AM