In article [EMAIL PROTECTED],
Adaikalavan Ramasamy [EMAIL PROTECTED] writes:
This seems more like the solution I want. I am using perl-DBI and when
there is an error (i.e. duplicate insert), the rest of the scrip it not
executed. But this is gives me the following error. What am I doing
wrong
I am creating a small database that keeps track of users and assigns
them a unique user ID.
The problem is that sometimes the users might request to be added more
than once (i.e. click on the submit button multiple times). Therefore I
only want to add users if their details (here defined by both
Adaikalavan Ramasamy [EMAIL PROTECTED] wrote on 26/07/2004
16:05:23:
I am creating a small database that keeps track of users and assigns
them a unique user ID.
The problem is that sometimes the users might request to be added more
than once (i.e. click on the submit button multiple
Your model is flawed.
My son and I have the same first and last names.
Therefore, we could not be users on your system.
Adaikalavan Ramasamy wrote:
I am creating a small database that keeps track of users and assigns
them a unique user ID.
The problem is that sometimes the users might request to
Thanks Alec ! This works wonderfully.
But I have another related question. How do I write an IF ELSE command
with MYSQL. In this context, I want it to return myID if the record
already exists, otherwise insert into database.
This naive syntax does not work :
IF EXISTS (SELECT myID FROM tb WHERE
from http://dev.mysql.com/doc/mysql/en/INSERT.html:
14.1.4 INSERT Syntax
INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES ({expr | DEFAULT},...),(...),...
[ ON DUPLICATE KEY UPDATE col_name=expr, ... ]
...
If you specify the ON DUPLICATE KEY UPDATE
This seems more like the solution I want. I am using perl-DBI and when
there is an error (i.e. duplicate insert), the rest of the scrip it not
executed. But this is gives me the following error. What am I doing
wrong ?
mysql desc tb;
Adaikalavan Ramasamy wrote:
This naive syntax does not work :
IF EXISTS (SELECT myID FROM tb WHERE firstname='Jack' AND
lastname='Doe') ELSE (INSERT INTO tb(firstname, lastname) VALUES
('Jack', 'Doe');
Assuming you have the unique index on (firstname, lastname), just do
INSERT IGNORE INTO tb
Yes, this does what I want and does not produce an error (which caused
the remaining MYSQL syntax not to be executed). The firstname, lastname
was for example only. In my problem, these are two different identifiers
so I am not worried about multiple dual identifiers.
Thanks to Keith Ivey, Alec
Adaikalavan Ramasamy [EMAIL PROTECTED] wrote on 26/07/2004
16:31:44:
But I have another related question. How do I write an IF ELSE command
with MYSQL. In this context, I want it to return myID if the record
already exists, otherwise insert into database.
This naive syntax does not work
On Mon, 26 Jul 2004 17:47:37 +0100, Adaikalavan Ramasamy
[EMAIL PROTECTED] wrote:
This seems more like the solution I want. I am using perl-DBI and when
there is an error (i.e. duplicate insert), the rest of the scrip it not
executed. But this is gives me the following error. What am I doing
11 matches
Mail list logo