Autor Beitrag
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 22.12.05 01:04 
Moin,
gibt es eine Möglichkeit einen DELETE-Vorgang in einem BEFORE-DELETE-Trigger abzubrechen? Wenn ja, wie?
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Do 22.12.05 02:50 
Ich glaube nicht, daß das geht. Wozu auch ? Der Trigger beißt eben automatisch zu. Einbrecher : Hund beißt zu. Eigener Hund : Trigger beißt auch zu, dem ist das nämlich egal. :mrgreen: Siehe Generatoren. Selbes Prinzip. Ein Trigger ist ja nichts anderes als eine Stored Procedure und die muß für solche Fälle eben dann zusammengebaut werden.

_________________
Gruß
Hansa
UGrohne Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 22.12.05 04:23 
Wozu? Um bestimmte Dinge zu prüfen, von denen abhängig ist, ob der Datensatz gelöscht werden darf oder nicht. Und genau in dem Fall, wenn der Datensatz gar nicht gelöscht werden darf, suche ich nach einer Möglichkeit, den Löschvorgang abzubrechen ohne das in der Applikation machen zu müssen.
Und eine Prüfung über Foreign-Key-Constraints ist in diesem Fall nicht möglich.
Lemmy
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 792
Erhaltene Danke: 49

Windows 7 / 10; CentOS 7; LinuxMint
Delphi 7-XE10.1, VS 2015
BeitragVerfasst: Do 22.12.05 08:54 
Hi,

in dem Fall würde ich eher eine StoredProcedure einsetzen, dort ist ein Abbruch drin.

Lemmy
alex517
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 60


D7Ent, FB, FIBPlus
BeitragVerfasst: Do 22.12.05 08:54 
das geht.
Als Erstes eine EXCEPTION anlegen:
ausblenden SQL-Anweisung
1:
CREATE EXCEPTION EX_NICHT_LOESCHBAR 'EX_NICHT_LOESCHBAR'					


Und dann im Trigger auslösen:
ausblenden SQL-Anweisung
1:
2:
3:
4:
5:
6:
7:
CREATE TRIGGER MASTERTAB_BD0 FOR MASTERTAB
ACTIVE BEFORE DELETE POSITION 0
AS
begin
  if (EXISTS (SELECT * FROM DETAILTAB D WHERE D.MASTER_ID = OLD.ID)) then
    EXCEPTION EX_NICHT_LOESCHBAR 'Abhängige Daten vorhanden!';
end

alex
Lemmy
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 792
Erhaltene Danke: 49

Windows 7 / 10; CentOS 7; LinuxMint
Delphi 7-XE10.1, VS 2015
BeitragVerfasst: Do 22.12.05 13:36 
user profile iconalex517 hat folgendes geschrieben:
das geht.


Danke für den Hinweis!

Lemmy
UGrohne Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Do 22.12.05 21:04 
Perfekt, genau das wollte ich haben :D

Wieder ein Schritt in Richtung Fat-Database :)

Gibt es eigentlich eine Möglichkeit, diese Exception abzufangen, ohne dass sie von der Anwendung ausgelöst wird?