How do I add foreign keys to two Innob tables so that they autoupdate each other?

I think you misunderstand how foreign keys work A reference from leads to users means that a row must already exist in users before a row in leads can reference it There's no way in SQL to make a dependent table automatically create a row in its parent table on demand You could do this with a trigger, I suppose. But not a foreign key constraints. Besides, the values to fill into the parent table must come from somewhere.

Either you need to specify them in an INSERT statement in your application or in a trigger, or else use the defaults defined for each column in the users table. Given that you have a unique constraint on users. Username I don't think this would be possible from a trigger Re: your followup question in the comment: No, a foreign key can't do what you're describing.

When you modify info in the leads table (the table with the foreign key), the only thing a foreign key can do is prevent the modification if you try to change the leads. User_id column to a value that is not found in the users table The foreign key in the child ( leads ) table can't change anything in the parent ( users ) table I'm not sure what is the source of your mistaken understanding. Did you read it somewhere or see someone do something like this?

I think you misunderstand how foreign keys work. A reference from leads to users means that a row must already exist in users before a row in leads can reference it. There's no way in SQL to make a dependent table automatically create a row in its parent table on demand.

You could do this with a trigger, I suppose. But not a foreign key constraints. Besides, the values to fill into the parent table must come from somewhere.

Either you need to specify them in an INSERT statement in your application or in a trigger, or else use the defaults defined for each column in the users table. Given that you have a unique constraint on users. Username, I don't think this would be possible from a trigger.Re: your followup question in the comment: No, a foreign key can't do what you're describing.

When you modify info in the leads table (the table with the foreign key), the only thing a foreign key can do is prevent the modification if you try to change the leads. User_id column to a value that is not found in the users table. The foreign key in the child (leads) table can't change anything in the parent (users) table.

I'm not sure what is the source of your mistaken understanding. Did you read it somewhere or see someone do something like this?

The first_name, last_name, company and email in users table is updated automatically when the leads table info is changed – Traveling_Monk Jun 17 '09 at 6:02.

I think you misunderstand how foreign keys work. A reference from leads to users means that a row must already exist in users before a row in leads can reference it. There's no way in SQL to make a dependent table automatically create a row in its parent table on demand.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions