maybe i can describe the idea of what im doing overall... for all i know its a bad idea but my database design experience aint much.
lets say i have one table with a crapload of data, and i need to create statistics that will be viewed and updated fairly often. the problem is creating the statistics i need would require a fairly wasteful computation each time, and they will have to be generated often. so i want to have a seperate table that just contains a foreign key and the totals i need to have for each of those items ready-made. so when a new entry is made i can just increment the appropriate record by one and have my statistics ready to go.
so its just a table with a foreign key and a number that i will need to increment using sql and coldfusion.
the only way i would know how to do this is query the record first, then increment that number in CF and update the record... but im sure thats not how its done.
a column of foreign keys
and several columns of statistics applicable to that key.
one of the "other columns" will contain numbers i will need to increment by one, one will be dollar amounts, one will be still other foreign keys. its just a bunch of stuff i think it will be easier to store than to calculate each time they are needed.
i dont know how to use auto increment unless im adding a new record to the database (then auto increment goes up for the new record). im not adding records, merely updating them.
but i guess my question is more general anyway. instead of +1 what if i need to do +2 or +$1.25 ?? is there a way that stuff is done other than one "fetch the data" query and another "update" query? all the sql ive seen is so startlingly efficient and spare i cant believe you would need 2 queries. do you?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.