What is the arrow in the one to many relationships in MS Access and what does it mean - ms-access

I am learning MS Access and am looking at the Northwind DB. There I find in the relationships an arrow at the "one-end" of some one-to-many relationships and I wonder what that means or what consequences it has. I could not find anything about it asking google (maybe used the wrong search term??)
screenshot of one-to-many relationship
I tried to replicate the relationship but did not succeed.

Besides the usual (compared to other databases) attributes related to relationships between tables and referential integrity, in Access you can also specify a Join Type. This does not affect the relationship between the tables as such but will have an influence on the query designer. When you add the tables to the query designer, this will automatically either create an INNER JOIN (with no arrow) where only matching records on both sides will be returned or an OUTER JOIN where all records of one table will be returned but only matching records of the other table (returning the corresponding columns as NULL). The arrow points to the table which might have missing records.
But you can change the join type afterwards in the query designer. So, the informational value of this arrow is very limited.

Related

Does IntelliJ has a function to visualize the relationship between two specific tables in a database?

I'm working with a big mySQL database in IntelliJ.
I'm trying to join two tables which aren't in a direct key-relation to each other. Hence I have to join over multiple tables.
Because I barley know the database scheme, I can't find out these tables in a appropriate time. I know that IntelliJ has a function which can visualize all tables with their relations within the database but does it also provide a function where I can find out all tables in between two specific tables?
You can get help from Intellij partially for your task, using the visualization feature as follows-
The relationship between tables are clearly shown.
For your question, you need to check the primary and foreign keys for each table which are easy to know as they are highlighted.
Traversing them you can find the relationship.

MS Access 2013 query query criteria can't assess if value A is contained in value B string

