chevron_left chevron_right
Login Register invert_colors photo_library
Thread Rating:
  • 0 Vote(s) - 0 Average


filter_list MySQL question (ON DELETE CASCADE)
Author
Message
RE: MySQL question (ON DELETE CASCADE) #11
(09-24-2018, 09:41 PM)darkninja1980 Wrote:
(08-15-2018, 04:43 PM)mothered Wrote:
(08-15-2018, 03:44 PM)Mansispicher39 Wrote: Yea but in case when you have for example 10 nested relations you have to "manually" one by one remove the FKeys

Agree.

As mentioned, It Is messing around a bit, but you can have your SQL ready and only change the table names and Foreign keys accordingly.
For example:

* Delete the Foreign key from the `User Data` table (child table):

Code:
ALTER TABLE `User Data` DROP FOREIGN KEY `User Data_ibfk_1`;

* Do whatever you wish to the parent table (which Is `User IDs`), and then add the Foreign key back Into child table (which Is `User Data`).  I've used the ON UPDATE & ON DELETE CASCADE clauses for demonstration purposes:

Code:
ALTER TABLE `User Data` ADD FOREIGN KEY (mothered) REFERENCES `User IDs` (mothered) ON UPDATE CASCADE ON DELETE CASCADE;

It's not too time consuming to only alter the table names & respective Foreign keys.

I totally agree

Are you proficient In SQL?
[Image: AD83g1A.png]

Reply

RE: MySQL question (ON DELETE CASCADE) #12
(09-24-2018, 09:54 PM)mothered Wrote:
(09-24-2018, 09:41 PM)darkninja1980 Wrote:
(08-15-2018, 04:43 PM)mothered Wrote: Agree.

As mentioned, It Is messing around a bit, but you can have your SQL ready and only change the table names and Foreign keys accordingly.
For example:

* Delete the Foreign key from the `User Data` table (child table):

Code:
ALTER TABLE `User Data` DROP FOREIGN KEY `User Data_ibfk_1`;

* Do whatever you wish to the parent table (which Is `User IDs`), and then add the Foreign key back Into child table (which Is `User Data`).  I've used the ON UPDATE & ON DELETE CASCADE clauses for demonstration purposes:

Code:
ALTER TABLE `User Data` ADD FOREIGN KEY (mothered) REFERENCES `User IDs` (mothered) ON UPDATE CASCADE ON DELETE CASCADE;

It's not too time consuming to only alter the table names & respective Foreign keys.

I totally agree

Are you proficient In SQL?

yes I am
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

Reply

RE: MySQL question (ON DELETE CASCADE) #13
(09-24-2018, 11:40 PM)darkninja1980 Wrote:
(09-24-2018, 09:54 PM)mothered Wrote:
(09-24-2018, 09:41 PM)darkninja1980 Wrote: I totally agree

Are you proficient In SQL?

yes I am

Good to read.

When appropriate, we can converse about It.
[Image: AD83g1A.png]

Reply

RE: MySQL question (ON DELETE CASCADE) #14
(09-25-2018, 09:39 AM)mothered Wrote:
(09-24-2018, 11:40 PM)darkninja1980 Wrote:
(09-24-2018, 09:54 PM)mothered Wrote: Are you proficient In SQL?

yes I am

Good to read.

When appropriate, we can converse about It.

sure Smile
My IT skills that I know perfect is SQL, HTML ,css ,wordpress, PHP.
coding skills that I know is Java, JavaScript and C#

Reply






Users browsing this thread: 1 Guest(s)