Connecting Tech Pros Worldwide Forums | Help | Site Map

zusammengesetzter Primary Key mit Deleted-Flag

SWE@kp
Guest
 
Posts: n/a
#1: Jul 20 '05
Knifflige Frage zu Datenbanken:

Es gibt Tabellen, die mehr als ein PK-Feld haben; also z.B.MAID und GMID.
Soweit ok.

Nehmen wir an, aus dieser Tabelle sollen keine Datensätze physikalisch
gelöscht werden, sondern der Löschstatus durch ein Datenfeld GELOESCHT
angegeben werden. Hat das Feld den Wert 0, dann ist der Datensatz nicht
gelöscht; ansonsten steht der Zeitpunkt (Tag und Uhrzeit) der Löschung drin.
Dann funktioniert der PK nicht mehr, denn es können ja durchaus mehrere
Datensätze mit gleicher MAID und GMID vorhanden sein. Aufnehmen von
GELOESCHT in den PK geht theoretisch, ist aber gefährlich (da
Fließkommafeld, und wer weiß schon, ob 0 immer gleich 0 ist...).

Hat jemand eine Idee?

SWE@KP

Heiko Luettge
Guest
 
Posts: n/a
#2: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag



ändere den prim key auf ein surrogate, der nichts mit den Daten zu tun hat
z.B. id integer not null

MAID und GMID sind dann 2 normale Felder

[color=blue]
> Es gibt Tabellen, die mehr als ein PK-Feld haben; also z.B.MAID und GMID.
> Soweit ok.[/color]

ebend nicht ;)
[color=blue]
> Nehmen wir an, aus dieser Tabelle sollen keine Datensätze physikalisch
> gelöscht werden, sondern der Löschstatus durch ein Datenfeld GELOESCHT
> angegeben werden. Hat das Feld den Wert 0, dann ist der Datensatz nicht
> gelöscht; ansonsten steht der Zeitpunkt (Tag und Uhrzeit) der Löschung[/color]
drin.[color=blue]
> Dann funktioniert der PK nicht mehr, denn es können ja durchaus mehrere
> Datensätze mit gleicher MAID und GMID vorhanden sein. Aufnehmen von
> GELOESCHT in den PK geht theoretisch, ist aber gefährlich (da
> Fließkommafeld, und wer weiß schon, ob 0 immer gleich 0 ist...).
>[/color]

0 muss ja nicht Fließkomma sein, sondern kann auch Char oder Smallint sein.

Heiko


Marian Aldenhoevel
Guest
 
Posts: n/a
#3: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


Hallo,
[color=blue]
> Aufnehmen von GELOESCHT in den PK geht theoretisch, ist
> aber gefährlich.[/color]
[color=blue]
> und wer weiß schon, ob 0 immer gleich 0 ist...).[/color]

0 ist in allen mir bekannten Fließkommaformaten exakt darstellbar,
und damit ist 0 immer gleich 0. Also kannst Du das ruhig mit
in den PK aufnehmen.

Aber ist das trotzdem eindeutig? Wenn Du die Serverzeit einsetzt
und nicht die potentiell abweichende vom Client, dann sollte das
gegeben sein, denn "gleichzeitig" löschen können keine zwei
Clients. Bleibt das Problem der begrenzten zeitlichen Auflösung
so eines Zeitstempels, und ob Du mit dem Risiko leben kannst und
willst, musst Du selbst überlegen.
[color=blue]
> Hat jemand eine Idee?[/color]

Standardantwort: Gibt es kein Feld im Datenmodell, das
zweifelsfrei als PK dienen kann, dann fügst Du einfach eines
hinzu. Generator dazu, BEFORE INSERT-Trigger drauf und
vergessen.

Ciao, MM
--
Rosenhain 23, 53123 Bonn - Fon +49 228 6203366, Fax +49 228 624031
www.marian-aldenhoevel.de
"Früher tauschte man Frauen gegen Ziegen, das war was
Handfestes" - D. Nuhr

Immo Landwerth
Guest
 
Posts: n/a
#4: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


Marian Aldenhoevel wrote:
[color=blue]
> Standardantwort: Gibt es kein Feld im Datenmodell, das
> zweifelsfrei als PK dienen kann, dann fügst Du einfach eines
> hinzu. Generator dazu, BEFORE INSERT-Trigger drauf und
> vergessen.[/color]

Was immer der Fall sein sollte, da man in nahezu allen Fällen zweifeln
muss... :)

