Adding to MS Access relationship diagram programmatically - ms-access

I have an application that ships to the customer with a JET database including a relationship diagram which more savvy users are invited to view to gain insight into the construction of the database.
I also have code in my application to update the database structure when new versions require new tables, new columns, or modified queries. I do this by pushing SQL through the ADO connection it works fine.
The problem is that if I add a new table with a constraint that relates it to an existing table (for instance, I add EmployeeHobbies with an FK relationship to an existing PK in Employees), while the table is constructed correctly the new relationship does not appear in the relationship diagram. Over time the diagram becomes progressively less complete.
Is there a programmatic method to force Access to update its relationship diagram from constraint information in the database or, failing that, is the relationship diagram stored in some hidden system object that I can update directly to reflect my changes?
Edit: I failed to make clear that my application is written in Delphi, not MS Access. Users who have a copy of MS Access can see the relationship diagram, others cannot.

I do not know if RunCommand will suit, but for what it's worth:
DoCmd.RunCommand acCmdRelationships
DoCmd.RunCommand acCmdShowAllRelationships

You may be able to leverage Stephen Lebans' SaveRelationshipView for this. His code saves properties for each item from the Relationships view to a table. Later the same layout view can be recreated from the table.
You could adjust your copy of the Relationships view to determine the values to include for a new row in the tblRelationshipViews table. Then let the users recreate their Relationships view based on the updated table information. Perhaps you could even automate to do it for them automatically.

Related

Normalization - How do I properly reference a list from one table in multiple fields in another table?

I'm pretty sure this is a basic question, but I'll be darned if I can find an example that helps me understand the proper way to do what I need to do.
In MS Access 365 I am creating a maintenance tracking database. I have a table with basic employee information. Employees can both perform maintenance tasks and verify maintenance tasks. I can set up a one to many reference using the Employee ID PK as a FK in my task log table for who performed the task. Obviously, I can't set up another one to many relationship to a field of who verified the task.
I already have the task details in a separate table which is referenced by the task log table. Am I just being stubborn in not splitting my task log table into task performed and task verified? Is there another way to normalize this data?
Obviously, I can't set up another one to many relationship to a field of who verified the task.
Yes, you totally can.
When you drag&drop the 2nd relation, Access will ask if you want to edit the existing relation or create a new one.
It will display like this, but it is actually 2 one-to-many relations from User to Log.

Hibernate one to many multiple tables

I'm trying to design a system for giving users permissions on objects. Currently I have a database schema where there are roles and each role can have a permission on multiple 'securable objects'. Such an object can be a sensor, an other user or whatever new thing we might add later. So I have a table role_permissions that links a role to a user, sensor etc. A user can also have a permission directly, so there would also be a user_permissions table that link a user directly to a user, sensor etc.
Now the field that refers to a securable object can't be a foreign key, because the target objects can be of different types and thus come from different tables.
The problem I'm facing right now is how I can make Hibernate work with this. One-to-many relations won't work here I think because Hibernate can't possibly know in which table to look.
An alternative would be to create a role_user_permissions table, a role_sensor_permissions table, a user_user_permissions talbe, a user_sensor_permissions table, and a new role_other_type_permissions table + user_other_permissions table for every securable type that's in the system. So for every single type that needs to have permissions on it I would need 2 new tables to manage the permissions.
But now the database is cluttered with permissions tables that actually serve the exact same purpose but for different types. However, Hibernate IS happy to take this because through foreign keys it always knows what table to look in and what type the object is.
Does anyone know a best practice to solve this issue?
Thanks in advance,
Stan

How to set column to be linked in an imported data list in Sharepoint 2010?

