general theory behind "primary_key" & "auto_increment" flags, and ON DUPLICATE KEY UPDATE ?
general theory behind "primary_key" & "auto_increment" flags, and ON DUPLICATE KEY UPDATE ?
am 15.07.2009 15:21:01 von Govinda
Reading docs.. I want to be sure of things... have your verification
of my understanding(s)-
Does setting a mysql db column (say "myPrimarykeyID") with the
'primary_key' & 'auto_increment' flags totally negate the logic for
ever having to use ON DUPLICATE KEY UPDATE in an INSERT?
Or is it that I can do an INSERT with SET
myPrimarykeyID=someAlreadyExistingVal, a=1, b=2.... ON DUPLICATE KEY
UPDATE a=edited1, b=edited2 ...
I am trying to learn/work out the mysql/php code that will allow me to
either create *or* edit a record, in one fell swoop.
Thanks for any insight!
-Govinda
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: general theory behind "primary_key" & "auto_increment"
am 15.07.2009 15:37:40 von Phpster
On Wed, Jul 15, 2009 at 9:21 AM, Govinda wrot=
e:
> Reading docs.. =A0I want to be sure of things... =A0have your verificatio=
n of my
> understanding(s)-
>
> Does setting a mysql db column (say "myPrimarykeyID") with the 'primary_k=
ey'
> & 'auto_increment' flags totally negate the logic for ever having to use =
ON
> DUPLICATE KEY UPDATE in an INSERT?
>
> Or is it that I can do an INSERT with SET
> myPrimarykeyID=3DsomeAlreadyExistingVal, a=3D1, b=3D2.... =A0ON DUPLICATE=
KEY UPDATE
> =A0a=3Dedited1, b=3Dedited2 ...
>
> I am trying to learn/work out the mysql/php code that will allow me to
> either create *or* edit a record, in one fell swoop.
>
> Thanks for any insight!
> -Govinda
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
If that is the goal use the REPLACE INTO sql syntax
You really don't want to allow duplicates in primary keys, that
completely negates the usefulness of that key
--=20
Bastien
Cat, the other other white meat
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: general theory behind "primary_key" & "auto_increment" flags, and ON DUPLICATE KEY UPDATE ?
am 15.07.2009 22:40:50 von Govinda
--Apple-Mail-9-947794664
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit
On Jul 15, 2009, at 7:37 AM, Bastien Koert wrote:
> On Wed, Jul 15, 2009 at 9:21 AM,
> Govinda wrote:
>> Reading docs.. I want to be sure of things... have your
>> verification of my
>> understanding(s)-
>>
>> Does setting a mysql db column (say "myPrimarykeyID") with the
>> 'primary_key'
>> & 'auto_increment' flags totally negate the logic for ever having
>> to use ON
>> DUPLICATE KEY UPDATE in an INSERT?
>>
>> Or is it that I can do an INSERT with SET
>> myPrimarykeyID=someAlreadyExistingVal, a=1, b=2.... ON DUPLICATE
>> KEY UPDATE
>> a=edited1, b=edited2 ...
>>
>> I am trying to learn/work out the mysql/php code that will allow me
>> to
>> either create *or* edit a record, in one fell swoop.
>>
>> Thanks for any insight!
>> -Govinda
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
> If that is the goal use the REPLACE INTO sql syntax
>
> You really don't want to allow duplicates in primary keys, that
> completely negates the usefulness of that key
well isn't it that in order for the REPLACE INTO to replace the old
row I have to try and replace a row with an already existing
uniqueID? The same thing I would do to cause the INSERT.. SET .. ON
DUPLICATE KEY UPDATE to kick in? Don't both methods equally
effectively 'prevent duplicate primary keys from occurring'?
-G
--Apple-Mail-9-947794664--
Re: general theory behind "primary_key" & "auto_increment"
am 15.07.2009 22:56:28 von Phpster
On Wed, Jul 15, 2009 at 4:40 PM, Govinda wrot=
e:
>
> On Jul 15, 2009, at 7:37 AM, Bastien Koert wrote:
>
>> On Wed, Jul 15, 2009 at 9:21 AM, Govinda
>> wrote:
>>>
>>> Reading docs.. =A0I want to be sure of things... =A0have your verificat=
ion of
>>> my
>>> understanding(s)-
>>>
>>> Does setting a mysql db column (say "myPrimarykeyID") with the
>>> 'primary_key'
>>> & 'auto_increment' flags totally negate the logic for ever having to us=
e
>>> ON
>>> DUPLICATE KEY UPDATE in an INSERT?
>>>
>>> Or is it that I can do an INSERT with SET
>>> myPrimarykeyID=3DsomeAlreadyExistingVal, a=3D1, b=3D2.... =A0ON DUPLICA=
TE KEY
>>> UPDATE
>>> =A0a=3Dedited1, b=3Dedited2 ...
>>>
>>> I am trying to learn/work out the mysql/php code that will allow me to
>>> either create *or* edit a record, in one fell swoop.
>>>
>>> Thanks for any insight!
>>> -Govinda
>>>
>>> --
>>> PHP Database Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>> If that is the goal use the REPLACE INTO sql syntax
>>
>> You really don't want to allow duplicates in primary keys, that
>> completely negates the usefulness of that key
>
> well isn't it that in order for the REPLACE INTO to replace the old row I
> have to try and replace a row with an already existing uniqueID? =A0The s=
ame
> thing I would do to cause the INSERT.. =A0SET .. ON DUPLICATE KEY UPDATE =
to
> kick in? =A0Don't both methods equally effectively 'prevent duplicate pri=
mary
> keys from occurring'?
>
> -G
REPLACE will do the same thing as an DELETE where KEY =3D and then an
INSERT or just does an insert if the KEY is not present
--=20
Bastien
Cat, the other other white meat
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php