ITPub博客

首页 > 数据库 > SQL Server > SQL SERVER 快速重建所有视图

SQL SERVER 快速重建所有视图

原创 SQL Server 作者:heyong3 时间:2006-12-30 10:22:59 0 删除 编辑


DECLARE test_cursor CURSOR
FOR select id,name from invest..sysobjects where OBJECTPROPERTY(id, N'IsView') = 1 and name not like 'sys%'

DECLARE @name varchar(100)
declare @id int
DECLARE @SQLSTR varchar(4000)

OPEN test_cursor

FETCH NEXT FROM test_cursor INTO @id,@name
WHILE (@@fetch_status <> -1)
BEGIN
BEGIN
set @sqlstr='drop view '+@name
select @sqlstr
select 'go'

--select text from sysobjects o,syscomments c where o.id=c.id and xtype='V' and name not like 'sys%' and o.id=@id
execute SP_HELPTEXT @objname=@name

select 'GO'

--exec @sqlstr

END
FETCH NEXT FROM test_cursor INTO @id,@name
END

CLOSE test_cursor
DEALLOCATE test_cursor
GO

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12172/viewspace-887285/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    16
  • 访问量
    766680