sql - One to many relationship with ensuring at least 1 record exists in (many table) -


How would you design tables in the following scenerio?

I do not give security at database level, in which at least 1 record will be present.

In addition to Table A should know from the last list Table B (based on any rule).

How can I do such a thing?

The foreign key will be in Table B, which will guarantee that each row will have a corresponding line in Table A. In a relationship, you can have an unnecessary FK in Table A to guarantee reverse, but for one-to-many, this is not possible.

A few years ago when I prepared a method for maintaining the data volumes, the table would be a static or irreversible data (or just the data that could change but not necessary to track) and the table B has changed this as every version of data. My solution was to emphasize all DML access to tables through a view. Actually, there were two main ideas, which were to connect one-to-many, in which A complete history of data transformation was provided. It was triggered "None" to read only (should not be able to change history only). The second was included in static data one-by-one and only the current version This data provides because it is "now" present. All DML went through this view.

When a row was inserted, the trigger was inserted into their potential area in both tables when a line was updated, the static field (if changed) was updated and updated The data was inserted as a new line, the extinction was handled as a soft removal.

The issue is that there was no way to put it in the stable table even if NULL joined all the variants of a new line, then the field is still in the version table Were cast. So it was not possible to have a line in Table A (My Stabilized Table) which did not have at least one common row in Table B (My Edited Table).


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -