0

I currently have a sql table where col 1,2,3 are raw data and col 4 has data that is derived from col 1,2,3. Something like this:

col 4 = col 1 + col2

I populate col 4 with an update statement:

update my_table......Set col_4 = ....

Unlike a View, I realized that I cannot see the column formula just by altering the table. Is there any other way for me to look at the formula that I put in col_4?

jxn
  • 7,685
  • 28
  • 90
  • 172

1 Answers1

3

The formula you use isn't persisted. As far as an UPDATE is concerned, the server doesn't retain information about how you did the operation, just what the result was.

It's like typing things into a regular, every-day calculator. It'll tell you the result, but there's generally no way to see what brought you to it.

On SQL Server (as in, Microsoft's), you could look into calculated (or "computed") columns if you wanted it to automatically update, but I don't know of any way of accomplishing that on MySQL. At least, aside from this which is pretty heavily warned against.

Edit:

Although I was looking into it, and it looks like MySQL does support trigger (Column calculated from another column?‌​). You could look into that. Although it's still a very different functionality than an UPDATE statement and you should be sure you understand the implications of those differences before you implement it.

Community
  • 1
  • 1
Matthew Haugen
  • 12,916
  • 5
  • 38
  • 54