I am struggling with this compound mysql. I am using the Start Transaction for the first time. So anything will be really helpful.
'Goal of this course',
ucourse_id = LAST_INSERT_ID();
VALUES(ucourse_id, 1, 1);
VALUES(ucourse_id, 1, 1, 0);
Missing semi-colon at the end of the first line. Ditto with
START TRANSACTION; .. .. COMMIT;
See START TRANSACTION, COMMIT, and ROLLBACK Syntax for a few examples.
as for your other issue, consider the below:
create table MyThings ( id int auto_increment primary key, thing varchar(100) not null ); insert MyThings(thing) values ('Fred, the pet Anchovy'); SET ucourse_id = LAST_INSERT_ID(); -- Error 1193: unknown sys var ... SET @ucourse_id = LAST_INSERT_ID(); -- YIPPIE, not a problem (user variable)
So, the first one above (
SET ucourse_id) choked, because it was assumed to be a LOCAL Variable (as it did not have an
@ sign). The whole thing was not running in a stored proc/function (I assumed). Local Variables need to have life breathed into them with a
declare k int; -- error, can't do this outside of a store proc/func etc
So, one should read up on User Variables vs Local Variables, when and how one can use them.