--
Immo Landwerth - XP Pro SP1 - D5 Pro UP 1 - XanaNews 1.15.7.2
Marian Aldenhoevel
Guest
 
Posts: n/a
#5: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


Hallo,
[color=blue]
> Was immer der Fall sein sollte, da man in nahezu allen Fällen zweifeln
> muss... :)[/color]

Es gibt schon typische PK-geeignete "echte" Datenfelder. Jedenfalls was
die Eindeutigkeit innerhalb der Tabelle angeht. Zum Beispiel Ausweis-
oder Matrikelnummern. Bestellnummern innerhalb eines Katalogs,
Rechnungsnummern et al..

Aber es gibt natürlich auch noch andere Kriterien neben der
Eindeutigkeit des Merkmals in der richtigen Welt:

- Jeder Datensatz muss eines davon haben. Mit Matrikelnummern als
PK kann man nur Studenten erfassen.

- Das Merkmal sollte sich möglichst während der ganzen Lebensdauer
eines Datensatzes nie mehr ändern.

Weil die letzte Anforderung ein typischer Kandidat für eine Aufweichung
während der Entwicklungsgeschichte der Datenbank/Anwendung ist, neige
ich aber auch dazu, einfach mal prophylaktisch jedem Datensatz eine
Nummer mitzugeben, die mit der richtigen Welt nichts zu tun hat und nur
innerhalb der Datenbank Verwendung findet.

Ciao, MM
--
Rosenhain 23, 53123 Bonn - Fon +49 228 6203366, Fax +49 228 624031
www.marian-aldenhoevel.de
"Früher tauschte man Frauen gegen Ziegen, das war was
Handfestes" - D. Nuhr

Dieter Nöth
Guest
 
Posts: n/a
#6: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


SWE@kp wrote:
[color=blue]
> Es gibt Tabellen, die mehr als ein PK-Feld haben; also z.B.MAID und GMID.
> Soweit ok.
>
> Nehmen wir an, aus dieser Tabelle sollen keine Datensätze physikalisch
> gelöscht werden, sondern der Löschstatus durch ein Datenfeld GELOESCHT
> angegeben werden. Hat das Feld den Wert 0, dann ist der Datensatz nicht
> gelöscht; ansonsten steht der Zeitpunkt (Tag und Uhrzeit) der Löschung drin.
> Dann funktioniert der PK nicht mehr, denn es können ja durchaus mehrere
> Datensätze mit gleicher MAID und GMID vorhanden sein.[/color]

Wieso? Du willst doch nicht etwa MAID und GMID wiederverwenden?
[color=blue]
> Aufnehmen von
> GELOESCHT in den PK geht theoretisch, ist aber gefährlich (da
> Fließkommafeld, und wer weiß schon, ob 0 immer gleich 0 ist...).[/color]

Wieso FLOAT? Ich denke, das ist ein Timestamp? Und dann nimmst du
entweder NULL für nicht gelöscht oder ein Datum in ferner Zukunft, z.B.
9999-12-31.

Dieter

Immo Landwerth
Guest
 
Posts: n/a
#7: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


Marian Aldenhoevel wrote:
[color=blue]
> Hallo,
>[color=green]
> > Was immer der Fall sein sollte, da man in nahezu allen Fällen
> > zweifeln muss... :)[/color]
>
> Es gibt schon typische PK-geeignete "echte" Datenfelder. Jedenfalls
> was die Eindeutigkeit innerhalb der Tabelle angeht. Zum Beispiel
> Ausweis- oder Matrikelnummern. Bestellnummern innerhalb eines
> Katalogs, Rechnungsnummern et al..[/color]

Das Problem liegt häufig nicht in der Eindeutigkeit des Feldes selbst,
sondern im Datenmodel begründet. Der Kunde möchte z.B. plötzlich auch
ausländische Personen erfassen, die eine andere Ausweisnummer haben und
wofür das Feld "AUSWEISNUMMER" leerzulassen ist. PK Felder dürfen
bekanntermaßen aber nicht NULL sein.
[color=blue]
> - Jeder Datensatz muss eines davon haben. Mit Matrikelnummern als
> PK kann man nur Studenten erfassen.[/color]

Bingo. S.o.
[color=blue]
> - Das Merkmal sollte sich möglichst während der ganzen Lebensdauer
> eines Datensatzes nie mehr ändern.[/color]

