Tabellen mit doppelten RecIDs ermitteln

Wenn man in Dynamics AX (4.0 bzw. 2009) einmal in die Verlegenheit kommen sollte, prüfen zu müssen, ob es Tabellen mit doppelten RecIDs gibt, kann folgendes SQL-Script dabei behilflich sein:

use ax2009_standard_sp1

set nocount on

declare @tableName char(100)
declare db_cursor CURSOR FOR 
 select name from dbo.sysobjects
 where xtype = 'U'
 and name <> 'ROWSTAT'
 and name <> 'ROWSTATUS'
 and name <> 'SQLSYSTEMVARIABLES'
 and name <> 'SYSTEMSEQUENCES' -- SYSTEMSEQUENCES enthält immer doppelte RecIDs
 order by name asc

-- Temporäre Tabelle aufbauen
IF OBJECT_ID(N'tempdb..#tmp_duplrecid', N'U') IS NOT NULL
 begin
 drop table #tmp_duplrecid
 end

create table #tmp_duplrecid (tablename char(100), recordcounter bigint)   

OPEN db_cursor  
FETCH NEXT FROM db_cursor INTO @tableName  

WHILE @@FETCH_STATUS = 0  
 BEGIN  
  -- Tabellen mit doppelten RecIds ermitteln
  exec('insert into #tmp_duplrecid select ''' + @tableName + ''', COUNT(*)' +
    ' from ' + @tableName +
    ' group by RECID ' +
    ' having COUNT(*) > 1')
       
  FETCH NEXT FROM db_cursor INTO @tableName  
 END  

CLOSE db_cursor  
DEALLOCATE db_cursor

set nocount off

-- Tabellen mit doppelten RecIDs
select 'Tabelle enthält doppelte RecIDs: ' + tablename
from #tmp_duplrecid


 

Dieser Beitrag bezieht sich auf die Versionen:
Dynamics AX 4.0, Dynamics AX 2009

Kommentar hinzufügen
 
 

 

 
 
 
Beiträge des aktuellen Monats
Mai 2024
MoDiMiDoFrSaSo
 12345
6789101112
13141516171819
20212223242526
2728293031 
 
© 2006-2024 Heinz Schweda | Impressum | Kontakt | English version | Mobile Version
Diese Webseite verwendet Cookies, um Benutzern einen besseren Service anzubieten. Wenn Sie weiterhin auf der Seite bleiben, stimmen Sie der Verwendung von Cookies zu.  Mehr dazu