CREATE PROCEDURE [dbo].[p_GetV_view]
AS
BEGIN
DECLARE @sqlstr1 varchar(255)
DECLARE @sqlstr2 varchar(255)

SELECT @sqlstr1='IF EXISTS (SELECT 1 FROM sys.VIEWS WHERE NAME=''V_view'')  DROP VIEW V_view'--判断视图是否存在,存在则删除

SELECT @sqlstr2='CREATE VIEW V_view AS SELECT * FROM [dbo].[t_table]' --创建视图
EXEC (@sqlstr1)
EXEC (@sqlstr2)
END

04-25 22:23