Issue with enforcing referential integrity In Access 2013 - ms-access

So I was mapping out the relationships between tables in a database I'm working on but I ran into some problems.
It was recommended to me that I use the "Enforce Referential Integrity" function when working with table relationships but everytime I try and and make more than one relationship between tables it gives me the error: "No unique index found for the referenced field of the Primary table".
If I don't use the "Enforce Referential Integrity" function then it seems to work fine. Will it negativity effect my table if I don't use the function and if yes then how can I solve the error?
Thanks in advance.

The purpose of referential integrity is data integrity, if you won't enforce it, the data may become inconsistent, may appear logical errors, so enforcing is highly recommended. Additionally you can enable cascading and the data from detail table will be deleted or updated automatically if you delete/update the key field in main table.
As of error, it means that your main table should have primary key or unique index on fields you map to detail table. If main table has primary key with few fields, all those fields should be mapped to detail table.
Please post the picture of your relationships map and describe which fields should be mapped.

Related

I'm getting Error: Missing index on column(s). when I try to create a relationship between tables in phpMyAdmin Designer tool

I need to create the database schema and include it in my software requirements specification for my school project, however, when I try to create a relationship between 2 tables, I get Error: Missing index on column(s).
I think #HazarathChillara has this right; you need to create primary, unique, or index keys.
You said every table has an primary key, but did you make each foreign and referenced key an index as well? It sounds like you neglected to properly set up your table structure; I only get the error when I don't have a primary key or index on the particular columns I'm working with.
"MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan"
You can just put an INDEX on the foreign key (often my referenced key is a primary key anyway, so I don't need any additional key on that column).
This error appears only when you neglect table structure. Make sure that you Indexed a foreign key as well. you can see i marked how could i select my foreign key as index.In this Image I am indexing selected, 'sr' my foreign key
As Usman Khan said you have to go to the structure tab of the particular table and clicked on more options and select 'INDEX' for the foreign key.
the below image will help you how to do it
I think i have another simple solve,
thing is, phpMyAdmin wont allow the addition of foreign keys to an already available data entry, so here is the my simple solve,
1. ensure to backup your database
2. confirm that your data was backed-up securely, recommended Offline backups
4. delete all data entries in all tables that will be part of the new relationship.
5. now Create the relevant relationships.
6. be sure you have created all required and preferred relations to avoid the need to
export data again

Generating SQL from an ERD - how are relations mapped into SQL?

I'm using Mysql workbench EER where I draw my ERD.
There are all kind of relationships between the tables (optional/mandatory,non identifying/identifying)
and I use the Forward engineering to generate the underlying SQL.
As far as the relationships go, for an optional relationship it generates a NULL FK
while in a mandatory a NOT NULL FK and that's it.
I mean shouldn't it also based on the relationships generate Cascades deletes for example?
i.e if I have an identifying relationships, then when the parent is deleted the child should be deleted too thus a cascade delete would have been generated
Or, in other words the relationships modeled in an ERD have no practical value other than conceptually know how your database is modeled on paper?
For example what should be the generated sql code for an identifying mandatory relationship?
What you are referring to is called a relationship. In database management terms a relation is something different.
Your relationships should get implemented as foreign keys. The practical value of a foreign key is that it enforces referential integrity. Cascaded deletes are not typically the desired behaviour and in SQL the default referntial integrity action is that delete of a row in a parent table is not permitted if the row is being referenced in another table. If you want cascaded deletes then you have to specify that. Note that in MySQL only the InnoDB database engine supports referential integrity.

How to disable all constraints(foreign key,Primary key,IDENTITY) in MS SQL Server 2008

I have created one database by executing generated script(schema).
After that I am copying database,only data while copying I facing problem of foreign key violation and primary key violation
What should I do for this issue.
key Violation
You really only have two options here, go though the data your importing and change the conflicting value or drop the constrains all together. Once the data is in the new DB you can not enable constraints until you address the duplicate data. See this SO for in on removing FKs, it also applies to dropping PKs
How do I drop a foreign key in SQL Server?
I would highly recommend seeing if you can change the data so it no longer violates the key constrains

Do I have to fill foreign key values?

Do I have to fill the field of a foreign key in MySQL or any other database manager?.
I'm writing the data of a table and when I get to the field that is a FK from another table, I have to write something, is this necessary?
I understand that the value in that FK is stored inside the parent table where it comes from.
You have to provide a value unless the foreign key column is nullable.
It depends on whether the is actually a foreign key constraint in place (available in InnoDB only). In some cases frameworks, applications, or database management tools create "false" foreign keys that exist only in the application and not actually in the database. Also, the limits on how you can insert/update/delete data realted to the foreign keys can differ based on the type on constraint in place.
Here is the MYSQL documentation for definitive information:
http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
Specifically, look at the "Referential Actions" section for comments on the behavior between the tables.

When to use foreign keys in mysql

I'm currently building a database and I'm not sure when to use foreign keys on the tables.
Most of the tables are for transaction, logging, and history.
Is there a general rule in which tables to put the foreign keys?
I have this table for the general details of a specific transaction, then another table for the specific details. Should I put a foreign key on the table for the specific details?
There's also this table used for storing user info and another for logging user activities. Should I also place a foreign key to the table that logs user activities?
If there is a relation between two tables you should always enforce that using a foreign key constraint.
I prevents logically "corrupted" data (e.g. details for a transaction that doesn't actually exist) and - equally important - it documents your database model.