MS Access Append Query, no error message, no result, no known cause - sql

Here goes with as much detail and clarity as I can give you...
Goal: Append portions of "Validated" table to several existing tables, all related by "PropertyID" field
Problem: Even a very basic append query fails to work. I created a query in design view to append [PropertyName] from the Validated table to the GeneralProperty table. Both are text field, same length, not required, allowed zero length, not indexed. When I run the query nothing happens. No error message, no result. The GeneralProperty table remains empty. I went to SQL view and pressed run on the following query and still got nothing:
INSERT INTO GeneralProperty ( PropertyName )
SELECT [Import2-Validated].PropertyName
FROM [Import2-Validated];
Additional Info:
Primary Key is "PropertyID" and it is an autonumbered field.
GeneralProperty table contains the above Primary key
Four other tables contain "PropertyID", joined by a relationship
Relationship enforces referential integrity, and cascades updates+deletes
Append query does work to append text from the "Validated" table to tables other than GeneralProperty, so long as I do not try to append PropertyID in the query.
Database is working as expected for manual entry through a form. All relationships and autonumbering of the primary key work as expected.
Using MS Access 2010
Edits
Result of SELECT [Import2-Validated].PropertyName is a popup to enter parameter value
Haven't specified DoCmd.SetWarnings=False in code anywhere

Related

Oracle APEX: Assign primary key as interactive grid ROWID, Use select Interactive Grid ROWID in SQL query

To preface -- I am as green as at gets.
I am tasked with building an app for internal org use. We have a DB with patient data, and in interface with a hospital electronic medical records system. patient data entered into the EMR is sent to us via interface to update the patient profile in our database. Partial matches require manual intervention.
Message is received in a table within a staging schema
attempts to match to existing patient
if there are only 'partial matches' a status is set to 'mismatch'
I want to:
Display a summary of all 'mismatch' status records. I want to use an interactive grid to select individual records.
Set ROWID of interactive grid rows to the respective primary key of the record in the staging table.
Use the selected Interactive Grid ROWID (user selects a specific record in the interactive grid) to select the matching primary key of the corresponding record in staging table to create SQL query to find potential matches within our DB. Potential matches are displayed in a second table.
Questions:
How do I set the rowID of an Interactive grid to the unique key column of the staging table?
--Some research shows I need a hidden item, is this correct?
How do I access a rowID that has been selected in the Interactive grid to use in a SQL query?
My humble thanks and appreciation
So, your question is a bit confusing, but as far as I understand it. You are getting some data from table A, trying to match it with table B. If it matches, it irrelevant for us. If a match is not found you want to show it so that it can be manually matched.
In apex in order to update a table, you need to select what is the primary key by which it will update the data. That is usually a column in the table, but it can also be rowid(just include it in the SQL like any other column).
What I would suggest for you from what I understand of your situation.
Display the mismatched rows in an interactive grid, with rowid as primary key. Then you will need to have a column by which you match, if these entries already have some sort of key by which you tried to match but failed, display that. And have that column be a PopupLOV so the user can edit what value is in that field and set it to the appropriate match. One thing you will need to be careful about. You are editing a Unique key, or perhaps even Primary key, you might get conflicts here. Even if you only display unmatched data in the LOV, you can still have a user editing multiple rows and trying to match two rows to the same value, that will fail with an error that isnt particularly user friendly.

SQL SSMS: changed 'allow nulls' design, now can't switch back (`cannot insert the value NULL into column`)

I'm working in a dev SQL database within SSMP.
We've got a junction table, jnc_roles_users, which pulls values from two lookup tables: lu_roles and lu_users.
Initially, all but one column in the junction table had the Allow Nulls checkbox checked. I then went into the design editor and checked all the boxes - got the alert that this will affect the two lookup tables, and saved the changes successfully.
Now, I want to switch back to the original table design of nothing allowing nulls except one column. But SSMS is no longer allowing me to uncheck the Allow Nulls box for one of the fields. Ironically, no problem unchecking our 'ID' primary key. It's our 'pseudo' primary key 'roleUserID' that I can't change back. When I try to uncheck 'Allow Nulls' for it and save, I get the alert:
'jnc_roles_users' table
- Unable to modify table.
Cannot insert the value NULL into column 'roleUserID', table 'jnc_roles_users'; column does not allow nulls. INSERT fails.
The statement has been terminated.
This seems counterintuitive because the column is currently stuck at 'Allow Nulls', yet this popup is telling me it can't accept nulls.
lu_roles and lu_users was saved successfully, but not jnc_roles_users which is the only table which contains 'roleUserID'.
The roleUserID column isn't technically a primary key - but we're considering it 'like' one as it does take unique values that we set. For certain reasons we're considering this column as a sort of primary key - something to do w/ database backups in different locations and how the regular ID pk might get duplicated incorrectly in different environments, so we needed a second pseudo pk of roleUserID.
Any ideas?
It's most likely that some new data with a NULL value was added to the table between the time you changed Allow NULL in the designer and the time you went to change it back.
You can try using ALTER TABLE -
ALTER TABLE jnc_role_users
ALTER COLUMN roleUserID NVARCHAR(50) NOT NULL
Change NVARCHAR(50) to the data type the roleUserID column uses

