视图的依赖
我现在写了个小工具。将视图导出成sql语句。但是视图的依赖关系没有解决。
谁有好的办法。
--------------
SELECT DISTINCT
dbo.sysobjects.name, sysobjects_1.name AS name2,
sysobjects_1.xtype,depnumber,depid,sysdepends.id,sysobjects.type
FROM dbo.sysobjects sysobjects_1 INNER JOIN
dbo.sysdepends ON sysobjects_1.id = dbo.sysdepends.id RIGHT OUTER JOIN
dbo.sysobjects ON dbo.sysdepends.depid = dbo.sysobjects.id
WHERE ((dbo.sysobjects.type = 'v 'or dbo.sysobjects.type = 'P 'or dbo.sysobjects.type = 'u ') and dbo.sysobjects.STATUS> =0 and sysobjects.name <> 'syssegments ' and sysobjects.name <> 'sysconstraints ')
order by depnumber desc
TABLE1 tttt P 2 1253579504 1653580929 U
TABLE1 VIEW1 V 2 1253579504 1621580815 U
TABLE2 VIEW2 V 2 1589580701 1637580872 U
VIEW1 VIEW3 V 2 1621580815 1685581043 V
VIEW2 VIEW3 V 2 1637580872 1685581043 V
TABLE1 tttt P 1 1253579504 1653580929 U
TABLE1 VIEW1 V 1 1253579504 1621580815 U
TABLE2 VIEW2 V 1 1589580701 1637580872 U
tttt ttt P 1 1653580929 1701581100 P
VIEW1 VIEW3 V 1 1621580815 1685581043 V
VIEW2 VIEW3 V 1 1637580872 1685581043 V
TABLE3 NULL NULL NULL NULL NULL U
ttt NULL NULL NULL NULL NULL P
VIEW3 NULL NULL NULL NULL NULL V
不知道这个有没有用。如果有用的话。该如果来程序来实现先后关系。可以用JAVA或。NET
------解决方案--------------------SELECT distinct b.name,b.xtype
FROM dbo.sysdepends a
left JOIN dbo.sysobjects b ON a.id=b.id
WHERE a.depid=object_id( 'h_info ') and b.status> 0
------解决方案--------------------两个一样的?
在sysdepends表中按id与depid找出父子关系,depid> 1的表示有父对象,先创建父对象,再创建子对象.