Bei einigen Datenbanken kann man sogar von "sollte sich möglichst"
durch "darf/kann sich nicht" ersetzen.

Die Probleme, die eine Änderung des PK mit sich bringen sind so groß,
dass ich dem erhöhten Initialaufwand durch generierte PKs lieber
Rechnung trage, als eine Änderung von vorhandenen (Detail-) Datensätzen.
[color=blue]
> Weil die letzte Anforderung ein typischer Kandidat für eine
> Aufweichung während der Entwicklungsgeschichte der
> Datenbank/Anwendung ist, neige ich aber auch dazu, einfach mal
> prophylaktisch jedem Datensatz eine Nummer mitzugeben, die mit der
> richtigen Welt nichts zu tun hat und nur innerhalb der Datenbank
> Verwendung findet.[/color]

Ja, genauso meinte ich das: Auch wenn man wirklich zu wissen glaubt,
dass Feld XY eindeutig ist, sollte man deennoch nur einen UNIQUE INDEX
drauflegen und einen generierten (künsltichen) Wert als PK verwenden.
Dieses Feld ist im Frontend nicht sichtbar, was die Wahrscheinlichkeit,
dass der Kunde in diesem Berich Änderungen wünscht, gegen 0 gehen lässt.

Fazit: Wann immer es geht, nur generierte Felder als PK verwenden.

--
Immo Landwerth - XP Pro SP1 - D5 Pro UP 1 - XanaNews 1.15.7.2
Stefan Menten
Guest
 
Posts: n/a
#8: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


Ist das nicht eher ein logisches Problem?

MAID, GMID und gelöscht stellen den PK dar.

Der erste Datensatz wird gelöscht.

Dann kommt ein neuer mit gleicher MAID und GMID aber nicht gelöscht.

Wenn der dann auch gelöscht wird, hast Du ein Problem.

Daraus folgt: MAID, GMID und gelöscht sind nicht der PK. Die Tabelle braucht
einen eigenen eindeutigen PK!


Viele Grüße

Stefan



"SWE@kp" <swe@klages-partner.de> schrieb im Newsbeitrag
news:2f5e5c00.0310012223.6056fbe2@posting.google.c om...[color=blue]
> Knifflige Frage zu Datenbanken:
>
> Es gibt Tabellen, die mehr als ein PK-Feld haben; also z.B.MAID und GMID.
> Soweit ok.
>
> Nehmen wir an, aus dieser Tabelle sollen keine Datensätze physikalisch
> gelöscht werden, sondern der Löschstatus durch ein Datenfeld GELOESCHT
> angegeben werden. Hat das Feld den Wert 0, dann ist der Datensatz nicht
> gelöscht; ansonsten steht der Zeitpunkt (Tag und Uhrzeit) der Löschung[/color]
drin.[color=blue]
> Dann funktioniert der PK nicht mehr, denn es können ja durchaus mehrere
> Datensätze mit gleicher MAID und GMID vorhanden sein. Aufnehmen von
> GELOESCHT in den PK geht theoretisch, ist aber gefährlich (da
> Fließkommafeld, und wer weiß schon, ob 0 immer gleich 0 ist...).
>
> Hat jemand eine Idee?
>
> SWE@KP[/color]


ben brugman
Guest
 
Posts: n/a
#9: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


Hello all stakeholders,

My German is worse than my English so I am going with English.
(This is a long anwser, I do appreciate respons and if there are
questions please ask. I have a view of what a Datamodel (logical)
and a implementation of a Datamodel=Databasemodel (fairly fysical)
is. This view I have may be unfamilliar to you or you might not
agree with this view).

I like to split the problem into two different 'fases', that of
datamodel and that of implementation into a database (databasemodel).

DATAMODEL
Requirements are a table were MAID and GMID are the 'logical' PK.
But a tuple can be deleted, were we want to keep the data, but need
an indication that the tuple was deleted and when the tuple was deleted.

Suppose that there is a 'child' table which has a relation with the table
over the MAID and GMID PK. (Two different situations can exist the
child table can not contain children of deleted 'parents', or the child
table can contain children of deleted 'parents'.)
I do not know if your situation includes such a table.

The deleted tuples can be seen as historical tuples, to be kept.
This can be modeled as a sepparate table.
This can also be modeled with extra information within the tuple.
(A deleted indication or a deleted date or both).

So the modelling of this table can be one table or an actual table
and a historical table.
(THIS IS STILL ONLY THE MODEL AND NOT THE IMPLEMENTATION).
Depending on the way the information is viewed on or the other can
prevail.

NOW TOWARD THE IMPLEMENTATION. (dataBASEmodel).
This should implement all the rules given in the datamodel fase, but
how to implement this is still a 'free' choice.
Here we can implement the model as it is, but independed of the model
one can choose for the one table or two table implementations.
(If we still have the choice here, why do we need a model ? The model
describes what we need these needs have to be implemented, the model
should help to make the choices not make the decisions).

If implemented as TWO tables, selection on actual information is easy,
selection on historical information is ease. Selection on both can
be done with a union.
With two tables the relation between the children and the parent.
Easiest to enforce deleted parents can not have children.
Second option deleted parents can only have deleted children also
in a historical children table.
Nasty implementation both the actual parents and deleted parents
can have children in the one children table. This is not a nice
implementation.

If implemented in ONE table. Extra columns are needed and the PK has te
be extended with some historical info. First we should avoid NULLs because
they are not nice in PK's and not nice in relationships. (This is an
understatement).
So if you have a deleted indication use at least two values one for not
deleted one
for deleted.
Datetime fields or stamps, personaly I think that time is continuous and
therefore
not suetable as a PK or other identification, but if the datetime is rounded
to say
days, seconds or milliseconds it can be made suetable for identification.
But then a a choice MUST be made how it is rounded example days or seconds.
If there is only one deleted tuple for each MAID and GMID than use the
identification. If there are more I would go for a version (automatically or
not) and one could define the highest as actual, but maybe it would be
better to define zero (Not null) as actual and keep the higher numbers
as historical. A fixed number zero (or any other number) for the actual
tuple makes selection easier.

Children.
If deleted tuples can have children the deleted indication or version should
be incorperated in the relational key. This makes updating difficult.
Because
both can not be updated in one go or defered checking has to be used.
(Defered checking has limitations and should if possible not be used).
(A write and delete cyclus is possible, first make a historical parent,
then move the children then delete the first parent).

If children are not allowed on deleted tuples they should be deleted before
a parent can be deleted (with the deleted signaling).
Problem the if only the MAID and GMID are checked, the database can not
enforce this rule. So applications should enforce this rule.
(Problem with applications enforcing rules that checking for children and
then
deleting the parent, another process can in the mainwhile add a new child.
Oracle does not do any predicate locking so this insert can not be blocked.)
One could include the actual indication in the relation. Then at least
during
a concurrency conflict at least one transaction will fail.)

If there are specific requirements that the solution should be ONE or TWO
tables,
one can also revert to VIEWS to make this available. And remember ONE or TWO
table implementation can be INDEPENDEND of ONE or TWO table models.
Depending on the functional requirements the model should have one or two
tables.
Depending on the model and nonfunctional requirements this should be
implemented
as one or two tables. (Which queries are done how offten, how many tuples
(actual
and deleted) and how fast should the queries and the updates be).

General filosofie :
First there should be a Datamodel to describe what we want.
Then a DataBaseModel should be made from this and be implemented.
(At this point some decisions have to be made which rules will be enforced
by the RDBMS and which rules have to be enforced by business logic.)
After this the business logic can be build.

If there are questions of which things are allowed (combinations of data)
one should look at the databasemodel. (The database model and functional
model (or design) should be able to anwser all the questions of what is
functionaly allowed).
If there are questions of how to interface with the RDBMS one should
look at the Databasemodel.
The RDBMS and business logic togethere should implement all the
constraints 'dictated' by the databasemodel.

If you are still there, thanks for your attention,


ben brugman.



"SWE@kp" <swe@klages-partner.de> wrote in message
news:2f5e5c00.0310012223.6056fbe2@posting.google.c om...[color=blue]
> Knifflige Frage zu Datenbanken:
>
> Es gibt Tabellen, die mehr als ein PK-Feld haben; also z.B.MAID und GMID.
> Soweit ok.
>
> Nehmen wir an, aus dieser Tabelle sollen keine Datensätze physikalisch
> gelöscht werden, sondern der Löschstatus durch ein Datenfeld GELOESCHT
> angegeben werden. Hat das Feld den Wert 0, dann ist der Datensatz nicht
> gelöscht; ansonsten steht der Zeitpunkt (Tag und Uhrzeit) der Löschung[/color]
drin.[color=blue]
> Dann funktioniert der PK nicht mehr, denn es können ja durchaus mehrere
> Datensätze mit gleicher MAID und GMID vorhanden sein. Aufnehmen von
> GELOESCHT in den PK geht theoretisch, ist aber gefährlich (da
> Fließkommafeld, und wer weiß schon, ob 0 immer gleich 0 ist...).
>
> Hat jemand eine Idee?
>
> SWE@KP[/color]


