sql server '<createView replaceIfExists="true" ' should use create;alter rather than drop;create syntax
Description
Environment
sql server
Activity
Show:
Nathan Voxland August 24, 2015 at 7:06 PM
Yes, this has been fixed. Thanks for finding the issue
Andrew Hill July 29, 2015 at 4:24 AM
appears to be fixed – recent code generation resulted in
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vw_XXX]'))
EXEC sp_executesql N'CREATE VIEW [dbo].[vw_XXX] AS SELECT ''This is a code stub which will be replaced by an Alter Statement'' as [code_stub]'
GO
ALTER VIEW [vw_XXX] AS ...
Fixed
Details
Details
Reporter
Andrew Hill
Andrew HillComponents
Affects versions
Priority
Created June 12, 2014 at 7:44 AM
Updated August 24, 2015 at 7:06 PM
Resolved August 24, 2015 at 7:06 PM
<createView replaceIfExists="true" viewName="test"> select columns from table
</creageView>
produces
IF EXISTS (...)
drop test
create vew
...
the problem with this is that this will drop any permission settings on the view, and re-running an already applied permissions change set could cause problems.
A much better approach for sql server is (see http://stackoverflow.com/a/18535115/432976 ):
if not exists(...)
create test as select 1;
alter view test as
select columns from table