MS Access duplicate record error

I am struggling with MS Access duplicate record error. I am getting this error on some of the records while doing inserts. The exact error is "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again".
The interesting part is that while running the same data set I get errors on different records each time. I removed the indexes in a destination table but still the same issue. I read that it might be MS Access glitch, so I created identical table in SQL Server and attempted the insert - worked like a charm. So it seems it is Access issue. Is there any workaround? I have tried to find one but so far no luck. Would appreciate if someone could point me to the right direction as of now changing databases would not be an option.
Thanks.
P.S. My primary key is a composite key of Name (text), Key (text) and LineNo (integer). There could be mnore than one key with the same name per each Name fields but different Line number.

Error: The INSERT statement conflicted with the FOREIGN KEY constraint

A business user requested that I change a dropdown list to a textbox for creating records. The dropdown list is what was created by default for relating to tables in my database. As requested I made the change and replaced the dropdown list with an #Html.EditorFor element. I now get this error message when I try to create records. Is there a possible solution that can fix this error? There aren't any syntax errors that stop me from compiling my code. This error occurs at runtime.
This means that your forward thinking database designer placed a constraint in your database to stop people entering invalid values. Your application allows the user to enter invalid values, but luckily your database is stopping it.
A foreign key is how you ensure that a table only gets it's 'lookup' values from a valid list.
If you remove the constraint you will risk putting garbage into your database that is a great effort to fix.
If you start putting invalid values in this table it means things like inner joins stop working and data starts going missing in reports.
Need a bit more information such as tables being inserted and the foreign keys on it. Likely the text entered doesn't match that of the drop down. You would likely have to remove the foreign key. However if the design was that a numeric value was being inserted and not just a text one, The users now have a text area... where's the numeric value (I'm assuming some design here which is why I asked for tables and keys)? I'd likely do the following:
Change the table structure so that the value being inserted is character based (if not already)
Remove key constraint
Update the existing records so the text of the lookup value is replacing the numeric values (assuming numeric design of foreign key.
Drop original lookup table.
Alter design so code uses distinct on the column in the remaining table for it's list of values.
The alternative is that you'd have to insert the new text value first into the lookup table, then get it's new key value then do the insert statement. I suppose this could be handled with triggers and a before update statement but the question; but unless there's a reason to keep them separate, the above numbered list seems simpler in the long run
Previously with the dropdown, you were allowing the user to chose from the predefined values, i.e. values that were present in your lookup table to which you have put a foreign key constraint. But now as user can enter any value(which might not be present in the foreign table) thus resulting in this error.
To remove this error you can drop the constraint
ALTER TABLE <TABLE_NAME> DROP CONSTRAINT <FOREIGN_KEY_NAME>
or check the value(against the foreign key table) entered by user before inserting it.
UPDATE
If you have removed the foreign key constraint, then you'll have to insert any new(you'll have to check if data is new or old) data in the lookup table, assign it an ID and then insert this new ID in the main table to create the link between the two. NOTE: You can maintain the foreign key constraint in this case.

How to Troubleshoot composite key violation in MS Access

My Access database (2007) has Four tables; Customer, Supplier, Account, and AccountAgeing
AccountAgeing has a composite key made up of the foreign keys of two of the other tables, plus a date. i.e.;
AsAtDate, SupplierID, AccountNumber
I am importing data from excel via a temporary table, and my parent tables (Customers, Suppliers, Accounts) are importing well.
However importing AccountAgeing from my tempTable continually has a key violation. Of 749 possible imports, 746 violate the key. A query to test was:
SELECT DISTINCT tempTable.[SupplierID], #31/7/14#, tempTable.[AccountNumber]
FROM tempTable;
This returned 749 records (all of them). If this is the case, how do I have a key violation??
The composite key fields are all indexed, with duplicates OK. There is no data in the destination table
I have date and [Account Number] indexed as these are the fields searches will be on.
Here is a sequence of some troubleshooting steps you can try.
Remove the primary key from your target table and populate it. If you can't populate the target table, your problem may not be the key itself, and may become apparent based on error messages you receive.
If the target table does populate, try adding your desired composite key to the already populated target table.
If you are unable to add the key, re-run your "select distinct" query on the populated target table.
If you don't select 749 distinct rows, visually inspect the table contents to see what's going on.
These steps should lead you to some insight. Just a guess - but it sounds possible that you may have a data type mismatch somewhere. In cases like this, Access will sometimes convert data on the fly and insert it without giving an error. But in the process the nature of the data are changed, resulting in a key violation in the target table.
I'm curious to hear what you find. Please post a comment when you figure out what the problem is.
Hope it helps. Good luck with the troubleshooting.
Thank you Marty!! I attempted to populate manually, which errored because there was no matching record in the Customers table.
I discovered that I had incorrectly assigned AccountAgeing to be the parent of Customers, rather than of Accounts.
The business logic is that an AccountAgeing record will always have an Account, but an AccountAgeing record does not always mention Company Number (the primary key of the Customer table).
The fix was binding part of the Account Ageing composite key to the Accounts composite key.
I am unsure what will happen when I add an ATBRecord which has an account number but no Company number, but that is another question
Check the Indexed Property in table properties - make sure it is not set at Duplicates OK on any of the composite key fields