I have an Access database with 1800 records, when moved to Sharepoint list, it randomly sets the linked column,
For example: I have the following columns:
"Badge No.", "Name" and "File status".
Every time when move it (import) to Sharepoint list, it sets "File status" to be linked to the item.
How to set the column "Name" to be linked to the item ?
It not quite clear here, but you do seem to be suggesting that you have more than one table involved here. If you going to send tables up to SharePoint and use the new relational features of SharePoint, then you need to setup the relationships in those Access tables BEFORE you send them up to SharePoint.
Every time when moved to Sharepoint list, it sets "File status" to be linked to the item.
Hum, it not clear what you mean by "item" here? Are you talking about more than one table and their PK (primary key values) and a FK (foreign key) value used to relate these two tables (or is there even more than one table involved here – I cannot tell from your description?
So sending a table up to SharePoint is in general neither an issue nor problem. Sending up tables with related data – well that is a major difference of an issue here.
As such when moving up related tables of data, this can be a challenge with SQL server or any system since often the PK auto number values will be changed on the target system during an up-load. And such a setup thus often suggests that you need a cascade update of child tables to keep the related data intact during an upload.
However, do keep in mind Access CAN upload data to SharePoint, and SharePoint WILL + CAN respect the related tables, but it will also change the PK values during an up-load. This means it is VERY VERY important to setup relationships in tables that conform to SharePoint, else you lose the logical relationship you have between tables due to auto number be re-numbered (changed) during a upload.
However, I do explain in the following video how to up-size related data from Access, and the built in tools WILL allow this type of up-sizing of data and child tables and their FK values will be automatic changed for you.
http://www.youtube.com/playlist?list=PL27E956A1537FE1C5&feature=plcp

Mapping SQL Views with NHibernate and Foreign Keys

In my Solution I have the following projects
MySystem.Core
MySystem.Core.Data
MySystem.MyAudit1.Core
MySystem.MyAudit1.Core.Data
MySystem.MyAudit2.Core
MySystem.MyAudit2.Core.Data
The number of audit projects could potentially grow to around 20.
The Audit projects all require an "Organisation" reference data table. Rather than duplicate the same reference data table across all audit projects 20 times and try to keep them in sync, my plan is to have a "master" organisation table in the Core project.
This will contain Code and Description for all organisations. Then, in each particular audit project have an OrganisationCode table that contains only the Org Codes relevant to that audit but not the description, and have a view in the audit database that looks up the description from the core Org table as follows:
CREATE VIEW Organisation AS
SELECT d.OrganisationCodeId as 'OrganisationId', d.Code, a.[Description]
FROM MyAudit1.dbo.OrganisationCode d
INNER JOIN [Core].dbo.OrganisationCode a ON d.Code = a.Code
This will mean that if Org descriptions change they can be updated in one place and reflected across all the audits.
However, as you cannot have foreign keys on Views within SQL I had created a foreign key between the OrganisationCode table and whichever other tables in the audit database needs them.
As I have discovered, this of course causes NHibernate to try and return OrganisationCode table rather than the Organisation view and causes my SessionFactory creation to fall over as Nhibernate is looking for OrganisationId in the OrganisationCode table.
Is there an easy way round this which will allow me to have a single description lookup in the core project for reference data that can be used across child projects
Yes the audit tables are spread over separate dbs, but I have got to the route of my problem.
The reason that my SessionFactory creation was falling over is that the Configuration was being passed the audit data assembly for mapping, and my organisation mapping file was in the core data assembly.
Now that I have solved that by adding an organisation mapping file in my audit data assembly, my trust object is returning the description values from the organisation view.
Thanks for looking.

Creating an AssociationSetMapping for MySQL with the Entity Framework Designer?

I am trying to build an Entity Framework model for my database schema using EF4 and Visual Studio 2010. Since I am stuck using MySQL as our database (for now), I pretty quickly discovered that since MYISAM tables don't support foreign key constraints, the designer does not have any way to automatically create all the associations for you. It is easy enough to go through the model and build them all manually, but I ran into a problem trying to map a pure join table.
Normally if you are using SQL Server or some other database that supports Foreign Keys, the designer will create all the mappings for you and in the case of pure join tables will create an AssociationSetMapping such that the join table is entirely hidden in the model. Instead you end up with a Many to Many mapping between two two primary entities.
However I am at a loss as to how to create this kind of mapping manually? If I create a Many to Many association between my two entities, I end up with a regular Association, not an AssociationSetMapping. There does not appear to be a way to create one of these in the designer than I can figure out, and to tell it which join table is supposed to be used at the database level.
Am I missing something, and there is a way to do this?
If not, I suppose I have to hack the XML directly, but at this point it is not clear what I need to add to the XML files and where, in order to manually create the association set mapping?
Ok, I can answer this one myself. Once you create a many to many association with the designer, you DON'T set a referential constraint on it, but rather use the Mapping Details window to tell the association what table is the join table, and which keys map to which fields in the database. Simple enough once I figured it out :) But I could not find any good documentation on this.