Issue:
I am developing a simple issue tracking database and have hit a stumbling block that I’m not sure how to resolve. Have tried several approaches using queries, sql statement etc but still not working. I may have to rethink how I am doing this but hoping someone may be able to address the issue as it stands, though if a more elegant way of doing it happy to implement that.
Scenario:
A table called tblUsers has a field called Access that is a lookup to a table called tblCategory and allows for multiple values to be stored (one to many). In essence this is saying which category(s) of “issue” the user is allowed to
A simple msgbox test in code shows that this is correctly storing the values selected in the following format "1, 2, 3, 4"
In turn, each issue can only have a single category (one to one) which is stored in a field called Category in table tblGMPIssues and is also populated from a lookup to the tblCategory table.
So far so good ….
I then have a query called qryUserIssues that should show all issues from the table tblGMPIssues that are a) “Open” (status = 1) and that b) match any of the categories that the user is permitted to view.
I can get this to work with a single value i.e. as it stands query prompts for input and if you enter a single valid integer it returns expected results
But I can’t work out the syntax to get the criteria to accommodate multiple values. For example, in above scenario our user should be allowed to see 4 different category or calls “1, 2, 3, 4”
Tried using INNER joins, tried assigning to variables and using a LIKE criteria but can’t seem to get the syntax right.
If anyone could let me know if this can be done and if so how as it’s driving me nuts.
All help and suggestions gratefully received.
Updated relationship diagram --> 1
For precisely the reason that you've asked this question I would recommend never using the multi-select lookup option for columns in MS Access tables. Instead create an intersection table which tells you the combinations of values from the two main tables that are allowed. So instead of having the multi-select Access column in tblUsers, you should have a separate table called tblUserAccess with two columns (UserID and CategoryID). The two columns together will form a composite Primary Key for this table, and individually they will be Foreign Keys to tblUsers and tblCategory respectively. (You should do the same kind of thing with tblType - remove the Categories column and set up a separate table called tblTypeCategories).
Coming to your query, are you expecting this to show you all the relevant Issues for a particular user? At the moment, it is not doing this. The reason it is prompting you for input is because it doesn't understand ([tblUsers].[Access]) - tblUsers is not referenced in your query, and the query has no way of knowing which particular user you're interested in.
With your new table in place (and populated with the relevant data) you should add tblUserAccess to the query, joining tblGMPIssues.Category to tblUserAccess.CategoryID. Take the ([tblUsers].[Access]) condition off the Category column. Add the UserID column to the grid and set the criteria to [Input UserID]. Now when you run the query it will ask you for a user ID, and it should hopefully show you all the Issues that the given user can access.
Good luck!
First, I suggest you normalize your data a bit:
You have a number of tables that are reference data (e.g. tables tblStatus, tblSeverity, tblLocation). You have a s a primary key a (system generated) ID. That is wrong! The primary key of these should be their data, i.e. status, severity, location.
I can't see what the relationships are between the data. It should be one-to-many, mandatory (i.e. one Status can occur in many tblGMPIssues and a status is mandatory).
Your table tblType is unclear to me but it contains the categories. I am not familiar with the '-' before Categories followed by a Categories.Value but I assume an occurrence of tblType can contain exactly one Categories.Value. If not, then you must decompose this table.
If a User has access to a number of Categories, then there must be a many-to-many relationship betwen Users and Categories. From this relationship you do your select query, but I don't see this relationship.
Use following query to get any of the Category IDs 1, 2, 3 or 4
Select * from tblGMPIssues where tblGMPIssues.Category in (Select UserAccess from tblUserAccess)
I still have many problems with your relational design, or actually the lack of a proper relational design. As an example, below is a diagram from my Access 2007 showing a part of your database with a proper design. Access automatically shows that "one" and "many" symbols (which I don't see in your diagrams). I also show the relationship dialog with the proper fields checked. Note that none of the keys of any table, except tblIssue, has a system generated primary key. They are all plain text whch allows better understanding when inspecting the data and, as said, the database automaticlly updates child tables when the primary key value of a parent table changes.
Note table tblCategoryType: it implements a many-to-many relation between categories and types, meaning a category can be of zero or more types and a type can be in zero or more categories. In addition to "update cascades", this table has the "delete cascades" checkbox checked so if a category is deleted, all its relations with types are deleted (not the types).

How to create default relationship for 2 MySQL tables with many-to-many relationships?

In MySQL, I have 2 tables, A and B, with many-to-many relationships. And I have a pivot table, A_B, for the relationships between table A and B.
In table A, there are some rows that I want to link to *ALL* (including current and future) rows in table B. For example, let's say currently there are 5 rows in table B. Row A2 in table A is linked to all 5 rows in table B. In the future, when new rows are added to table B, I want row A2 to be automatically linked to ALL those new rows in table B.
Currently I am thinking of using MySQL Trigger to add this function. But I am not sure whether this is the correct way to do this or not.
Or I should add a new column in table A, and use it as an indicator for the default relationship? Then in my programming codes, I can check the column value whether a row in table A has relationship to all rows in table B.
Pivot table
In Relational Database terms, that is an Associative Table.
What you have is a need, such that designated rows in Table_A are related to all rows in Table_B; and the rest re related via Table_A_B. The great Dr E F Codd asks us to think of data in terms of sets. There are two sets in Table_A. Let's call the first set All_B and the second set Specific_B, for which Table_A_B identifies the specific relations.
Therefore is not a "default" relationship, it is two separate relationships, based on the Subtype.
You don't need the "default" relationship you described. That would result in masses of rows that serve no purpose, because the rows in Table_B for All_B are known, they do not need to be stored.
You don't need triggers (which would have been necessary to keep inserting Table_A_B Rows whenever an All_B row is inserted). Ugly as sin.
The correct method is to use Exclusive Subtypes, named for the sets, where:
Specific_B is related to Table_B, via Table_A_B
Table_A itself, and All_B, are related to nothing.
Your code can determine which Subtype any Table_A row is, and join Table_B accordingly:
via Table_A_B for Specific_B
Cartesian Product Table_A::Table_B for All_B.
Picture
Typical XOR Gate • Table Relation Diagram
An Exclusive Subtype requires a Discriminator column in the Basetype.
If you don't want to bother with full Relational Integrity, then sure, an Indicator column in Table_A will suffice. That is the Discriminator column in Table_A, minus the Subtypes.
Response to Comment
This is the first time I learn about the concept of exclusive subtype. Now I know how to solve the problem
In that case, study this document on Subtypes. The links include code that you will need, such that the integrity is Declarative. If you would like a full discussion, and particularly to avoid ugly methods to enforce "integrity", read this answer.
I think using database triggers is the most appropriate way to do what you want because it conserve independence of the DB from program and DB is complete by itself.
But maybe you consider using Grouping concept as it is used in user accounts management DBs. you can create a group such as admins and relate all records of table B to it and only assign records of A to this group.

MySQL many-to-many relationship table usage

I have three tables: Resumes, Orgs, and Resume2Org. Basically, Resume2Org is my many-to-many relationship table linking Resumes.resume_id to Orgs.org_id (so it only has those two keys in that table).
My question is, is it okay to use that many-to-many relationship table to store other data? My use case: the database is part of a system to sift through incoming resumes. But I've been asked to implement a "marked as read" feature so we can easily get the list of resumes we haven't looked at yet. But since a resume can belong to many different orgs, we only want to mark a resume as read for the org the user/viewer belongs to. I thought, hey, having that flag in Resume2Org would be perfect. Is this a smart approach, or should I create a new table specifically for "marked as read"? All the examples I've seen about many-to-many relationship tables is that those tables are used just for that... linking two tables.
Yes it is okey to have additional fields in a many-to-many table. I think it is the right way to do in your case as you don't need to join additional tables and you save spaces.
I was in a very similar situation last week and I added additional field for that.

How to create multiple relationships between the same two tables in MS Access?

I have a Users table and a Reviews table. The Reviews Table has ReviewedUserId and ReviewerUserId, both foreign keys that are pointing to the primary key of User table (UserId). When I try to create the second relationship in Access between the User table and Reviews table, it creates a second User table and names in Users_1.
Firstly, is this normal in Access? In SQl Server, I can have two relationships between two tables with no problem.
Secondly, is it possible to rename this alias table so that it doesn't have to be called Users_1?
Thanks.
User_1, User_2 etc is the way Access aliases tables when creating multiple relationships. If you use code to create the relationships, you can choose your own names
Database.CreateRelation Method
But I do not know of any way to change the alias in the relationship window.
Do you have to have referential integrity enforced at the table level? Can you just set up the relationships as a query? I'd guess that you can rename the 'alias' table if you do it via a query. In fact, you could just write the SQL and paste it right into an MS Access query.
I very rarely set up table level relationships in Access nowadays, and I also rarely even link forms through directly to tables or queries any more. I use unbound forms, populate them with code, and use code / DAO to control the updates of the relevant recordsets. All the behaviour of relationships, I then enact using SQL & VB as required.