可以么?
create view v_a
as
select * from aalter view v_a
as
select * from v_aselect * from v_a
/*
Msg 4429, Level 16, State 1, Line 1
View or function 'v_a' contains a self-reference. Views or functions cannot reference themselves directly or indirectly.
Msg 4413, Level 16, State 1, Line 1
Could not use view or function 'v_a' because of binding errors.
*/
不行的,会报错!
视图或者函数不能直接或者引用它自身.
create view v_a
as
select * from aalter view v_a
as
select * from v_aselect * from v_a
/*
Msg 4429, Level 16, State 1, Line 1
View or function 'v_a' contains a self-reference. Views or functions cannot reference themselves directly or indirectly.
Msg 4413, Level 16, State 1, Line 1
Could not use view or function 'v_a' because of binding errors.
*/
不行的,会报错!
视图或者函数不能直接或者引用它自身.
AS
Declare @jxc_ck_table varchar(50),
@jxc_count_i bigint,
@jxc_row_count bigint,
@jxc_sql_string varchar(8000)
--初始化设定
select @jxc_ck_table='',
@jxc_count_i=1,
@jxc_row_count=0,
@jxc_sql_string=''
--判断视图是否存在的情况
Begin
if exists (select * from sysobjects where name='jxc_ck_list' and xtype='V')
drop view jxc_ck_list
End
--得到表的个数
select @jxc_row_count=count(*) from jxc_count_demo_1
--进行判断
if @jxc_row_count<>0
Begin
Begin
While @jxc_count_i<=@jxc_row_count
Begin
Begin
if @jxc_count_i=1
Begin
select @jxc_ck_table=table_name from jxc_count_demo_1 where id=@jxc_count_i
select @jxc_sql_string='Create view jxc_ck_list_'+convert(varchar(10),@jxc_count_i)+' as select * from '+@jxc_ck_table
execute (@jxc_sql_string)
End
End
Begin
if @jxc_count_i>1
Begin
Begin
select @jxc_sql_string='create view jxc_ck_list_'+convert(varchar(10),@jxc_count_i)+' as select * from jxc_ck_list_'+convert(varchar(10),(@jxc_count_i-1))+' union'
select @jxc_sql_string=@jxc_sql_string+' select * from '+@jxc_ck_table
execute (@jxc_sql_string)
End
--初始数据
Begin
select @jxc_count_i=@jxc_count_i+1
select @jxc_sql_string=''
End
End
End
End
End
-- --删除多于的视图了
-- Begin
-- select @jxc_count_i=1
-- select @jxc_sql_string='sp_rename jxc_ck_list_'+convert(varchar(10),@jxc_row_count)+',jxc_ck_list'
-- while @jxc_count_i<@jxc_row_count
-- Begin
-- select @jxc_sql_string='drop view jxc_ck_list_'+convert(varchar(10),@jxc_count_i)
-- execute(@jxc_sql_string)
-- End
-- End
End
Else
Return
GO
------这是我写的一个存储过程,但是运行非常慢