生活随笔
收集整理的這篇文章主要介紹了
SQL Server修改表结构后批量更新所有视图
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
--獲取指定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
原文地址:http://www.jianfangkk.com/sqlserver/201608/333
轉載于:https://www.cnblogs.com/jianfangkk/p/6030295.html
總結
以上是生活随笔為你收集整理的SQL Server修改表结构后批量更新所有视图的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。