mysql触发器 [英] mysql triggers

查看:139
本文介绍了mysql触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是第一次使用触发器.
我有一个表名登录名,我想在其中注册新触发器之前触发触发器.触发器将检查新用户名是否已存在,如果用户已经存在则将限制新条目,并显示一条消息表明该用户已经存在.plz帮助.

hi all i am using triggers firsttime.
i have a table name login in which i want to fire trigger before new registration.the trigger will check if the new username already exist and will restrict the new entry if the user already exist and will show a message that user already exist.plz help.

推荐答案

为什么不使用存储过程?根据您的要求,这是实现存储过程的理想场所......最后使用触发器,您无法显示用户存在或不存在的消息...

有关触发器,在何处使用以及如何使用它的更多概念,请转到以下链接

http://dev.mysql.com/doc/refman/5.0/en/triggers.html [^ ]

http://dev.mysql.com/doc/refman/5.0/en/create- trigger.html [^ ]
Why you are not using stored procedure? As per your requirement this is a perfect place to implement Stored Procedure.....and last of all using trigger you can''t show a message that the user exists or not...

For more concept about trigger and where to use it and how to use it please go to the following links

http://dev.mysql.com/doc/refman/5.0/en/triggers.html[^]

http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html[^]


嗨Mylogics,

我的问题是为什么您要添加一个触发器来检查现有记录.
您可以只在用于在db表中插入记录的同一个sp中签入查询.

要创建触发器,您可以将代码编写为

Hi Mylogics,

My question is why you are adding a trigger to check existing records.
you can just check in query in same sp that is you are using to inserts records in db table.

to create trigger you can write code as

CREATE TRIGGER trgname
BEFORE INSERT ON my_table_name
FOR EACH ROW
BEGIN
IF something THEN
#do somthing
END IF;
END;


这篇关于mysql触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