Question

This is just a quick question, but when making update procedures for a table say Personinfo for example is this acceptable

Update Person
 Set 
   FirstName = IFNULL(_FirstName, FirstName),
   LastName = IFNULL(_LastName, LastName)
  Where PID = _PID

Is this at all advisable for doing partial updates to a record or should all the information just be sent back regardless?

Was it helpful?

Solution

IFNULL will return exp2 if exp1 is not null.

I assume you want to return a fixed string of ‘First Name’ and ‘Last Name’ if the parameter you’ve passed to the stored procedure isn’t set. I asume by performance you're also talking in relation to speed of updating / selecting and data fragmantation.

You need to be asking yourself, whether for application reasons you want NULL or a fixed string rather than worrying about performance (unless you're already got a performance issue related to this).

It is true that this can affect performance but it should only start to cause issues if your row size exceeds the limit - the internal representation of a table has a maximum row size of 65,535 bytes. If you’re not going to exceed that then the performance difference between having a fixed string and NULL isn't worth thinking about.

You could also opt for a CHAR type as that will always be the same length and never cause any fragmentation. But then you should store an empty value and not a NULL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top