Not sure syntaxes are right.
They are not. SQLite doesn't support "IF-THEN-ELSE" within a Trigger-Body.
You can't even do a "SELECT CASE WHEN XXXX THEN INSERT INTO blablbalba"
Believe me, i tried.
It's the reason, why i had to make a trigger per Column for AFTER UPDATE.
@Joanna: Question for those 8 Columns: Are NULLs allowed in those 8 Columns?
Because if NOT (there always must be an Integer-Value), then the AFTER-INSERT-Triggers can be reduced to one Trigger
Thanks Zvoni, my sql skills are not so great I’ve never used triggers before.
Think of Triggers like "Events" you're used to from Lazarus
an AFTER INSERT-trigger would be something like an "OnAfterInsert"-Event you might know from Lazarus
The table for distinct also stores the occurrences of each distinct value and that is something I’d like to know.
To store the count is the only way i've found to keep track, WHEN to delete a former "distinct" value.
You could argue, that it's not necessary to delete that value from "Distinct", when you keep the count = 0.
Then to Grab "What distinct" Values are currently in my 73M rows?"
it would be a simple "SELECT DistValue FROM tbl_joanna_distinct WHERE DistCount>0 ORDER BY DistValue"
(which you should do anyway that way)
I will add this to my schema. I do have another table that references the big table but not the columns I want unique values for.
My question, if you have another table, which references the big table, doesn't have to do if it references the values.
It has to do with, that for the first creation of the distinct table, you would have to drop any and all ForeignKey-constraints between them, because you would have to do a dump of the big table, drop/empty out the big table, create the triggers and distinct table, then reimport the big table (to get the Values and counts starting in "Distinct")
This would be a one-time thing
One thing I wonder about though is how much will the triggers slow down things when I recreate the table and make new data?
The first creation (see above how to) will take time, since in a nutshell you execute 73M x 8 SQL-Instructions instead of just 73M
BUT AFTER THAT (running process), it's the difference between 1 Statement and max. 24 (depending what you do, INSERT ( 8 Statements), UPDATE (24), DELETE ( 8 ) Statements, which nowadays is pretty much not noticable