Cascade delete in a one-to-one relationship in Access - ms-access

New to Access so please excuse me for the basic question ...
I have two tables in an Access database (Office 365 enterprise) for which I have setup a one to one relationship using the relationships tab (I have setup the same unique field in each table and used as pk/fk). I have checked "Enforce Referential Integrity", "Cascade Update Related Fields" and "Cascade Delete Related Records". In Access, I right-click the child table and click "open", I then right-click a record and select "delete". However, when I check for the matching record in the parent table it is still there.
What am I missing here? Does the delete need to be done in SQL for the cascade delete to work?

Related

Can I not enforce referential integrity in MySQL

I have a SQL table called "user" and a table "login" that has a foreign key constraint to a user. I want to be able to delete a row in the user table, even if there are login rows that reference it. Right now the database stops me from doing this.
Does anyone know how I can alter the table (through SQL or preferably through PHPmyAdmin to allow me to do this?
The tables were created automatically through Django.
Edit: To clarify: I don't want to cascade the delete. That is, I want the rows in the Login table to remain even though the user they reference is gone.
If you want this kind of behavior you have to create the foreign key with an ON DELETE CASCADE clause. With an ON DELETE CASCADE foreign key all rows referencing the user will be deleted with the user.
See: http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
Edit: If you want to keep the user_id in your login tables you just have to drop the foreign key. Anyway, If you are asking this is because you should probably do a logical delete instead of a physical delete: Physical vs. logical / soft delete of database record?
Proper way to do this is to mark offending users as "inactive" so they can't login and you still maintain referential integrity of your database.
Deleting data from master table that has referential integrity links to some data in slave table is bad praxis.

MySQL: #1217 when dropping tables

I've created a simple database relation consisting of the entities entry and keywords.
Any entry can have n keywords, but each keyword may only exist once in the keywords table.
To realize this, I've created three tables: entries, keywords and entries2keywords. I'd like to maintain semantic integrity, so a DELETE or UPDATE procedure should propagate to the related tables.
Another requirement for the database setup is to be re-entrant, meaning that I can just re-run the creation script in which case all data should simply be deleted, as in DROP TABLE.
However, my current script fails with a #1217 error when re-running it:
#1217 - Cannot delete or update a parent row: a foreign key constraint fails
I've linked to the database script here because it's too large to paste.
So, than, dropping entries2keywords (table with constraints) will solve the issue :)

mySQL Restrict Cascade No Action settings

What is the best constraint to use on a forum table where users leave comments?
Assuming some users will be deleted at a later stage. if i delete a user who has commented, what happens to the users entry in the table?
Hope someone can explain.
There are two parts to this question:
how best to implement this? You can "soft-delete" user rows. This has the advantages of:
not losing user information
allowing users to be un-deleted
maintaining referential integrity without losing data linked to users
Soft-deleting can be implemented by adding another column to the users table, with a dateDeleted column -- if it's Null, then the user isn't deleted. I believe SO uses such a mechanism for deleting posts.
what does restrict cascade no action do? The MySQL docs say
RESTRICT: Rejects the delete or update operation for the parent table.
Specifying RESTRICT (or NO ACTION) is the same as omitting the ON
DELETE or ON UPDATE clause.
NO ACTION: A keyword from standard SQL. In MySQL, equivalent to
RESTRICT. InnoDB rejects the delete or update operation for the parent
table if there is a related foreign key value in the referenced table.
Some database systems have deferred checks, and NO ACTION is a
deferred check. In MySQL, foreign key constraints are checked
immediately, so NO ACTION is the same as RESTRICT.
In other words, if you use this, you won't be able delete rows if doing so would break referential integrity.

How to check the relation of a row in database table to another table before performing any deletion on it?

I am using MySql Database, I have a task that is,
Any item should not get deleted if
they are already linked to any other
module’s item, if asked for deletion
same is the case for Active and
Inactive.
Now, the data base I Have is not at all normalised. So can this achieved?
Could some help me out?
one option is to use triggers,
another option if you have innodb engine tables
ON UPDATE CASCADE ON DELETE RESTRICT

Linq to sql - delete some related records

I´m using linq to sql and I have a lot of tables with foreign keys leading to the UserId.
Is it possible to have some of these foreign tables cleaned upon deletion.
For example I want the users profile (other table) to be deleted automatically with the user but not the users forum posts.
Is this possible or do I have to handle this with code?
I think this link is very usefull.
LINQ to SQL does not support or
recognize cascade-delete operations.
If you want to delete a row in a table
that has constraints against it, you
must complete either of the following
tasks:
Set the ON DELETE CASCADE rule in the foreign-key constraint in the
database.
Use your own code to first delete the child objects that prevent the
parent object from being deleted.
I am not sure with code, but couldn't you set the Cascade on Delete option in SQL?