We get this daily data feed. (We have no control over the original data, so asking them to correct the database isn’t an option.)
The customer records contain addresses in the US. Street address, City, State and Zip.
On our end, we use the data in a database for the marketing department. They sometimes find the address is incorrect, or incomplete, and want to make changes to it. But of course, the next data feed would come in and wipe out their corrections.
Is there a method inf MySQL to protect certain fields from being changes, kind of like a protected cell in a spreadsheet. This is some of the field names of the MySQL record layout:
address1
address2
address3
city
state
zipcode
What if I created along side of this, additional fields that are flagged either “Y” or “N” as being a protected field:
address1
address1_flag
address2
address2_flag
address3
address3_flag
city
city_flag
state
state_flag
zipcode
zipcode_flag
So when the marketing department corrects, for example, the zipcode, it would set the zipcode_flag to “Y” meaning, Yes protect the field zipcode from further changes. If the original data feed does get corrected at a later point, then if zipcode from the marketing department’s database matches the original field, then the zipcode_flag protection would be changed to “N”.
Does this sound like the correct method to manage the marketing department’s database from the daily feed? Or is there another approach or feature available in MySQL to do this? Thanks!
I don’t think there’s a “protected” flag or feature, but there are a few roads you could take to accomplish your goal.
The first and most specific would be to create a “restricted user” in MySQL. To restrict the user, you can/would grant only
SELECTprivileges to the column(s) you don’t want modified. To do this you would use:You can see a good example of this here, or get detailed information in the manual.
A second method would be to create a procedure that selects/inserts/updates. This one may be overkill, but could be accomplished to suit your needs and won’t require modifying user permissions.
A simple example of a select and update procedure would be (not tested):
This will allow a user to select any column you specify that they’re allowed to read by calling
select_addresses()and then perform an update on any allowed column viaupdate_addresses(). You’d have to add several layers of logic to only update variables that have been set, etc – so using a procedure may in fact be overkill =P