For example, we created a table T1 and a T1 view V1, then changed T1, and then looked at the V1 results:
Create Table T1 first:
Copy codeThe Code is as follows:
IF OBJECT_ID ('T1 ') IS NOT NULL
Drop table T1
Create table T1 (col1 INT, col2 INT)
Insert into T1 (col1, col2) VALUES (1, 2)
GO
Then create the T1 view V1:
Copy codeThe Code is as follows:
Create view V1
AS
SELECT * FROM T1
In practice, avoid using * in the SELECT statement in the view. This is only a demonstration. If you query view V1, the following results are displayed:
Next, we will add a column col3 to table T1:
Copy codeThe Code is as follows:
Alter table T1 ADD col3 INT
Then you can query view V1 again. Do you want to query three columns or columns? The answer is two columns. The change in T1 architecture does not affect the view metadata. At this time, if we need to refresh the view V1, we can use the EXEC sp_refreshview V1 command to query it again, the V1 result is three columns.