Using Auto-Increment value in MYSQL Before Insert Trigger?

前端 未结 4 714
我寻月下人不归
我寻月下人不归 2020-12-10 04:36

The users table:

CREATE TABLE `users` (
  `id` int(8) unsigned NOT NULL AUTO_INCREMENT,
  `email` varchar(45) DEFAULT NULL,
  `username` varchar(16) DEFAULT          


        
4条回答
  •  囚心锁ツ
    2020-12-10 05:07

    PLEASE USE AFTER INSERT AND UPDATE

    Do not make auto_increment any column you want to manipulate explicitly. That can confuse an engine and cause serious problems. If no column you have used for primary key are auto_increment you can do anything you want with them via triggers. Sure generated values will be rejected if they violate the mandatory uniqness of the primary key.

提交回复
热议问题