Alkos
Guest
 
Posts: n/a
#10: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


What is the question, please ?
(I also hope you are trying to design your DB with Oracle ;)

Alkos

"ben brugman" <ben@niethier.nl> a écrit dans le message news:
3fa256a3$0$279$4d4ebb8e@read.news.nl.uu.net...[color=blue]
> Hello all stakeholders,
>
> My German is worse than my English so I am going with English.
> (This is a long anwser, I do appreciate respons and if there are
> questions please ask. I have a view of what a Datamodel (logical)
> and a implementation of a Datamodel=Databasemodel (fairly fysical)
> is. This view I have may be unfamilliar to you or you might not
> agree with this view).
>
> I like to split the problem into two different 'fases', that of
> datamodel and that of implementation into a database (databasemodel).
>
> DATAMODEL
> Requirements are a table were MAID and GMID are the 'logical' PK.
> But a tuple can be deleted, were we want to keep the data, but need
> an indication that the tuple was deleted and when the tuple was deleted.
>
> Suppose that there is a 'child' table which has a relation with the table
> over the MAID and GMID PK. (Two different situations can exist the
> child table can not contain children of deleted 'parents', or the child
> table can contain children of deleted 'parents'.)
> I do not know if your situation includes such a table.
>
> The deleted tuples can be seen as historical tuples, to be kept.
> This can be modeled as a sepparate table.
> This can also be modeled with extra information within the tuple.
> (A deleted indication or a deleted date or both).
>
> So the modelling of this table can be one table or an actual table
> and a historical table.
> (THIS IS STILL ONLY THE MODEL AND NOT THE IMPLEMENTATION).
> Depending on the way the information is viewed on or the other can
> prevail.
>
> NOW TOWARD THE IMPLEMENTATION. (dataBASEmodel).
> This should implement all the rules given in the datamodel fase, but
> how to implement this is still a 'free' choice.
> Here we can implement the model as it is, but independed of the model
> one can choose for the one table or two table implementations.
> (If we still have the choice here, why do we need a model ? The model
> describes what we need these needs have to be implemented, the model
> should help to make the choices not make the decisions).
>
> If implemented as TWO tables, selection on actual information is easy,
> selection on historical information is ease. Selection on both can
> be done with a union.
> With two tables the relation between the children and the parent.
> Easiest to enforce deleted parents can not have children.
> Second option deleted parents can only have deleted children also
> in a historical children table.
> Nasty implementation both the actual parents and deleted parents
> can have children in the one children table. This is not a nice
> implementation.
>
> If implemented in ONE table. Extra columns are needed and the PK has te
> be extended with some historical info. First we should avoid NULLs because
> they are not nice in PK's and not nice in relationships. (This is an
> understatement).
> So if you have a deleted indication use at least two values one for not
> deleted one
> for deleted.
> Datetime fields or stamps, personaly I think that time is continuous and
> therefore
> not suetable as a PK or other identification, but if the datetime is[/color]
rounded[color=blue]
> to say
> days, seconds or milliseconds it can be made suetable for identification.
> But then a a choice MUST be made how it is rounded example days or[/color]
seconds.[color=blue]
> If there is only one deleted tuple for each MAID and GMID than use the
> identification. If there are more I would go for a version (automatically[/color]
or[color=blue]
> not) and one could define the highest as actual, but maybe it would be
> better to define zero (Not null) as actual and keep the higher numbers
> as historical. A fixed number zero (or any other number) for the actual
> tuple makes selection easier.
>
> Children.
> If deleted tuples can have children the deleted indication or version[/color]
should[color=blue]
> be incorperated in the relational key. This makes updating difficult.
> Because
> both can not be updated in one go or defered checking has to be used.
> (Defered checking has limitations and should if possible not be used).
> (A write and delete cyclus is possible, first make a historical parent,
> then move the children then delete the first parent).
>
> If children are not allowed on deleted tuples they should be deleted[/color]
before[color=blue]
> a parent can be deleted (with the deleted signaling).
> Problem the if only the MAID and GMID are checked, the database can not
> enforce this rule. So applications should enforce this rule.
> (Problem with applications enforcing rules that checking for children and
> then
> deleting the parent, another process can in the mainwhile add a new child.
> Oracle does not do any predicate locking so this insert can not be[/color]
blocked.)[color=blue]
> One could include the actual indication in the relation. Then at least
> during
> a concurrency conflict at least one transaction will fail.)
>
> If there are specific requirements that the solution should be ONE or TWO
> tables,
> one can also revert to VIEWS to make this available. And remember ONE or[/color]
TWO[color=blue]
> table implementation can be INDEPENDEND of ONE or TWO table models.
> Depending on the functional requirements the model should have one or two
> tables.
> Depending on the model and nonfunctional requirements this should be
> implemented
> as one or two tables. (Which queries are done how offten, how many tuples
> (actual
> and deleted) and how fast should the queries and the updates be).
>
> General filosofie :
> First there should be a Datamodel to describe what we want.
> Then a DataBaseModel should be made from this and be implemented.
> (At this point some decisions have to be made which rules will be enforced
> by the RDBMS and which rules have to be enforced by business logic.)
> After this the business logic can be build.
>
> If there are questions of which things are allowed (combinations of data)
> one should look at the databasemodel. (The database model and functional
> model (or design) should be able to anwser all the questions of what is
> functionaly allowed).
> If there are questions of how to interface with the RDBMS one should
> look at the Databasemodel.
> The RDBMS and business logic togethere should implement all the
> constraints 'dictated' by the databasemodel.
>
> If you are still there, thanks for your attention,
>
>
> ben brugman.
>
>
>
> "SWE@kp" <swe@klages-partner.de> wrote in message
> news:2f5e5c00.0310012223.6056fbe2@posting.google.c om...[color=green]
> > Knifflige Frage zu Datenbanken:
> >
> > Es gibt Tabellen, die mehr als ein PK-Feld haben; also z.B.MAID und[/color][/color]
GMID.[color=blue][color=green]
> > Soweit ok.
> >
> > Nehmen wir an, aus dieser Tabelle sollen keine Datensätze physikalisch
> > gelöscht werden, sondern der Löschstatus durch ein Datenfeld GELOESCHT
> > angegeben werden. Hat das Feld den Wert 0, dann ist der Datensatz nicht
> > gelöscht; ansonsten steht der Zeitpunkt (Tag und Uhrzeit) der Löschung[/color]
> drin.[color=green]
> > Dann funktioniert der PK nicht mehr, denn es können ja durchaus mehrere
> > Datensätze mit gleicher MAID und GMID vorhanden sein. Aufnehmen von
> > GELOESCHT in den PK geht theoretisch, ist aber gefährlich (da
> > Fließkommafeld, und wer weiß schon, ob 0 immer gleich 0 ist...).
> >
> > Hat jemand eine Idee?
> >
> > SWE@KP[/color]
>
>[/color]


