SQL Serveϵͳ±íË𻵵Ĵ¦Àí·½·¨
½üÈÕÓöµ½¶þÌ×Êý¾Ý¿âË𻵵ÄÎÊÌâ,Ìظø´ó¼Ò·ÖÏíÒ»ÏÂ.ÈçºÎ½â¾ö!
Ò»¡¢SQL SVRÊý¾Ý¿âÖÐÈýÕÅÖØÒªµÄϵͳ±í
    sysobjects£ºÔÚÊý¾Ý¿âÄÚ´´½¨µÄÿ¸ö¶ÔÏó£¨Ô¼Êø¡¢Ä¬ÈÏÖµ¡¢ÈÕÖ¾¡¢¹æÔò¡¢´æ
            ´¢¹ý³ÌµÈ£©ÔÚ±íÖÐÕ¼Ò»ÐС£
sysindexes£ºÊý¾Ý¿âÖеÄÿ¸öË÷ÒýºÍ±íÔÚ±íÖи÷Õ¼Ò»ÐС£
syscolumns£ºÃ¿¸ö±íºÍÊÓͼÖеÄÿÁÐÔÚ±íÖÐÕ¼Ò»ÐУ¬´æ´¢¹ý³ÌÖеÄÿ¸ö²ÎÊý
            ÔÚ±íÖÐÒ²Õ¼Ò»ÐС£
ÕâÈýÕűíÓÃID£¨±íID£©×ֶιØÁª¡£ÕâÈýÕÅϵͳ±íÒ»µ©Ë𻵣¬ÓëÖ®¶ÔÓ¦Êý¾Ý¿â¶ÔÏó½«ÎÞ·¨·ÃÎÊ£¬Æä×÷ÓÃÏ൱ÓÚDOSÖеġ°Îļþ·ÖÅä±í¡± ¡£
¶þ¡¢ÏµÍ³±íË𻵵ÄÖ¢×´
u      Óà DBCC CHECKDB Я´øÈκβÎÊý¶¼ÎÞ·¨ÐÞ¸´Êý¾Ý¿â£¬Ò²¾ÍÊÇ˵£ºDBCC CHECKDB¶ÔÕâ¸öÕÊÌ׸ù±¾²»Æð×÷Óã»
u      ÎÞ·¨Ö´ÐÐÈçϲÙ×÷£º
select * from sysobjects »òselect * from sysindexes
»òselect * from syscolumns £»
u      ÎÞ·¨ÓÃSQL server DTS»òÆäËûSQL ½Å±¾µ¼¿â¹¤¾ß½øÐе¼¿â£¬µ¼¿âµÄÖÐ;ʧ°Ü£¬±¨¸æ£ºÁ¬½ÓÖжϣ»
u      ÔÚÆóÒµ¹ÜÀíÆ÷»ò²éѯ·ÖÎöÆ÷ÖУ¬²¿·ÖÓû§Êý¾Ý±íÎÞ·¨·ÃÎÊ¡£
Èý¡¢´¦Àí·½·¨
ËÄ¡¢Àý
Àý£ºÒ»sql svrÊý¾Ý¿â£¬ÊµÌåÃûΪ£ºAIS20030529181217
ÓÃDBCC CHECKDB¼ì²â£¬±¨¸æ£¨ÓÃDBCC CHECKDB ´øÈκβÎÊý¶¼ÊÇÒÔÏÂÌáʾ£©£º
·þÎñÆ÷: ÏûÏ¢ 8966£¬¼¶±ð 16£¬×´Ì¬ 1£¬ÐÐ 1
δÄܶÁÈ¡²¢ãÅËøÒ³ (1:29262)£¨ÓÃãÅËøÀàÐÍ SH£©¡£SYSOBJECTS ʧ°Ü¡£
DBCC Ö´ÐÐÍê±Ï¡£Èç¹û DBCC Êä³öÁË´íÎóÐÅÏ¢£¬ÇëÓëϵͳ¹ÜÀíÔ±ÁªÏµ¡£
Ö´ÐÐselect * from sysobjects£¬±¨¸æÈçÏ£º
·þÎñÆ÷: ÏûÏ¢ 644£¬¼¶±ð 21£¬×´Ì¬ 3£¬ÐÐ 1
δÄÜÔÚË÷ÒýÒ³ (1:29262) ÖÐÕÒµ½ RID ¡®16243a6d19100¡¯ µÄË÷ÒýÌõÄ¿£¨Ë÷Òý ID 0£¬Êý¾Ý¿â ¡®AIS20030529181217¡¯£©¡£
Á¬½ÓÖжÏ
  µ«ÊÇÖ´ÐÐselect * from sysindexes ºÍselect * from syscolumns Õý³£¡£
  Õâ˵Ã÷Ö»ÓÐsysobjects±íË𻵣¬¶ø sysindexes ºÍ syscolumns ûÓÐÎÊÌâ¡£
