473,511 Members | 15,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

zusammengesetzter Primary Key mit Deleted-Flag

SWE
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
Jul 20 '05 #1
11 4589

ä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

Es gibt Tabellen, die mehr als ein PK-Feld haben; also z.B.MAID und GMID.
Soweit ok.
ebend nicht ;)
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...).


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

Heiko
Jul 20 '05 #2
Hallo,
Aufnehmen von GELOESCHT in den PK geht theoretisch, ist
aber gefährlich. und wer weiß schon, ob 0 immer gleich 0 ist...).
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.
Hat jemand eine Idee?


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

Jul 20 '05 #3
Marian Aldenhoevel wrote:
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.


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
Jul 20 '05 #4
Hallo,
Was immer der Fall sein sollte, da man in nahezu allen Fällen zweifeln
muss... :)


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

Jul 20 '05 #5
SWE@kp wrote:
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.
Wieso? Du willst doch nicht etwa MAID und GMID wiederverwenden?
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...).


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

Jul 20 '05 #6
Marian Aldenhoevel wrote:
Hallo,
Was immer der Fall sein sollte, da man in nahezu allen Fällen
zweifeln muss... :)
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..


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.
- Jeder Datensatz muss eines davon haben. Mit Matrikelnummern als
PK kann man nur Studenten erfassen.
Bingo. S.o.
- Das Merkmal sollte sich möglichst während der ganzen Lebensdauer
eines Datensatzes nie mehr ändern.
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.
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.


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
Jul 20 '05 #7
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" <sw*@klages-partner.de> schrieb im Newsbeitrag
news:2f**************************@posting.google.c om...
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

Jul 20 '05 #8
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" <sw*@klages-partner.de> wrote in message
news:2f**************************@posting.google.c om...
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

Jul 20 '05 #9
What is the question, please ?
(I also hope you are trying to design your DB with Oracle ;)

Alkos

"ben brugman" <be*@niethier.nl> a écrit dans le message news:
3f*********************@read.news.nl.uu.net...
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" <sw*@klages-partner.de> wrote in message
news:2f**************************@posting.google.c om...
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


Jul 20 '05 #10
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" <az****@nospam.org> wrote in message
news:bn*********@news.rd.francetelecom.fr...
What is the question, please ?
(I also hope you are trying to design your DB with Oracle ;)

Alkos

"ben brugman" <be*@niethier.nl> a écrit dans le message news:
3f*********************@read.news.nl.uu.net...
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" <sw*@klages-partner.de> wrote in message
news:2f**************************@posting.google.c om...
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



Jul 20 '05 #11
(I also hope you are trying to design your DB with Oracle ;) No.

Alkos


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
Jul 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1470
by: TinTin | last post by:
Dear All, I got a wierd problem which I haven't been able to explain. I am working on MS SQL 2000. I don't know for what reason, the relationship between Parent/Child table is getting deleted....
8
8082
by: Klemens | last post by:
The linked table has a bigint in primary key columns. I've read that service pack 8 on Jet should solve this but it didn't. On patch1 options I only found to map timestamp to char(26) entry for...
10
2779
by: DaveDiego | last post by:
I've had a user delete one of the client records, I do have a version of the DB with all records intact before the deletion occured. Whats the best approach to getting all the related records in...
5
28977
by: Grant | last post by:
Hi Is there a way to recover deleted records from a table. A mass deletion has occurred and Access has been closed since it happened Louis
4
5149
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
3
1537
by: Prakash | last post by:
Below is my code to delete a record in a continuous form. I can't figure out any reason but sometimes (another) record gets deleted instead of where the record pointer is positioned. Small table...
7
11817
by: Joe | last post by:
I am using Access 2003 and are linking to an Oracle 9i ODBC datasource (using Oracle ODBC drivers). After linking the tables in Access, I inspect the data contained in the linked tables. For...
1
7836
by: iam247 | last post by:
Hi I am a relative beginner with SQL and ASP. With some help after previous posts I have a page which successfully requests querystrings from another page and deletes a record from an access...
1
1124
by: scott | last post by:
Hi all, got a bit of a problem with a datagrid. I have a datagrid that gets it information from a data table which in turn is connected to a data set. The data set is linked to an xml file...
2
12554
by: senthiltsj | last post by:
hi two days before arount 20,000 rows are manuly deleted, is there any way to recover it back. We have backup, that is 10 days old, Is there any way to recover only that 20,000 rows, Plz help...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5077
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.