--遍历表 go sp_configure 'allow updates',1 go RECONFIGUREWITH OVERRIDE go declare@SQLvarchar(4000) declare@TableNamevarchar(30) declare sTableName Cursorforselect[name]from sysobjects where xtype='u'and name<>'dtproperties' Open sTableName fetchnextfrom sTableName into@TableName while@@fetch_status=0 begin --更新 set@SQL='update syscolumns set colid=(select count(*) from syscolumns a where a.name<=syscolumns.name and a.id=syscolumns.id),colorder=(select count(*) from syscolumns a where a.name<=syscolumns.name and a.id=syscolumns.id) where id=object_id('''+@TableName+''')' print(@SQL) exec(@SQL) fetchnextfrom sTableName into@TableName end close sTableName deallocate sTableName go sp_configure 'allow updates',0 go RECONFIGUREWITH OVERRIDE