是不是出手救援一下!?

being21 2006-11-06 05:15:11
http://community.csdn.net/Expert/topic/5128/5128512.xml?temp=.9723169

这个是原来的帖子,我想模仿例子写一个自己比较索引的过程,怎么就什么结果都没有呢??
帅哥,靓妹们是不是出手救援一下!?


if exists (select * from dbo.sysobjects where id = object_id(N'[abo].[p_comparestructure_0]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_comparestructure_0]
GO

create proc p_comparestructure_0
@dbname1 varchar(250), --要比较的数据库名1
@dbname2 varchar(250) --要比较的数据库名2
as

begin
set nocount on

create table #tb1(索引名称1 varchar(250),表名 varchar(250),列名 varchar(250),排序 varchar(10),聚集 bit,唯一 varchar(10),
name int,填充因子 int)
create table #tb2(索引名称2 varchar(250),表名 varchar(250),列名 varchar(250),排序 varchar(10),聚集 bit,唯一 varchar(10),
name int,填充因子 int)

exec('select 索引名称1=case when b.keyno=1 then a.name else '''' end
,表名=case when b.keyno=1 then c.name else '''' end
,列名=d.name
,排序=case indexkey_property(c.id,b.indid,b.keyno,''isdescending'')
when 1 then ''降序'' when 0 then ''升序'' end
,聚集=INDEXPROPERTY(c.id,a.name,''IsClustered'')
,唯一=case INDEXPROPERTY(c.id,a.name,''IsUnique'')
when 0 then ''非唯一''
when 1 then case when e.id is null then ''唯一索引'' else ''唯一约束'' end
end
,e.name
,填充因子=a.OrigFillFactor
into #tb1
from '+@dbname1+'..sysindexes a
join '+@dbname1+'..sysindexkeys b on a.id=b.id and a.indid=b.indid
join '+@dbname1+'..sysobjects c on b.id=c.id and c.xtype=''U'' and c.status>=0
join '+@dbname1+'..syscolumns d on b.id=d.id and b.colid=d.colid
left join '+@dbname1+'..sysobjects e on b.indid=e.id and e.xtype=''UQ''
where a.indid not in(0,255)
order by c.name,a.name')


exec('select 索引名称2=case when b.keyno=1 then a.name else '''' end
,表名=case when b.keyno=1 then c.name else '''' end
,列名=d.name
,排序=case indexkey_property(c.id,b.indid,b.keyno,''isdescending'')
when 1 then ''降序'' when 0 then ''升序'' end
,聚集=INDEXPROPERTY(c.id,a.name,''IsClustered'')
,唯一=case INDEXPROPERTY(c.id,a.name,''IsUnique'')
when 0 then ''非唯一''
when 1 then case when e.id is null then ''唯一索引'' else ''唯一约束'' end
end
,e.name
,填充因子=a.OrigFillFactor
into #tb2
from '+@dbname2+'..sysindexes a
join '+@dbname2+'..sysindexkeys b on a.id=b.id and a.indid=b.indid
join '+@dbname2+'..sysobjects c on b.id=c.id and c.xtype=''U'' and c.status>=0
join '+@dbname2+'..syscolumns d on b.id=d.id and b.colid=d.colid
left join '+@dbname2+'..sysobjects e on b.indid=e.id and e.xtype=''UQ''
where a.indid not in(0,255)
order by c.name,a.name')

select 比较结果=case when a.索引名称1 is null then '库1缺少索引:'+b.索引名称2
when b.索引名称2 is null then '库2缺少索引:'+a.索引名称1
else '' end,
*
from #tb1 a
full join #tb2 b on a.索引名称1=b.索引名称2 and a.表名=b.表名
where a.索引名称1 is null or a.表名 is null or b.索引名称2 is null or b.表名 is null
order by isnull(a.索引名称1,b.索引名称2),isnull(a.表名,b.表名)

set nocount off
end

go

--------------------------------------------
select 比较结果=case when a.索引名称1 is null then '库1缺少索引:'+b.索引名称2
when b.索引名称2 is null then '库2缺少索引:'+a.索引名称1
else '' end,
*
from #tb1 a
full join #tb2 b on a.索引名称1=b.索引名称2 and a.表名=b.表名
where a.索引名称1 is null or a.表名 is null or b.索引名称2 is null or b.表名 is null
order by isnull(a.索引名称1,b.索引名称2),isnull(a.表名,b.表名)
--------------------------------------------
为什么差距就这么大呢?我就模仿的写了这么一点,都出问题。
大家尽管BS吧!!!
...全文
115 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
being21 2006-11-07
  • 打赏
  • 举报
回复
呵呵,来者得分!!!分少散了得了!!!
being21 2006-11-07
  • 打赏
  • 举报
回复
呵呵,连BS的都没有???
caixia615 2006-11-07
  • 打赏
  • 举报
回复
飘过学习!!
yjlhch 2006-11-07
  • 打赏
  • 举报
回复
帮顶
allright_flash 2006-11-07
  • 打赏
  • 举报
回复
⊙⌒⊙
 ∨
allright_flash 2006-11-07
  • 打赏
  • 举报
回复


┌──┐
│好贴│ ╭───────╮
 └──┘  ┏━━━━━━━┓ │ 既然有分, │
  ┏┓  ┏┫    |||┣┓∠ 这贴就顶了 │
  ┣┫  ┗┫━━ ┃ ━━┣┛ ╰───────╯
┏┳┫┣┳┓ ┃ ━━━━━ ┃
┃    ┃ ┗━━━┳━━━┛
┗━━━━┻━━━━▇▇▇┛ ()000o
          ┃ ┃  (````)
          ┃ ┃   )``/
          ┛ ┗━━(__/
yuedeem 2006-11-07
  • 打赏
  • 举报
回复
顶肺
marco08 2006-11-06
  • 打赏
  • 举报
回复
關注

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