I'm seeing a large number of examples on how to do this in MySQL/SQLYog but everything I try gives me an error. I must be misunderstanding something critical here or something, it seems like it should be so simple.
I want to make a column use UUID() as it's default and I've read that triggers are the way to go about this.
I have tried the following methods and they all fail:
CREATE TRIGGER `tips`.`TableKey` BEFORE INSERT ON `tips`.`TableKey` FOR EACH ROW
SET `tips`.`TableKey` = UUID();
error: Unknown system variable 'TableKey'
CREATE TRIGGER UUID_Trigger
AFTER INSERT ON `databasename`.`tips`
FOR EACH ROW
SET `databasename`.`tips`.`TableKey` = UUID();
error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.TableKey
= uuid()' at line 4
DELIMITER $$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
TRIGGER `databasename`.`tips_uuid` BEFORE INSERT
ON `databasename`.`tips`
FOR EACH ROW BEGIN
IF `databasename`.tips.TableKey IS NULL
THEN
SET `databasename`.tips.TableKey = UUID();
END IF;
END$$
DELIMITER ;
error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.TableKey = UUID(); END IF; END' at line 8
CREATE TRIGGER tips_uuid_default
BEFORE INSERT ON tips
FOR EACH ROW
IF tips.TableKey IS NULL
THEN
SET tips.TableKey = UUID();
END IF;
error: Error Code: 1193 Unknown system variable 'TableKey'
and
Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END IF' at line 1
Can anyone let me know what I'm doing wrong here? It never seems to know what the TableKey column is so I must be specifying the tables or columns incorrectly?