User table, ID number must be unique, mobile phone number, email address must be unique Implementation:The table structure does not need to be changed. A primary key ID plus index implementation As shown in the figure, set the index type to Unique to select the only field and give it a name. The index method is btree. Ok~ Supplement: MySQL implements multi-table primary key non-duplicate There are two tables in the same database, and the fields are the same, but the stored data needs to be distinguished. But the primary key cannot be repeated. The specific implementation is as follows: Create a new database mytestCreate new user table and admin tableCREATE TABLE `user` ( `user_id` INT(11) NOT NULL, `user_name` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL, `phone` VARCHAR(255) NOT NULL, PRIMARY KEY (`user_id`) ) COMMENT = 'User table' COLLATE='utf8_general_ci' ENGINE=InnoDB; CREATE TABLE `admin` ( `user_id` INT(11) NOT NULL, `user_name` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL, `phone` VARCHAR(255) NOT NULL, PRIMARY KEY (`user_id`) ) COMMENT = 'Administrator table' COLLATE='utf8_general_ci' ENGINE=InnoDB; Create a new sequence table: CREATE TABLE `sequence` ( `seq_name` VARCHAR(50) NOT NULL, `current_val` INT(11) NOT NULL, `increment_val` INT(11) NOT NULL DEFAULT '1', PRIMARY KEY (`seq_name`) ) COMMENT = 'Sequence List' COLLATE='utf8_general_ci' ENGINE=InnoDB; Add a new sequence: INSERT INTO sequence VALUES ('seq_test', '0', '1'); Create a currval function to get the current value of the sequence: delimiter # create function currval(v_seq_name VARCHAR(50)) returns integer(11) begin declare value integer; set value = 0; select current_val into value from sequence where seq_name = v_seq_name; return value; end; Query the current value: select currval('seq_test'); Create a nextval function to get the next value of the sequence: delimiter # create function nextval (v_seq_name VARCHAR(50)) returns integer(11) begin update sequence set current_val = current_val + increment_val where seq_name = v_seq_name; return currval(v_seq_name); end; Query the next value select nextval('seq_test'); Specific implementation:<insert id="addUser" parameterType="User"> <selectKey keyProperty="userId" resultType="int" order="BEFORE"> select nextval('seq_test'); </selectKey> insert into user(user_id,user_name,password,phone) values (#{userId},#{userName, jdbcType=VARCHAR},#{password, jdbcType=VARCHAR}, #{phone, jdbcType=VARCHAR}) </insert> <insert id="addAdmin" parameterType="Admin"> <selectKey keyProperty="userId" resultType="int" order="BEFORE"> select nextval('seq_test'); </selectKey> insert into admin(user_id,user_name,password,phone) values (#{userId},#{userName, jdbcType=VARCHAR},#{password, jdbcType=VARCHAR}, #{phone, jdbcType=VARCHAR}) </insert> Final implementation:The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me. You may also be interested in:
|
<<: New ways to play with CSS fonts: implementation of colored fonts
>>: Tomcat configuration and how to start it in Eclipse
Designing navigation for a website is like laying...
【content】: 1. Use background-image gradient style...
I just happened to encounter this small requireme...
React Native is a cross-platform mobile applicati...
Is there any way to remove spaces from a certain ...
<br />When you click the link, the web page ...
This article shares with you the specific code of...
Recently, I have been learning to use nginx to pl...
Hello everyone, I wonder if you have the same con...
Whitespace rules in HTML In HTML, multiple spaces...
Table of contents 1. Retrieve via --skip-grant-ta...
mysql efficient query MySQL sacrifices group by t...
First check the /etc/group file: [root@localhost ...
background Before we know it, a busy year is comi...
Table of contents nonsense Functions implemented ...