0

My table's primary key 'rfidno' is Auto Increment. and I am trying to form a procedure and it's fairly simple, and it should work. I am geeting error at line 4.

SELECT max(rfidno)+1 FROM rfid_uidCREATE PROCEDURE rfidautomatic_INSERT(IN uid varchar(45))
BEGIN
insert into webtest.rfid_uid (rdidno,rfiduid) values (SELECT max(rfidno) + 1 FROM rfid_uid,uid);
END

CREATE PROCEDURE rfidautomatic_INSERT(IN uid varchar(45))
BEGIN
SELECT max(rfidno) + 1 INTO newPK FROM rfid_uid
insert into webtest.rfid_uid (rdidno,rfiduid) values (newPK,uid);
END
Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
SOAMad
  • 325
  • 5
  • 22
  • missing semi-colon at the end of line 3. Bigger problem is that what you are doing is potentially error prone by use of `MAX()` and concurrency. Much has been written about why not to do that – Drew Oct 30 '16 at 07:49
  • I understand your point. I am trying this alternatively, stii error at line 4, there are only 2 columns in table. CREATE PROCEDURE rfidautomatic_INSERT(IN uid varchar(45)) BEGIN DECLARE next_id INT; SET next_id = (SELECT AUTO_INCREMENT FROM webtest.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='rfid_uid'); SET NEW.field=next_id; insert into webtest.rfid_uid (next_id,rfiduid) values (newPK,uid); END – SOAMad Oct 30 '16 at 08:08
  • Ok you need a DELIMITER wrapper then. – Drew Oct 30 '16 at 08:21
  • it's new to me, is there any simple example you know? – SOAMad Oct 30 '16 at 08:23
  • Ex [1](http://stackoverflow.com/a/40092688) , [2](http://stackoverflow.com/a/39860634) if you still need help come chat in the [Campaigns](http://chat.stackoverflow.com/rooms/95290) chat room – Drew Oct 30 '16 at 08:26
  • it worked for me. – SOAMad Sep 24 '17 at 05:17

0 Answers0