List:General Discussion« Previous MessageNext Message »
From:Dan Greene Date:September 10 2003 7:40pm
Subject:RE: Foreign key update?
View as plain text  
What most data structures do is use foreign keys to the unique numerical id column, in
your case, company_id.  That way, if the company code changes, the id does not, and
therefore, no issues on update...



> -----Original Message-----
> From: Daevid Vincent [mailto:daevid@stripped]
> Sent: Wednesday, September 10, 2003 3:29 PM
> To: mysql@stripped
> Subject: Foreign key update?
> 
> 
> I see there is a way to DELETE or NULL a cascade, but is 
> there a way to
> UPDATE?
> 
> Here's what I mean. Given these rough table schemas. I'd like 
> to be able to
> UPDATE the company_code in the company_table, and have it 
> update the same
> rep_company_code in the rep_table.  Ie. So a company has a 
> certain code,
> then we change it. I want all the reps to get their codes updated too
> automagically... Is this possible now or in a future mySQL version?
> 
> CREATE TABLE company_table (
>   company_id mediumint(8) unsigned NOT NULL auto_increment,
>   company_name varchar(255) NOT NULL default '',
>   company_code varchar(15) NOT NULL default '',
>   company_referal_code varchar(15) NOT NULL default '',
>   company_phone varchar(20) NOT NULL default '',
>   company_fax varchar(20) NOT NULL default '',
>   company_url varchar(50) NOT NULL default '',
>   company_address1 varchar(70) NOT NULL default '',
>   company_address2 varchar(70) NOT NULL default '',
>   company_city varchar(50) NOT NULL default '',
>   company_state varchar(50) NOT NULL default '',
>   company_zip varchar(50) NOT NULL default '',
> ) TYPE=InnoDB;
> 
> 
> CREATE TABLE rep_table (
>   rep_id smallint(5) unsigned NOT NULL auto_increment,
>   rep_login varchar(15) NOT NULL default '',
>   rep_password varchar(15) NOT NULL default '',
>   rep_company_code varchar(15) NOT NULL default '',
>   rep_fname varchar(20) NOT NULL default '',
>   rep_lname varchar(20) NOT NULL default '',
>   rep_title varchar(50) NOT NULL default '',
> ) TYPE=InnoDB;
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    
> http://lists.mysql.com/mysql?unsub=1
> 
> 
Thread
Foreign key update?Daevid Vincent10 Sep
  • Re: Foreign key update?Victoria Reznichenko10 Sep
    • RE: Foreign key update?Daevid Vincent11 Sep
      • RE: Foreign key update?Daevid Vincent11 Sep
      • Re: Foreign key update?Victoria Reznichenko11 Sep
        • RE: Foreign key update and Error :: 1217Daevid Vincent11 Sep
RE: Foreign key update?Dan Greene10 Sep
Re: Foreign key update and Error :: 1217Heikki Tuuri11 Sep
  • RE: Foreign key update and Error :: 1217 with v4.0.15Daevid Vincent12 Sep
    • Re: Foreign key update and Error :: 1217 with v4.0.15Heikki Tuuri12 Sep
      • RE: Foreign key update and Error :: 1217 with v4.0.15 [SOLVED]Daevid Vincent12 Sep