CREATE OR REPLACE VIEW data_VVVV AS
SELECT
VCV.xxxx,
VCV.yyyy AS yyyy,
VCV.zzzz AS zzzz
FROM
TABLE_A
;
但是MS SQL下無法這樣做要處理以下的問題可使用
1.
IF OBJECT_ID('dbo.data_VVVV') IS NULL
BEGIN
CREATE VIEW dbo.data_VVVV
AS
SELECT VCV.xxxx, VCV.yyyy AS yyyy, VCV.zzzz AS zzzz FROM TABLE_A VCV
END
ELSE
ALTER VIEW dbo.data_VVVV
AS
SELECT VCV.xxxx, VCV.yyyy AS yyyy, VCV.zzzz AS zzzz FROM TABLE_A VCV
BEGIN
END
or2.
IF OBJECT_ID('dbo.test_abc_def', 'V') IS NOT NULL
DROP VIEW dbo.test_abc_def
GO
CREATE VIEW dbo.test_abc_def AS
SELECT
VCV.xxxx
,VCV.yyyy AS yyyy
,VCV.zzzz AS zzzz
FROM TABLE_A
如果要判斷這個View是否存在還有別的用法,如:
IF (NOT EXISTS (SELECT 1 FROM sys.views WHERE name = 'data_VVV'))
if not exists (select * from sysobjects where name='data_VVV
' and xtype='V')
剩下就看你要Drop重建或是Alter View
沒有留言:
張貼留言