Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use functions and triggers to realize self-increment of non-primary keys in mysql

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces how to use functions and triggers in mysql to achieve non-primary key self-increment, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Function

Set global log_bin_trust_function_creators=1;DELIMITER / / DROP function if exists incNum//CREATE FUNCTION incNum () RETURNS int (11) BEGINset @ tem=1;select card_number into @ tem from `vip_ Card` order by card_number desc limit 1 position set @ tem=@tem+1;return @ tem;END//DELIMITER; select incNum ()

Trigger

CREATE TRIGGER incNum BEFORE INSERT ON vip_card FOR EACH ROW BEGIN set @ tem=1; select card_number into @ tem from `vip_ Card` order by card_number desc limit 1; set new.card_number=@tem+1; end has shared here about how to use functions and triggers to achieve non-primary key increment in mysql. I hope the above can be helpful and learn more. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report