日期:2014-05-16 浏览次数:20615 次
IF OBJECT_ID('TEST') IS NOT NULL DROP TABLE TEST
GO
CREATE TABLE TEST(ID INT,VAL VARCHAR(50))
GO
INSERT INTO TEST
SELECT 1,'A'
GO
IF OBJECT_ID('V_TEST') IS NOT NULL DROP VIEW V_TEST
GO
CREATE VIEW V_TEST
AS
SELECT *
FROM TEST
GO
SELECT *
FROM V_TEST
GO
INSERT INTO TEST
SELECT 2,'B'
GO
SELECT *
FROM V_TEST
GO
ALTER TABLE TEST ADD VAL2 VARCHAR(50)
GO
SELECT *
FROM V_TEST
GO
INSERT INTO TEST
SELECT 3,'C','D'
GO
SELECT *
FROM V_TEST
GO
SELECT *
FROM SYS.COLUMNS
WHERE OBJECT_ID=OBJECT_ID('V_TEST')
GO
EXEC sp_refreshview V_TEST
GO
SELECT *
FROM SYS.COLUMNS
WHERE OBJECT_ID=OBJECT_ID('V_TEST')