ben brugman
Guest
 
Posts: n/a
#11: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


Roughly translated. (very Rougly ?).
"
A table PK fields MAID and GMID.
Tuples are deleted but not removed from the table.
There is a field GELOESCHT (REMOVED).
A 0 (I think a NULL) in this means not removed a datetime
gives the time when this tuple is removed.
Using this then the PK doesn't work anymore because including
these removed fields there can be more than one MAID and GMID
combination.
Adding the GELOESCHT field to the PK doesn't work because
this gives trouble with a ???floatfield???(=Fließkommafeld) and
is a 0 equal to a 0 ?? (I think a NULL equal to a NULL).

Does anybody have an Idee ?
"

The anwser I have given is more extended than the request.
I did elaborate with datamodel and databasemodel fase, to
get above table what the problem was and included a table
which has referential constriants with the table.
This because to 'solve' the problem one has to know exactly
wat it is to be used for. (Hense the datamodel).
And how this can be solved. (Hence the databasemodel).

ben brugman.



"Alkos" <azerty@nospam.org> wrote in message
news:bnto9p$m861@news.rd.francetelecom.fr...[color=blue]
> What is the question, please ?
> (I also hope you are trying to design your DB with Oracle ;)
>
> Alkos
>
> "ben brugman" <ben@niethier.nl> a écrit dans le message news:
> 3fa256a3$0$279$4d4ebb8e@read.news.nl.uu.net...[color=green]
> > Hello all stakeholders,
> >
> > My German is worse than my English so I am going with English.
> > (This is a long anwser, I do appreciate respons and if there are
> > questions please ask. I have a view of what a Datamodel (logical)
> > and a implementation of a Datamodel=Databasemodel (fairly fysical)
> > is. This view I have may be unfamilliar to you or you might not
> > agree with this view).
> >
> > I like to split the problem into two different 'fases', that of
> > datamodel and that of implementation into a database (databasemodel).
> >
> > DATAMODEL
> > Requirements are a table were MAID and GMID are the 'logical' PK.
> > But a tuple can be deleted, were we want to keep the data, but need
> > an indication that the tuple was deleted and when the tuple was deleted.
> >
> > Suppose that there is a 'child' table which has a relation with the[/color][/color]
table[color=blue][color=green]
> > over the MAID and GMID PK. (Two different situations can exist the
> > child table can not contain children of deleted 'parents', or the child
> > table can contain children of deleted 'parents'.)
> > I do not know if your situation includes such a table.
> >
> > The deleted tuples can be seen as historical tuples, to be kept.
> > This can be modeled as a sepparate table.
> > This can also be modeled with extra information within the tuple.
> > (A deleted indication or a deleted date or both).
> >
> > So the modelling of this table can be one table or an actual table
> > and a historical table.
> > (THIS IS STILL ONLY THE MODEL AND NOT THE IMPLEMENTATION).
> > Depending on the way the information is viewed on or the other can
> > prevail.
> >
> > NOW TOWARD THE IMPLEMENTATION. (dataBASEmodel).
> > This should implement all the rules given in the datamodel fase, but
> > how to implement this is still a 'free' choice.
> > Here we can implement the model as it is, but independed of the model
> > one can choose for the one table or two table implementations.
> > (If we still have the choice here, why do we need a model ? The model
> > describes what we need these needs have to be implemented, the model
> > should help to make the choices not make the decisions).
> >
> > If implemented as TWO tables, selection on actual information is easy,
> > selection on historical information is ease. Selection on both can
> > be done with a union.
> > With two tables the relation between the children and the parent.
> > Easiest to enforce deleted parents can not have children.
> > Second option deleted parents can only have deleted children also
> > in a historical children table.
> > Nasty implementation both the actual parents and deleted parents
> > can have children in the one children table. This is not a nice
> > implementation.
> >
> > If implemented in ONE table. Extra columns are needed and the PK has te
> > be extended with some historical info. First we should avoid NULLs[/color][/color]
because[color=blue][color=green]
> > they are not nice in PK's and not nice in relationships. (This is an
> > understatement).
> > So if you have a deleted indication use at least two values one for not
> > deleted one
> > for deleted.
> > Datetime fields or stamps, personaly I think that time is continuous and
> > therefore
> > not suetable as a PK or other identification, but if the datetime is[/color]
> rounded[color=green]
> > to say
> > days, seconds or milliseconds it can be made suetable for[/color][/color]
identification.[color=blue][color=green]
> > But then a a choice MUST be made how it is rounded example days or[/color]
> seconds.[color=green]
> > If there is only one deleted tuple for each MAID and GMID than use the
> > identification. If there are more I would go for a version[/color][/color]
(automatically[color=blue]
> or[color=green]
> > not) and one could define the highest as actual, but maybe it would be
> > better to define zero (Not null) as actual and keep the higher numbers
> > as historical. A fixed number zero (or any other number) for the actual
> > tuple makes selection easier.
> >
> > Children.
> > If deleted tuples can have children the deleted indication or version[/color]
> should[color=green]
> > be incorperated in the relational key. This makes updating difficult.
> > Because
> > both can not be updated in one go or defered checking has to be used.
> > (Defered checking has limitations and should if possible not be used).
> > (A write and delete cyclus is possible, first make a historical parent,
> > then move the children then delete the first parent).
> >
> > If children are not allowed on deleted tuples they should be deleted[/color]
> before[color=green]
> > a parent can be deleted (with the deleted signaling).
> > Problem the if only the MAID and GMID are checked, the database can not
> > enforce this rule. So applications should enforce this rule.
> > (Problem with applications enforcing rules that checking for children[/color][/color]
and[color=blue][color=green]
> > then
> > deleting the parent, another process can in the mainwhile add a new[/color][/color]
child.[color=blue][color=green]
> > Oracle does not do any predicate locking so this insert can not be[/color]
> blocked.)[color=green]
> > One could include the actual indication in the relation. Then at least
> > during
> > a concurrency conflict at least one transaction will fail.)
> >
> > If there are specific requirements that the solution should be ONE or[/color][/color]
TWO[color=blue][color=green]
> > tables,
> > one can also revert to VIEWS to make this available. And remember ONE or[/color]
> TWO[color=green]
> > table implementation can be INDEPENDEND of ONE or TWO table models.
> > Depending on the functional requirements the model should have one or[/color][/color]
two[color=blue][color=green]
> > tables.
> > Depending on the model and nonfunctional requirements this should be
> > implemented
> > as one or two tables. (Which queries are done how offten, how many[/color][/color]
tuples[color=blue][color=green]
> > (actual
> > and deleted) and how fast should the queries and the updates be).
> >
> > General filosofie :
> > First there should be a Datamodel to describe what we want.
> > Then a DataBaseModel should be made from this and be implemented.
> > (At this point some decisions have to be made which rules will be[/color][/color]
enforced[color=blue][color=green]
> > by the RDBMS and which rules have to be enforced by business logic.)
> > After this the business logic can be build.
> >
> > If there are questions of which things are allowed (combinations of[/color][/color]
data)[color=blue][color=green]
> > one should look at the databasemodel. (The database model and functional
> > model (or design) should be able to anwser all the questions of what is
> > functionaly allowed).
> > If there are questions of how to interface with the RDBMS one should
> > look at the Databasemodel.
> > The RDBMS and business logic togethere should implement all the
> > constraints 'dictated' by the databasemodel.
> >
> > If you are still there, thanks for your attention,
> >
> >
> > ben brugman.
> >
> >
> >
> > "SWE@kp" <swe@klages-partner.de> wrote in message
> > news:2f5e5c00.0310012223.6056fbe2@posting.google.c om...[color=darkred]
> > > Knifflige Frage zu Datenbanken:
> > >
> > > Es gibt Tabellen, die mehr als ein PK-Feld haben; also z.B.MAID und[/color][/color]
> GMID.[color=green][color=darkred]
> > > Soweit ok.
> > >
> > > Nehmen wir an, aus dieser Tabelle sollen keine Datensätze physikalisch
> > > gelöscht werden, sondern der Löschstatus durch ein Datenfeld GELOESCHT
> > > angegeben werden. Hat das Feld den Wert 0, dann ist der Datensatz[/color][/color][/color]
nicht[color=blue][color=green][color=darkred]
> > > gelöscht; ansonsten steht der Zeitpunkt (Tag und Uhrzeit) der Löschung[/color]
> > drin.[color=darkred]
> > > Dann funktioniert der PK nicht mehr, denn es können ja durchaus[/color][/color][/color]
mehrere[color=blue][color=green][color=darkred]
> > > Datensätze mit gleicher MAID und GMID vorhanden sein. Aufnehmen von
> > > GELOESCHT in den PK geht theoretisch, ist aber gefährlich (da
> > > Fließkommafeld, und wer weiß schon, ob 0 immer gleich 0 ist...).
> > >
> > > Hat jemand eine Idee?
> > >
> > > SWE@KP[/color]
> >
> >[/color]
>
>[/color]


ben brugman
Guest
 
Posts: n/a
#12: Jul 20 '05

re: zusammengesetzter Primary Key mit Deleted-Flag


[color=blue]
> (I also hope you are trying to design your DB with Oracle ;)[/color]
No.
[color=blue]
>
> Alkos[/color]

With Oracle Designer you can design DB's.

With Oracle you can implement DB's. (Databasemodel).

But the designing process can be done with a great number
of tools (pen and paper for one). Also designing the
databasemodel can be done with a great number of tools
(pen and paper for one).

The designing process should be at least for a great deal
be independend of the database where you implement
the database. Because of RDBMS differences and
performance one can make different implementations
on different RDBMSsen. So although an RDBMS (Oracle)
for example can be in the back op your mind during the
design fase, it should not have to much influence.

When designing try to make the 'design' as generic
as possible. A design which can be implemented in
multiple different RDBMSsen is 'stronger' than a
dedicated design.
(The world is not completely ideal, so some parts of
the design are dependend on the database you are
actually going to use. There are differences in
concurrency model, in grouping of records (think iot and clustering),
in sequencing, some of these should be taken into the
designing process at an early stage.
So when possible try to be independend of an RDBMS but when
neccesary take the RDBMS into account)

ben brugman


Closed Thread