--获取指定SQLServer数据库所有表及视图的字段列表及类型、长度
Select o.Name As ObjectsName , c.name As ColumnsName , t.name As ColumnsType , c.length As ColumnsLength From SysObjects As o , SysColumns As c , SysTypes As t Where o.type in ('u','v') And o.id = c.id And c.xtype = t.xtype Order By o.name , c.name , t.name , c.Length
--SQL SERVER得到表、视图、存储过程、触发器、字段的信息
select name from sysobjects where xtype='TR' --所有触发器 select name from sysobjects where xtype='P' --所有存储过程 select name from sysobjects where xtype='V' --所有视图 select name from sysobjects where xtype='U' --所有表
--SQL Server修改表结构后批量更新所有视图
CREATE PROCEDURE RefreshAllViewASBEGIN DECLARE MyCursor CURSOR FOR select Name from dbo.sysobjects where OBJECTPROPERTY(id, N'IsView') = 1 and (not name in ('sysconstraints','syssegments')) DECLARE @name varchar(40) OPEN MyCursor FETCH NEXT FROM MyCursor INTO @name WHILE (@@fetch_status <> -1) BEGIN IF (@@fetch_status <> -2) begin exec sp_refreshview @name end FETCH NEXT FROM MyCursor INTO @name END CLOSE MyCursor DEALLOCATE MyCursor END