From: Michael Dykman Date: January 21 2011 6:26pm Subject: Re: CURRENT insert ID List-Archive: http://lists.mysql.com/mysql/224184 Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable You don't need to do an update: ... new.xxx =3D new.id ... On Fri, Jan 21, 2011 at 12:20 PM, Jerry Schwartz wrote: >>-----Original Message----- >>From: Jerry Schwartz [mailto:jerry@stripped] >>Sent: Friday, January 21, 2011 11:56 AM >>To: 'Michael Dykman'; 'MySql' >>Subject: RE: CURRENT insert ID >> >>>-----Original Message----- >>>From: Michael Dykman [mailto:mdykman@stripped] >>>Sent: Friday, January 21, 2011 11:50 AM >>>To: MySql >>>Subject: Re: CURRENT insert ID >>> >>>I think an ON INSERT TRIGGER would take care of this; can't think of >>>any other way. =A0Using last_insert_id() in the argument list would >>>likely yield you the previous value (which might not even related to >>>your table. >>> > [JS] Alas, you cannot update a record in a trigger if the record is in th= e > same table as the trigger. > > > CREATE TRIGGER xx AFTER UPDATE ON t > FOR EACH ROW > =A0UPDATE t SET f1 =3D 7; > > > That's illegal. > > Right now, I'm stumped. > >>>Having siad that.. =A0 odd requirement. >>> >>[JS] You don't know the half of it. >> >>Thanks. >> >>Regards, >> >>Jerry Schwartz >>Global Information Incorporated >>195 Farmington Ave. >>Farmington, CT 06032 >> >>860.674.8796 / FAX: 860.674.8341 >>E-mail: jerry@stripped >>Web site: www.the-infoshop.com >> >> >> >>> =A0- michael dykman >>> >>>ps =A0-- sorry for the duplicate Jerry, reply-to policy on this list is >>>forever tripping me up. >>> >>> >>>> >>>> On Fri, Jan 21, 2011 at 11:41 AM, Jerry Schwartz wro= te: >>>>> Here it is in a nutshell: >>>>> >>>>> >>>>> >>>>> I have a field that needs to be set equal to the auto-increment ID as= a >>>record is entered. I don't know how to do this without a subsequent UPDA= TE >>>(which I can do with a trigger). Is there any way to avoid the cost of a= n >>>UPDATE? >>>>> >>>>> >>>>> >>>>> Here's a more concrete description of the problem: >>>>> >>>>> >>>>> >>>>> CREATE TABLE t ( >>>>> >>>>> id INT(11) AUTO-INCREMENT PRIMARY, >>>>> >>>>> xxx INT(11) >>>>> >>>>> ); >>>>> >>>>> >>>>> >>>>> When a record is added to table `t`, I need to set `xxx` to the value >>>generated for `id`. (`xxx` might be changed later.) >>>>> >>>>> >>>>> >>>>> Is there anything clever I can do? >>>>> >>>>> >>>>> >>>>> Regards, >>>>> >>>>> >>>>> >>>>> Jerry Schwartz >>>>> >>>>> Global Information Incorporated >>>>> >>>>> 195 Farmington Ave. >>>>> >>>>> Farmington, CT 06032 >>>>> >>>>> >>>>> >>>>> 860.674.8796 / FAX: 860.674.8341 >>>>> >>>>> E-mail: =A0 jerry@stripped >>>>> >>>>> Web site: =A0 www.the-infoshop.com >>>>> >>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> -- >>>> =A0- michael dykman >>>> =A0- mdykman@stripped >>>> >>>> =A0May the Source be with you. >>>> >>> >>> >>> >>>-- >>> - michael dykman >>> - mdykman@stripped >>> >>> May the Source be with you. >>> >>>-- >>>MySQL General Mailing List >>>For list archives: http://lists.mysql.com/mysql >>>To unsubscribe: =A0 =A0http://lists.mysql.com/mysql?unsub=3Djerry@stripped= .jp >> >> >> >> >> >>-- >>MySQL General Mailing List >>For list archives: http://lists.mysql.com/mysql >>To unsubscribe: =A0 =A0http://lists.mysql.com/mysql?unsub=3Djerry@stripped.= jp > > > > > --=20 =A0- michael dykman =A0- mdykman@stripped =A0May the Source be with you.