Print ''
Print '-------------------------------------------------------------------------'
Print ' using Database...........: #DB_N#'
Print ' Executing SQL Script.....: JobMgr_62_DataBaseOptimice_ReorgDb.sql Script'
Print ' #New.....................: 22.03.2006'
Print ' #LUp.....................: 18.07.2025/A.Becker + J.Fes Optimi JF_DropIndicesOfTable'
Print '-------------------------------------------------------------------------'

 use [#DB_N#]
 declare @DateTimeStart datetime
 DECLARE @ExecuteSQLstr nvarchar(max)
 DECLARE @StepCurText nvarchar(max)

 print ('')
 print ('----------------------------------------------------------------------')
 Print ('DB Compress:#DB_N#')

 set @StepCurText='Step: del all Indices #DB_N#'
 set @DateTimeStart = GetDate()
 print ('......................................................................')
 Print (@StepCurText)

 --- #New: delete all Constraints
 print ('......................................................................')
 execute JF_DropDataBaseAllConstraints

--  execute JF_DropIndicesOfTable 'Objects_ObjectGroups_Rel_tbl'
--  execute JF_DropIndicesOfTable 'Objects_tbl'
--  execute JF_DropIndicesOfTable 'JobComputers_tbl'
--  execute JF_DropIndicesOfTable 'JobControl_ObjectsProcessData_tbl'
--  execute JF_DropIndicesOfTable 'JobControlRules_tbl'
--  execute JF_DropIndicesOfTable 'JobScript_tbl'
--  execute JF_DropIndicesOfTable 'Objects_Ir_Rel_tbl'
--  execute JF_DropIndicesOfTable 'ProcessGroups_tbl'
--  execute JF_DropIndicesOfTable 'Sites_tbl'
--  execute JF_DropIndicesOfTable 'Tasks_Objects_Rel_tbl'
--  execute JF_DropIndicesOfTable 'TaskScheduler_tbl'
--  execute JF_DropIndicesOfTable 'zzzzzDbMaintain_tbl'
--  execute JF_DropIndicesOfTable 'zzzzzDebug_tbl'

print ('......................................................................')
--- #Lup: 18.07.2025/A.Becker + J.Fes -  delete all indices
DECLARE @tableNames TABLE (Name SYSNAME)
DECLARE @tableName_c SYSNAME

INSERT INTO @tableNames (Name)
SELECT T.name
FROM sys.Tables T
WHERE T.schema_id=SCHEMA_ID('dbo') AND T.type='U'
  and name not in ('DrawingIndexingSearchFullText_tbl')
-- #Doc: 18.07.2025 not drop index for DrawingIndexingSearchFullText_tbl
ORDER BY T.name

WHILE EXISTS (SELECT 1 FROM @tableNames)
BEGIN
	SELECT TOP 1 @tableName_c=T.Name FROM @tableNames T
	select @ExecuteSQLstr='dbo.JF_DropIndicesOfTable ''' + @tableName_c + ''''
	 -- print (@ExecuteSQLstr)
  exec  (@ExecuteSQLstr)
	DELETE @tableNames WHERE Name=@tableName_c
END

 Execute JF_ShowTimeDiffToNow @StepCurText, @DateTimeStart
 set @DateTimeStart = GetDate()
 -- 30.08.2019/#toDo nutzen wenn max Daten deleted
 set @StepCurText='Step: DBCC SHRINKDATABASE 5% #DB_N#'
 print ('......................................................................')
 Print (@StepCurText)
 DBCC SHRINKDATABASE(N'#DB_N#', 5)
 Execute JF_ShowTimeDiffToNow @StepCurText, @DateTimeStart
ende:

GO
