T-SQL语句显示级联依赖关系 .
2011-10-12 17:28
260 查看
if exists(select name from sysobjects where name='sp_dependss' and xtype='p')
drop procedure sp_dependss
go
create procedure sp_dependss --- 1996/08/09 16:51
@objname nvarchar(776) /* the object we want to check */
as
declare @objid int /* the id of the object we want */
declare @found_some bit /* flag for dependencies found */
declare @dbname sysname
/*
** Make sure the @objname is local to the current database.
*/
select @dbname = parsename(@objname,3)
if @dbname is not null and @dbname <> db_name()
begin
raiserror(15250,-1,-1)
return (1)
end
/*
** See if @objname exists.
*/
select @objid = object_id(@objname)
if @objid is null
begin
select @dbname = db_name()
raiserror(15009,-1,-1,@objname,@dbname)
return (1)
end
/*
** Initialize @found_some to indicate that we haven't seen any dependencies.
*/
select @found_some = 0
/*
** Now check for things that depend on the object.
*/
if exists (select *
from sysdepends
where depid = @objid)
select distinct 'name' = (s.name + '.' + o.name),d.depid,d.id,
type = substring(v.name, 5, 16) into #a
from sysobjects o, master.dbo.spt_values v, sysdepends d,
sysusers s
where o.id = d.id
and o.xtype = substring(v.name,1,2) collate database_default and v.type = 'O9T'
and d.depid = @objid
and o.uid = s.uid
and deptype < 2
begin
while exists(select distinct 'name' = (s.name + '.' + o.name),d.depid,d.id,
type = substring(v.name, 5, 16)
from sysobjects o, master.dbo.spt_values v, sysdepends d,
sysusers s
where o.id = d.id
and o.xtype = substring(v.name,1,2) collate database_default and v.type = 'O9T'
and o.uid = s.uid
and deptype < 2
and d.depid in(select [id] from #a)
and d.id not in (select [id] from #a))
begin
insert into #a(name,depid,id,type) select distinct 'name' = (s.name + '.' + o.name),d.depid,d.id,
type = substring(v.name, 5, 16)
from sysobjects o, master.dbo.spt_values v, sysdepends d,
sysusers s
where o.id = d.id
and o.xtype = substring(v.name,1,2) collate database_default and v.type = 'O9T'
and o.uid = s.uid
and deptype < 2
and d.depid in(select [id] from #a)
and d.id not in (select [id] from #a)
end
select @found_some = 1
select name,type from #a
end
/*
** Did we find anything in sysdepends?
*/
if @found_some = 0
raiserror(15461,-1,-1)
set nocount off
return (0) -- sp_depends
GO
print '1111111111111111111111111测试例子一111111111111111111111111111111111111'
exec sp_depends 'sp_dropdevice'
print '1111111111111111111111111111111111111111111111111111111111111'
exec sp_dependss 'sp_dropdevice'
print '1111111111111111111111111111111111111111111111111111111111111'
print '22222222222222222222222222测试例子二22222222222222222222222222222222222'
exec sp_depends 'syscomments'
print '2222222222222222222222222222222222222222222222222222222222222'
exec sp_dependss 'syscomments'
print '2222222222222222222222222222222222222222222222222222222222222'
--作者:maizc ,珠海科干院05级accp2
--本人不才,只能把系统的sp_depends存储过程修改了一下
drop procedure sp_dependss
go
create procedure sp_dependss --- 1996/08/09 16:51
@objname nvarchar(776) /* the object we want to check */
as
declare @objid int /* the id of the object we want */
declare @found_some bit /* flag for dependencies found */
declare @dbname sysname
/*
** Make sure the @objname is local to the current database.
*/
select @dbname = parsename(@objname,3)
if @dbname is not null and @dbname <> db_name()
begin
raiserror(15250,-1,-1)
return (1)
end
/*
** See if @objname exists.
*/
select @objid = object_id(@objname)
if @objid is null
begin
select @dbname = db_name()
raiserror(15009,-1,-1,@objname,@dbname)
return (1)
end
/*
** Initialize @found_some to indicate that we haven't seen any dependencies.
*/
select @found_some = 0
/*
** Now check for things that depend on the object.
*/
if exists (select *
from sysdepends
where depid = @objid)
select distinct 'name' = (s.name + '.' + o.name),d.depid,d.id,
type = substring(v.name, 5, 16) into #a
from sysobjects o, master.dbo.spt_values v, sysdepends d,
sysusers s
where o.id = d.id
and o.xtype = substring(v.name,1,2) collate database_default and v.type = 'O9T'
and d.depid = @objid
and o.uid = s.uid
and deptype < 2
begin
while exists(select distinct 'name' = (s.name + '.' + o.name),d.depid,d.id,
type = substring(v.name, 5, 16)
from sysobjects o, master.dbo.spt_values v, sysdepends d,
sysusers s
where o.id = d.id
and o.xtype = substring(v.name,1,2) collate database_default and v.type = 'O9T'
and o.uid = s.uid
and deptype < 2
and d.depid in(select [id] from #a)
and d.id not in (select [id] from #a))
begin
insert into #a(name,depid,id,type) select distinct 'name' = (s.name + '.' + o.name),d.depid,d.id,
type = substring(v.name, 5, 16)
from sysobjects o, master.dbo.spt_values v, sysdepends d,
sysusers s
where o.id = d.id
and o.xtype = substring(v.name,1,2) collate database_default and v.type = 'O9T'
and o.uid = s.uid
and deptype < 2
and d.depid in(select [id] from #a)
and d.id not in (select [id] from #a)
end
select @found_some = 1
select name,type from #a
end
/*
** Did we find anything in sysdepends?
*/
if @found_some = 0
raiserror(15461,-1,-1)
set nocount off
return (0) -- sp_depends
GO
print '1111111111111111111111111测试例子一111111111111111111111111111111111111'
exec sp_depends 'sp_dropdevice'
print '1111111111111111111111111111111111111111111111111111111111111'
exec sp_dependss 'sp_dropdevice'
print '1111111111111111111111111111111111111111111111111111111111111'
print '22222222222222222222222222测试例子二22222222222222222222222222222222222'
exec sp_depends 'syscomments'
print '2222222222222222222222222222222222222222222222222222222222222'
exec sp_dependss 'syscomments'
print '2222222222222222222222222222222222222222222222222222222222222'
--作者:maizc ,珠海科干院05级accp2
--本人不才,只能把系统的sp_depends存储过程修改了一下
相关文章推荐
- T-SQL语句显示级联依赖关系 .
- T-SQL语句显示级联依赖关系
- 在创建外键约束的时候, 设置级联删除为SET NULL执行sql语句的时候显示有错误,(数据库为sqlserver2000)?
- 全国省市级联关系表sql语句
- DBCC大全集之(适用版本MS SQLServer 2008 R2)----DBCC INPUTBUFFER显示从客户端发送到 Microsoft SQL Server 实例的最后一个语句
- 设置、显示、移除服务启动依赖关系
- 紧急求助,慢查询日志显示sql语句执行超过几年,怎么回事
- Ibatis中如何才能显示生成的SQL语句
- 通过Log4j的DEBUG级别来显示mybatis的sql语句
- SQL语句两字段拼成一个字段显示
- PowerDesinger:实体关系图->物理数据模型(关系表)->sql语句-数据库
- 随机显示 ** 条记录的SQL语句
- MyBatis显示SQL语句
- 采用p6spy显示Hibernate的SQL语句
- 【63】关系数据库常用的sql语句总结
- mybatis补充教程之一:在控制台显示sql语句,类似hibernate show_sql.
- sql显示sql语句的执行时间及cpu消耗
- mysql显示SQL语句执行时间
- hibernate.cfg.xml配置详解 以及 显示并格式化SQL语句