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
>
>