Speed of updating database fields SQL - mysql

General question on speed:
I have a section of my site where users can update account information. Considering run-time, I was wondering which of the following two approaches would be quicker.
Do a select query on the users existing information, compare it against what the user has submitted in the update form, and only if the field values differ, then updating the fields.
OR
Just overwrite the values in the SQL field, regardless of whether the data in the field matches what has been entered into the form. (This saves me one SQL SELECT request).
Also, just as an aside, does SQL respond differently if attempting to replace data with an exact copy? Is there already some built in method for not replacing what is already there?
Thanks

Related

Updating one table in MS Access with data from another

In MS Access 2016 I have a table named Master that periodically needs to gets updated with ‘updated’ data from a table named NewData. Each table has the same fields, except Master has one additional field named OTHER_SOURCES (explained further down). They each have an indexed unique id field named EVENT_ID. I’ve built an update query where the tables are joined one-to-one on the EVENT_ID field. In this query I have the fields in Master getting updated to the new values from the same fields in NewData if the TIMESTAMP field value is different. If the TIMESTAMP values haven’t changed, then those records do not get updated. This part is pretty straightforward and works fine.
However, I have end users that may make occasional changes to the values in the SIZE field of Master that need to be preserved and not overwritten with updated values from NEW_DATA. When a user makes a change in SIZE field, he documents the change with information obtained from other sources, which is stored in the extra field I mentioned earlier: OTHER_SOURCES. Here’s what I need to do, and I just can’t figure it out. Whenever a user has made a change to the SIZE field for a record, I need the update query to not override that value in the SIZE field, but still update the values in all the other fields (again, assuming the TIMESTAMP values are different between the two tables). It seems I need to use an IIF statement, but I’m thinking it needs to be done in VBA where I’m a bit of a hack. See screenshots. I greatly appreciate any help you can offer.
enter image description here
enter image description here
You can still proceed with the update, but update it to the same value as its previous value:
SET SIZE= IIF(nz(OTHER_SOURCES,'')<>'', MASTER.Size, NEW_DATA.Size)
This assumes that anything present in the MASTER.OTHER_SOURCES column indicates that the user has changed MASTER.Size. Note that MASTER.Size will never be updated from NEW_DATA.Size until someone (end user) removes MASTER.OTHER_SOURCES.

MS Access rookie - Ask for confirmation before updating a record

I'm trying to create a small MS Access database to ease up my everyday job. The problem is I'm a noob when it comes to databases. I'm trying to prevent the user from accidentaly updating the wrong record.
I have a table of records, some of which are not 100% complete.
I created a query that lists only these incomplete records.
On a form, the mentioned query is fed into a listbox.
I want the user to be able to pick an incomplete record from this listbox and fill in some of the remaining parts of the record in a bunch of text boxes. What I don't like is that the record gets updated as you fill in the form fields (they're bound to the table) WITHOUT any request for confirmation. If the user picks a wrong record at the start, the records are gonna get messy with every text box filled. Or that's what seems to be happening.
Here's my idea of the user form:
Is there a correct way to do this? I could force it all with VBA but I'd rather avoid that and use a more native (correct) solution.
Thank you for any answers.
Table constraints are an important part of database design. Any grouping of elements that together are required should be in their own table. This way the required fields must be entered for every record in that table.
For each data entry step you will have one or more tables representing the required data of that step.
If you are following database normalization best practices this should be simple to achieve because your data will already be broken down in to small elements that can have required fields to complete each record.
If you have a record that contains fields that are filled out at different steps then that is a design smell that indicates your table is not properly normalized.
In MS-Access, the forms will follow these rules set in the tables. You will not be able to save a record that has required fields missing.

Use query's hidden columns/fields in MS Access report

I have a query which joins a few tables. The query asks for a parameter when it is run. Then it displays a few columns/fields from its results, the other fields (like, the entered parameter and other fields that are common to all rows) are hidden. I'm trying to create my first Access report based on this query and I'd like to use some of these hidden fields as a record source for text-boxes/labels but I've been unable to do so. Those fields don't appear in the list of possible record sources.
I've tried the Add Existing Fields button and selecting the field I want from Fields in related tables but when the bound textbox shows up in the report with an error like Invalid Control Property. No Such Field in the Field List which I think means the fields are still invisible to the report. Would appreciate any help getting this done.
The answers is to edit the query and include the missing columns so that they are available to the report.
For non-selected query columns, the use of the word "hidden" is misleading. The way that SQL works--even beyond SQL in the overall concept of datasets--is that only subsets of data are requested in a query. If certain columns are not selected in a query, they are plainly and simply NOT available in the resultant dataset.
It may be possible to re-aquire the excluded columns with another query, but that still does not imply that missing columns were just "hidden". In the case of a subsequent query to get different columns of data, the database engine must re-analyze the new query, re-read the data, then compile the data from the new set of columns to be returned in a completely new subset of data. It is a complete round-trip process that is much more involved than just un-hiding the data.
Forms and reports are completely different types of objects that can mark fields as "hidden", but a query is not the same despite being displayed in a datasheet. Objects like Access Forms and Recordset objects in (VBA) code are designed to hold subsets of queried data, so they are able to temporarily hide (or ignore) or un-hide certain fields without re-querying the database. (Technically an Access Form has its own Recordset object for holding and managing queried data.)
Even though Access is "self contained" with both database and user-interface elements, it is still primarily a standard RDBMS (Relational Database Management System). The principle idea in efficient data handling of an RDBMS is to get only what you need for the current operation. Consider that SQL can be used to query data from a remote server. Even Access can get data from and update data on SQL Server, for example. If data fields were only "hidden" when not included in a query, that would imply that the entire database (or at least an entire table) would be passed back and forth, and that the only thing hindering getting at any column would be "making it visible" as though it is actually immediately available. That would be terribly inefficient both for memory and for remote communications.