´¦Àí²½Ö裺
µÚÒ»²½£º ´¦Àí¿ÉÒÔ·ÃÎʵÄÊý¾Ý±í
(1.1) ÕÒ³öÄÄЩ±í²»¿É·ÃÎÊ£»
  н¨Á¢Ò»¸ösql svrÊý¾Ý¿â£¬Êý¾Ý¿âʵÌåÃûΪAisNew¡£½øÈë²éѯ·ÖÎöÆ÷£¬Ö´ÐÐÈçÏÂSQL£º
****************************************************
use AIS20030529181217
DECLARE @TbName VARCHAR(80)
DECLARE FindErrTable SCROLL CURSOR FOR 
  select name from AisNew.dbo. sysobjects where xtype=¡®u¡¯ order by name
OPEN FindErrTable
FETCH FindErrTable INTO  @TbName
  WHILE @@FETCH_STATUS<>-1
    BEGIN
          print  @TbName
          exec( ¡®select top 1 * from¡¯ +  @TbName)
          FETCH FindErrTable INTO  @TbName
    END
PRINT ¡®Scan Complate¡¡¯
CLOSE FindErrTable
DEALLOCATE FindErrTable
****************************************************
  Ö´ÐдËSQL¸ø³öµÄ±¨¸æµÄ×îºó¼¸ÐÐΪ£º
¡
T_voucher
·þÎñÆ÷: ÏûÏ¢ 644£¬¼¶±ð 21£¬×´Ì¬ 3£¬ÐÐ 1
δÄÜÔÚË÷ÒýÒ³ (1:29262) ÖÐÕÒµ½ RID ¡®161dd201a100¡¯ µÄË÷ÒýÌõÄ¿£¨Ë÷Òý ID 0£¬Êý¾Ý¿â ¡®AIS20030529181217¡¯£©¡£
Á¬½ÓÖжÏ
    ¸ù¾ÝÒÔÉϱ¨¸æ¿ÉÒÔÖªµÀ T_voucher ±íÔÚsysobjects±íÖеĶÔÓ¦¼Ç¼³ö´í£¬Ôì³ÉT_voucher²»ÄÜ·ÃÎÊ¡£ÐÞ¸ÄÉÏÃæµÄSQL:ÔÚÉùÃ÷ÓαêµÄ¼Ç¼¼¯ÖÐÆÁ±ÎT_voucher ±í¡£¼´£º
¡
DECLARE FindErrTable SCROLL CURSOR FOR 
select name from AisNew.dbo. sysobjects where xtype=¡®u¡¯ and name != ¡¯t_voucher¡¯
order by name
¡
    ÐÞ¸ÄÍê±Ï,¼ÌÐøÖ´ÐдËSQL¡£Èç´Ë·´¸´£¬¾ÍÄܹ»²»¶Ï±¨¸æ³ösysobjectsÖÐÄÇЩ±í²»ÄÜ·ÃÎÊ¡£
(1.2) µ¼ ¿â
      ÓÃSQL DTS¹¤¾ß½«AIS20030529181217ÖпÉÒÔ·ÃÎʵÄÊý¾Ý±íµ¼ÈëAisNew¡£
