Microsoft Access 2007 List Column with relationship value - ms-access-2007

I am new to access and I cannot understand how to create a list column with a relationship between 2 tables.
I have one table called Persons and the other Interviews. I create a relationship between ID from Persons and Interviews ParentId. When I create a list column (or control) appear all records. Why?

IN a relational database it will give every instance for all records that have a relationship. When creating your new query or form, try Select.Distinct

Related

Is bridge table population implicit in SQL?

Basic question, since I have not written much SQL. When building a link table, which solely has columns that are foreign keys, do you need to insert into the bridge table manually or is the population of this table automatic based on the insertion of values into the 2 other tables?
Example below.
When inserting into student table and class table, the studentclass link table is empty, so I assume I need to also manually enter the values into the link table?
Yes, you need to populate the table yourself. The link table defines the relationship between Student and Class (which students attends which classes). How would the database know which student attends which class if you do not enter the data?
or is the population of this table automatic based on the insertion of values into the 2 other tables?
It is not automatic because even if you insert a class and a student into their respective tables, that does not automatically mean that a student also attends the class. If you did this, every student would attend every class.
sql can not know which rows of the foreign key table(s) you want to link, so oyu have to do it yourself.
A trigger only knows the actual table and data you can select, but the linkin ztable, makes those links that are previously not there, so you can't SELECT that information.
but in your gui, you have the linking information, so it is easy to fill the linking table or bridging table

Using a MS Access SQL query to create a second table with a one-to-one relationship with the existing table

I am using Microsoft Access 2016 and am attempting to use an Access SQL query to create a new table with a one-to-one relationship with an existing table.
I have already set-up the first table of the database - employees.
I have then used another query to create a second table (desks) and to link the EmployeeID field as a foreign key. However, it creates a one-to-many relationship, rather than a one-to-one relationship.
How do I need to alter the queries to create a one-to-one relationship?
Thanks for your help!
EmployeeID in table Employess linking to the unique attribute of table Desks guarantees a 1-to-1 relationship even if the relationship diagram says otherwise.
I would claim that the relationship diagram does not consider unique attributes and therefore shows it as a 1-to-many relationship.

Transfer data model tables from sql to csv

I have lots of sql tables. The tables are "dependent" , i.e. constraints on foreign keys are defined between the tables.
I need to transfer the tables from sql to csv. What is correct way to do that:
Define tables exactly as they are defined in sql? (What should I do with the foreign keys?)
Try to generate other tables by joining the existing ones based on foreign keys in order to hide the foreign keys dependencies?
May be there are other options? What are the pros and cons ?
Thanks,
Note:This is need for another application that run some anylitics on the data
I would suggest to create a view in SQL which contains all information from all tables you need in your CSV later.
The view already implements the dependencies (link of two rows from different tables) and linkes all together in one table.
It would be way easier than your second proposal to create a new table because the view will do all the work for you.
I guess you will need your dependencies.
So you should not ignore them.
Here a quick example how they work:
Lets say you have 2 Tables the first one is named persons and the second one is cars. In the persons table you have 3 columns: ID, Name, Age. In the second one you have ID, Car. To see which person has which car you just check which id from the first table has which value for car in the second one.
If you link them together in a view the result is one single table with the columns ID, Person, Age, Car.
Same does the view.
Later you can simply export the view to CSV.
Maybe I can help you better if you define your needs a bit more detailed.
What kind of data is in your tables, how are they linked(what are the primary/secondary keys).

creating View from an existing table and maintain a relationship with new table

I have these 2 database A(existing) and B (newly created). I have created 4 different table under Database B as per the requirement, whereas i am trying to retrieve the data(SSN, Fname, MI, Address, LName) from one of the table (demographics) from Database A (existing database). also i got to make sure that the relationship (Foreign key relation has to be maintained) has to be maintained between Demographic table and couple other tables from Database B. i am thinking of Creating a VIEW_demographic ( virtual table) and maintain relationship. Can someone please let me know if there are any other ways to do that? i would appreciate your help.

Many-to-Many but sourced from multiple tables

I am supposed to be shipping out a box with variable contents and tracking this in a database. All of my items (the contents of a box) are different types and require different tables to track their respective pieces of information, although each item type has the same length serial number (i.e. PK are the same datatype). And I have a Boxes table.
So each item has a table (~7 tables) plus the box table. I want to create a BoxContents table. I tried to make a many-to-many relationship intermediate table with two columns: one for BoxID and one for ItemBarcode, where BoxID is a FK to the PK on the Boxes table and the ItemBarcode is a FK to each of the PKs on the Items tables (i.e. I tried to link multiple tables to the same column). Unsurprisingly this didn't work. I tried to insert an item and the FK constraint was violated on all but one of the ItemBarcode relationships.
How can I construct my relationships to link several types of items to one box in one table? Is this a logical approach? Do you need more information?
You need a category hierarchy (aka. class hierarchy, subtype hierarchy, inheritance hierarchy...):
There are 3 main strategies for implementing a category hierarchy. If you choose "all classes in one table" or "class per table", then no matter how many kinds of items you have, you only need one "link" table to implement the many-to-many relationship.
My first choice, if the ItemBarcode values are truly unique, would be to:
EDIT: Added description of required triggers.
Add triggers to enforce the barcode uniqueness.
(An insert/update trigger on each item table needs to verify that all (newly) assigned barcodes do not appear in other item tables.)
Use a single BoxId/ItemBarcode table without a FK relation on the barcode side, but with triggers to ensure it remains valid.
(An insert/update trigger on the association table needs to verify that the barcodes exist in the item tables. A delete trigger on each item table needs to prevent, or cascade, deletion of items that are in the association table. An update trigger on the item tables needs to update and changed barcodes in the association table. This last may be integrated into the insert/update trigger in the prior bullet.)
Consider using a view of all items to access common data by ItemBarcode.
My second choice would be n BoxId/ItemBarcode tables for the n item types. Straightforward, but a bit busy. It makes adding a new item type messier than it needs to be.
I would not use a BoxId/ItemTypeId/ItemBarcode table. It denormalizes the data by associating the ItemTypeId and ItemBarcode again, it doesn't allow the use of a FK on the barcode side, and it still requires triggers to ensure integrity.
Don't be afraid of triggers. There are some problems that they can address quite effectively.
Relational databases are not good with this kind of problem. Your basic design is correct - an association table for FKs between the tables.
Your choices are:
Have multiple columns in your association table - one for for each item table
Merge the item data into one item table
I would go option 2.