Complex fill in the blanks query in MS Access 2010

I have looked and haven't found a method on here to do this. I am assuming my search is skewed and I just missed it, if this is the case, please let me know.
Anywhooo, I have a large and unwieldy report coming out of SAP every day. Because it will often have some strangeness, we import that into an Access database so we can keep an eye on the stuff we need in our department. I am using a combination of 6 fields to create a primary key in Access. The information in those fields is about the only thing consistent I get out of this SAP report, but the remainder of the data can be considered dynamic and can change from day to day. Usually this is a matter of filling in a few blanks, Occasionally this is changing existing data, and on rare occasions, it may involve deleting data out of a handful of fields.
The SAP report is around 130 columns of data, So I'm looking for an efficient way to roll in the changes without overwriting what folks put in there manually.
EDIT:
Here is the way this is used. SAP (for reasons I'm not going to go into) sometimes will have bad data show up in the daily report. We are using Access to track and put the correct data in to something that we can generate much more accurate summaries. What the users put in is to be considered true and accurate.
The transactions we are tracking can take a long time to complete. Most take around 30 days to complete. That's why I will have blank fields on one day, and several of them to be filled in on the next. We might not get any for the next few days and then a bunch more are filled in later. That is the normal flow.
What I have to account for is the odd occasion where a mistake is made early in the process. At a certain point, an error will break SAP's ability to update anything at all in the report we have to use.
I have 3 fields set up that trigger what my users daily work is going to be. There is a logical flow so that user 1 completes what he needs to do and then that record will show up on User 2's report. These fields will also stop the general update process in an exception report if there is a difference in what is coming in from SAP, and what is already in my database.
What I am looking for is some way to systematically fill in blank fields, on existing records in access. I do not want to overwrite if something is in a field, only the null values. I can do this on one field at a time, but each record has about 130 fields. I'm wondering if there is a way I could do this in just 1 query?
Thanks all! I hope the edit makes more sense now
A simple google for "Access SQL update null values" could have yeilded you what you need. But if all you need to do is fill constant values into empty fields then something like:
UPDATE Table SET Table.field1 = VALUE
WHERE Table.field2 is NULL;
Now if this data is different for each record based on; say data from another field, then you may need to write some VBA to build that value/string for you. But otherwise if you are JUST updating null fields to include data, then a simple UPDATE statement will do
EDIT Based on new info:
So if I'm understanding correctly: you have two tables. One table with the blank fields and another table that contains the values you need.
If this is the case, you can use a similar UPDATE statement, but use an inner join to get the data you need from table B to fill in table A
UPDATE TableA INNER JOIN TableB ON TableA.KeyField = TableB.KeyField
SET TableA.NullField = TableB.NotNullField
WHERE TableA.NullField Is NULL;

Using Mysql/Ajax to populate Form using value from Input Fields

Am trying to populate a reasonably large form (40 odd fields) with values from a MySQL database.
I have no problems creating the JSON array from the query.
echo json_encode($row);
What I would like to achieve is difficult to find out from other posts etc and it may be impossible to do.
What I wish to do...
Use 2 Input Fields that both must be filled correctly before populating the rest of the form.
So
FIELD1 = Membership No
FIELD 2 = Drivers License No.
(A quick sort of Security Check)
So if FIELD1 AND FIELD2 equals values in the database, then populate the rest of the form.
Nothing happens UNTIL BOTH fields are filled.
My mysql query is a straight forward - WHERE FIELD1='value1' AND FIELD2='value2'
Is this at all possible to do?
The other approach I was contemplating was to somehow use AJAX to update the mysql query with the input values, then refresh the page. The query would change to EG WHERE FIELD1='56779' AND FIELD2='Q16987999'
I am not pursuing this any further. Too complicated when I can just create a "Login" style form using Member No and Drivers Licence as the Username and password, then POST these values to the SQL Query on the next page.
Then a simple SELECT query to populate all necessary fields with mysqli_fetch_assoc