µÚ¶þ²½£º´¦Àí²»¿É·ÃÎʵÄÊý¾Ý±í£º
(2.1) ÕÒ³öϵͳ±íÖдíÎó¼Ç¼µÄID
»ñµÃAIS20030529181217ÖÐT_voucher±íÔÚsysobjectsÖеÄID £º
SELECT id FROM AIS20030529181217.dbo.sysobjects WHERE name=¡® t_voucher¡¯
==¡·123
( ˵Ã÷£ºÍ¨³£¼´Ê¹sysobjects±íË𻵣¬²»ÄÜ×ö select * from sysobjects ²éѯ£¬µ«ÊÇ¿ÉÒÔ×ö select ID,name from sysobjects ²éѯ¡£Èç¹ûselect ID,name from sysobjects ²éѯҲ²»ÄÜÖ´ÐУ¬¿ÉÒÔ¶ÔÕÕAisNewºÍAIS20030529181217Á½¸öÊý¾Ý¿âÖеÄͬÃû±í: syscolumns¡£¸ù¾ÝAisNew.dbo.syscolumns±íÖÐT_voucherËùÕ¼×ֶεĸöÊýÒÔ¼°¸÷¸ö×ֶεÄÃû³Æ£¬ÔÚAIS20030529181217.dbo.syscolumnsÖÐÕÒ³öT_voucherËù¶ÔÓ¦µÄ¼Ç¼£¬ÓÉ´Ë»ñµÃT_voucherÔÚAIS20030529181217Êý¾Ý¿âµÄϵͳ±íÖÐËù·ÖÅäµÄID¡£)
»ñµÃAisNewÖÐT_voucher±íÔÚsysobjectsÖеÄID £º
SELECT id FROM AisNew.dbo.sysobjects WHERE name=¡® t_voucher¡¯
==¡·456
(2.2) ɾ³ýAIS20030529181217ÖÐϵͳ±íÖдíÎó¼Ç¼£º
DELETE AIS20030529181217.dbo.sysobjects WHERE id=123
DELETE AIS20030529181217.dbo.sysindexes WHERE id=123
DELETE AIS20030529181217.dbo.syscolumns WHERE id=123
(2.3) Öؽ¨ÏµÍ³±í¼Ç¼
Öؽ¨AIS20030529181217.dbo.sysobjects±íÖÐT_voucher±í¶ÔÓ¦µÄ¼Ç¼£º
INSERT INTO AIS20030529181217.dbo.sysobjects
(name,id,xtype,uid,info,status,base_schema_ver,replinfo,parent_obj,crdate,ftcatid)
SELECT
¡®t_voucher_b¡¯,123,xtype,uid,info,status,base_schema_ver,replinfo,parent_obj,crdate,ftcatid    
FROM  AisNew.dbo. sysobjects WHERE id=456
Öؽ¨AIS20030529181217.dbo.sysindexes±íÖÐt_voucher±í¶ÔÓ¦µÄ¼Ç¼£º
INSERT INTO AIS20030529181217.dbo.sysindexes
(id,status,first,indid,root,minlen,keycnt,groupid,dpages,reserved,used,rowcnt,rowmodctr,reserved3,reserved4,xmaxlen,maxirow,OrigFillFactor,StatVersion,reserved2,FirstIAM,impid,lockflags,pgmodctr,keys,name,statblob) 
SELECT
123,status,first,indid,root,minlen,keycnt,groupid,dpages,reserved,used,rowcnt,rowmodctr,reserved3,reserved4,xmaxlen,maxirow,OrigFillFactor,StatVersion,reserved2,FirstIAM,impid,lockflags,pgmodctr,keys,name,statblob
FROM AisNew.dbo.sysindexes WHERE id=456
Öؽ¨AIS20030529181217.dbo.syscolumns±íÖÐt_voucher±í¶ÔÓ¦µÄ¼Ç¼£º
INSERT INTO AIS20030529181217.dbo.syscolumns
(name,id,xtype,typestat,xusertype,length,xprec,xscale,colid,xoffset,bitpos,reserved,colstat,cdefault,domain,number,colorderby,autoval,offset,collationid,language)
SELECT
name,123,xtype,typestat,xusertype,length,xprec,xscale,colid,xoffset,bitpos,reserved,colstat,cdefault,domain,number,colORDERBY,autoval,offset,collationid,language
FROM AisNew.dbo.syscolumns WHERE id=456
£¨2.4£©ÓÃDTSµ¥¶À½«t_voucher_b±íµ¼ÈëеÄDataBase
¾¹ýÒÔÉϲÙ×÷£¬AIS20030529181217ÖÐt_voucher_b ±íÓëÔt_voucher±í¹²ÓÃͬһID¡£
ÊÔÊÔ¿´¿É·ñÖ´ÐÐSELECT * FROM t_voucher_b ²éѯ ¡ª
Èç¹û¿ÉÒÔ£¬ÄÇôt_voucher_b¾ÍÒ»¶¨¼Ì³ÐÔt_voucher±íÖеÄÈ«²¿Êý¾Ý¡£ÔÙÓÃINSERT INTO AisNew.dbo.T_voucher FROM AIS20030529181217.dbo.t_voucher_b
»òDTS ½«t_voucher_bÖеÄÊý¾Ýµ¼ÈëAisNew¡£
  Èç¹ûÖ´ÐÐSELECT * FROM t_voucher_b ²éѯÈÔÈ»±¨´í£¬ÕâÕÅ±í³¹µ×ûϷÁË¡£
(2.5) ÆäËû¡°²»¿É·ÃÎʵÄÊý¾Ý±í¡±´¦Àí·½Ê½Í¬ÉÏ£¬Öظ´(2.1)~(2.4) ²½¡£
*******ÐÞ¸´ÏµÍ³±í******
USE zygl3_data
GO
SELECT au.allocation_unit_id, OBJECT_NAME(p.object_id) AS table_name, fg.name AS filegroup_name,
au.type_desc AS allocation_type, au.data_pages, partition_number
FROM sys.allocation_units AS au
JOIN sys.partitions AS p ON au.container_id = p.partition_id
JOIN sys.filegroups AS fg ON fg.data_space_id = au.data_space_id
WHERE au.allocation_unit_id = 72057594055098368 OR au.allocation_unit_id = 72057594055098368
ORDER BY au.allocation_unit_id
GO