pol*_*nts 1 sql t-sql ddl stored-procedures sql-server-2005
我想创建一个临时存储过程来创建几个视图; 所以这样的事情:
create proc #t1 as
begin
create view v1 as select 1 as x
go
create view v2 as select 2 as x
end
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我在Microsoft SQL Server 2005中执行此操作时,我在第一create view行遇到语法错误.
像这样的东西有效:
create proc #t1 as
begin
exec('create view v1 as select 1 as x')
exec('create view v2 as select 2 as x')
end
Run Code Online (Sandbox Code Playgroud)
然而,这似乎是一种做我想做的事情的可怕方式.
那么第一次尝试出了什么问题,在存储过程中创建多个视图的最佳方法是什么?