分享

批量重排标识列顺序

 bubbi7 2016-02-26

原贴发表在 http://community.csdn.net/Expert/TopicView1.asp?id=4296496

/*
    由于删除等操作,表中的identity列可能出现不连续的数字,这时可以重新对标识列排序
    基本思路:删除标识列,然后重建

    --vivianfdlpw 2005.9 引用请保留此信息
*/
exec sp_msforeachtable
       @command1='if exists(select 1 from syscolumns
                               where id=object_id(''?'')
                                     and autoval is not null)
                  begin
                     declare @name varchar(20)
                     select @name=name from syscolumns
                        where id=object_id(''?'') and autoval is not null
                     exec(''alter table ? drop column ''+@name)
                     exec(''alter table ? add ''+@name+'' int identity(1,1)'')
                 end
                '

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多