您的位置:首页 > 数据库 > MySQL

mysql触发器的使用

2017-10-11 11:18 393 查看
use t14test

show tables

drop table if exists uuidTest

create table uuidTest(

  testId VARCHAR(36) not NULL DEFAULT '1',

  testData VARCHAR(32),

  PRIMARY KEY(`testId`)

)

/*创建触发器*/

/*

 * terminal创建存储过程需要定义分隔符

 * delimiter //

 * */

create trigger tri_auto_uuid

before insert

on uuidTest

for each ROW

BEGIN

if new.testId = '1' THEN set new.testId = (select uuid());

end if;

END

/*删除触发器*/

drop trigger if exists tri_auto_uuid

/*插入数据*/

insert into uuidTest(testData)VALUES('一条数据') 

select * from uuidTest
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: