--云星空重建索引SQLDECLARE@sqlNVARCHAR(1000)=DBCCDBREINDEX(@TABLE_NAME)WITHNO_INFOMSGS;DECLARE@tblNVARCHAR(1000)=DECLAREtblcurCURSORFORSELECT[NAME]FROMsys.tablesWHERE[NAME]NOTLIKETMP%AND[NAME]NOTLIKEZ[_]%ORDERBY1FORREADONLYOPENtblcurFETCHNEXTFROMtblcurINTO@tblWHILE@@FETCH_STATUS=0BEGINEXECSP_EXECUTESQL@sql,N@table_nameNVARCHAR(1000),@tblPRINT表重建索引成功:+@tblFETCHNEXTFROMtblcurINTO@tblENDCLOSEtblcurDEALLOCATEtblcurPRINT全部执行完成!
SETANSI_NULLSONSETQUOTED_IDENTIFIERONDECLARE@sqlVARCHAR(max)SET@sql=SELECT@sql=@sql+dbccdbreindex([+name+]);+char(13)+char(10)FROMsys.tablesWHEREnameNOTLIKETMP%ANDNAMENOTLIKEZ[_]%EXEC(@sql)
Ifexists(select*fromKSQL_INDEXESwhereKSQL_INDNAME=index_HR_EnrollEntryBillId)dropindexT_HR_EmpEnrollBizBillEntry.index_HR_EnrollEntryBillId;Ifnotexists(select*fromKSQL_INDEXESwhereKSQL_INDNAME=index_HR_EnrollEntryBillId)createindexindex_HR_EnrollEntryBillIdonT_HR_EmpEnrollBizBillEntry(FBillID);Ifexists(select*fromKSQL_INDEXESwhereKSQL_INDNAME=index_HR_HireEntryBillId)dropindexT_HR_EmpHireBizBil...
DECLARE@DBCCStringNVARCHAR(1000)DECLARE@TableNameVARCHAR(100)DECLARECur_IndexCURSORFORSELECTNameASTblNameFROMsysobjectsWHERExType=UORDERBYTblNameFORREADONLYOPENCur_IndexFETCHNEXTFROMCur_IndexINTO@TableNameWHILE@@FETCH_STATUS=0BEGINPRINT重建表+@TableName+的索引........Start!SET@DBCCString=DBCCDBREINDEX(@TblName,)WITHNO_INFOMSGSEXECSP_EXECUTESQL@DBCCString,N@TblNameVARCHAR(100),@TableNamePRINT重建表+@TableName+的索引........END!FETCHNEXTFROMCur_IndexINTO@TableNameEND
创建test表(测试表)droptableifexiststest;createtabletest(idintprimarykeyauto_increment,c1varchar(10),c2varchar(10),c3varchar(10),c4varchar(10),c5varchar(10))ENGINE=INNODBdefaultCHARSET=utf8;insertintotest(c1,c2,c3,c4,c5)values(a1,a2,a3,a4,a5);insertintotest(c1,c2,c3,c4,c5)values(b1,b2,b3,b4,b5);insertintotest(c1,c2,c3,c4,c5)values(c1,c2,c3,c4,c5);insertintotest(c1,c2,c3,c4,c5)values(d1,d2,d3,d...