Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL Server equivalente a CREATE OR REPLACE VIEW di Oracle

Le soluzioni di cui sopra, anche se riusciranno a portare a termine il lavoro, lo fanno a rischio di far cadere le autorizzazioni dell'utente. Preferisco creare o sostituire viste o stored procedure come segue.

IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vw_myView]'))
    EXEC sp_executesql N'CREATE VIEW [dbo].[vw_myView] AS SELECT ''This is a code stub which will be replaced by an Alter Statement'' as [code_stub]'
GO

ALTER VIEW [dbo].[vw_myView]
AS
SELECT 'This is a code which should be replaced by the real code for your view' as [real_code]
GO