Добрый день!
Существует ли информация о том, как удалить записи о событиях/авариях за опр. период из WWALMDB НЕ средствами Alarm DB Purge/Archive?
tech-note или мануал?
Генератор зла писал(а):Я просто удаляю из вьюера AlarmAndEvents (как то так, надо смотреть, а я дома) обычным Delete Select * Where условие
SET DATEFORMAT dmy
DELETE FROM [AlarmEvents]
WHERE AlarmEventTime < '18/10/2012 12:00:00'
Невозможно обновить представление или функцию "AlarmEvents", так как изменение влияет на несколько базовых таблиц.
CREATE VIEW AlarmEvents AS
SELECT AlarmDetail.EventStamp AS AlarmEventTime,
AlarmDetail.TransitionTimeZoneOffset AS AlarmEventTimeZoneOffset,
Comment.Comment AS Comment,
AlarmMaster.Tagname AS Tagname,
AlarmDetail.ValueString AS ValueString,
AlarmDetail.OperatorName AS OperatorName,
AlarmDetail.Priority AS AlarmEventPriority,
AlarmDetail.AlarmState AS AlarmEventState,
AlarmDetail.TransitionTime AS OriginStamp,
AlarmMaster.GroupName AS GroupName
FROM AlarmMaster INNER JOIN AlarmDetail ON
AlarmMaster.AlarmId = AlarmDetail.AlarmId
LEFT OUTER JOIN Comment ON AlarmDetail.CommentId = Comment.CommentId
--WHERE AlarmDetail.AlarmTransition <> 'ACK' AND AlarmDetail.ValueString <> 'OFF'
--ORDER BY AlarmDetail.TransitionTime
UNION ALL SELECT
Events.EventTime as EventStamp,
Events.EventTimeZoneOffset AS AlarmEventTimeZoneOffset,
Events.Comment as Comment,
Events.Tagname as Tagname,
Events.ValueString AS ValueString,
Events.OperatorName AS OperatorName,
Events.EventPriority AS Priority,
Events.EventState AS State,
Events.EventTime AS OriginStamp,
Events.GroupName AS GroupName
FROM Events
--where Events.ValueString<>'OFF'
--order by Events.EventTime
Генератор зла писал(а):Delete From dbo.AlarmConsolidated
Where AlarmTime <= DateAdd (dd, -30, GetDate())
USE [WWALMDB]
GO
--DELETE DUPLICATE DETAIL by Iodice Pierluigi
--low resurce need
if EXISTS (select * from sys.objects where name = 'TempAlarm')
drop table TempAlarm
GO
CREATE TABLE TempAlarm
(
ValidId int NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE TempAlarm ADD CONSTRAINT
PK_TempAlarm PRIMARY KEY CLUSTERED
(
ValidId
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
Insert INTO TempAlarm
Select MIN(alarmid) ValidId
from alarmmaster
group by TagName, OriginationTime
GO
declare @Seed int
declare @MinID int
declare @Step int
declare @MaxStep int
set @Seed = 1000
set @MinID = 0
set @Step =0
set @MaxStep = (select (MAX(validId) % @Seed)+1 from TempAlarm)
while (@Step <= @MaxStep)
BEGIN
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AlarmConsolidated]') AND type in (N'U'))
delete from AlarmConsolidated
where AlarmId between @MinID and (@MinID+@Seed) and AlarmId not in(select ValidId from TempAlarm)
;
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AlarmDetail]') AND type in (N'U'))
delete from AlarmDetail
where AlarmId between @MinID and (@MinID+@Seed) and AlarmId not in(select ValidId from TempAlarm)
;
DELETE FROM AlarmMaster
WHERE AlarmId between @MinID and (@MinID+@Seed) and AlarmID not in (select ValidId from TempAlarm)
;
set @MinID = @MinID + @Seed
set @Step = @Step +1
END
if EXISTS (select * from sys.objects where name = 'TempAlarm')
drop table TempAlarm
GO
NewOrdered писал(а):А что делать, если WWALMDB уже создана в Detailed Logging Mode?
Генератор зла писал(а):Поискать таблицу dbo.AlarmDetailed ?
skom писал(а):Я нашёл только скрипт удаления повторяющегося аларма:
Можно попробовать его переделать под твою задачу.
NewOrdered писал(а):Генератор зла писал(а):Delete From dbo.AlarmConsolidated
Where AlarmTime <= DateAdd (dd, -30, GetDate())
Спасибо.
А что делать, если WWALMDB уже создана в Detailed Logging Mode?
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 20