Mysql Data insertion failure to prevent auto-growth primary key growth method, mysql primary key
Mysql sets the ID of the auto-increment primary key, and the auto-increment ID that fails to be inserted is also added. For example,
Oracel ALTER TABLE adds a primary key to the table primary key
Sql>Sql> CREATE TABLE EMP (empno number (4) is not NULL,2 ename varchar2 (10),3 Job Varchar2 (9),4 Mgr Number (4),5 HireDate Date,6 Sal Number (7, 2),7 Comm Number
auto-incrementing primary key. Before using PHP to insert data, I imported some data, similar to the following:
1 xx
2 ss
3 rr
Then insert it in PHP. After multiple inserts, it is as follows:
1 xx
2 ss
3 rr
4 ww
1 xx
2 ss
3 rr
5 ee
4 ww
1 xx
2 ss
3 rr
6 tt
5 ee
4 ww
However, after I only import the table structure, it is normal to use PHP to insert it. However, at the time of insertion, the id does not
[PHP] MySQL obtains the primary key (auto-increment ID) and mysql primary key of the inserted data.
To prevent primary key conflicts, auto-increment (auto_increment type) fields are often used in DB Design. Therefore, the
number)Insert into table values (serial number as ID, other columns);EndProgram code Con.commit ();Serial Number Stored procedure:Update tab Statistics Field +1Update tab Final serial number set type + Month Day + complement 0 bit + statistic fieldSelect final serial number;//as Primary key-----------------------------------------------------------------But where does the problem occur, since it is a
. However, at the time of insertion, the id does not start from 0, but is a relatively large number. it should be the next of the last id used, as shown in the following code:
40 gg
41 ii
How can we make it start from 0? (Or 1 ?)
I really don't want to waste points. I have a lot of problems. I 'd like to save some points. If there is a satisfactory answer, I will add points. if it can be completely solved, I will add 80 points, including directly deleting the records in the table in the phpmya
Oracle primary key deletion, joint primary key Creation1. Delete the primary key alter table tablename drop PRIMARY_KEY execute the preceding SQL statement to delete the
1. Delete the primary key ALTER table TABLENAME drop primary_key Run the above SQL to remove the primary key; Assuming that the ALTER TABLE TABLENAME drop CONSTRAINTS COLUMN Cascad is not successful E --delete constraint alter TABLE TABLENAME DISABLE Primary_column; --Set th
Hibernate primary key generation policy and hibernate primary key policyThe All generators implement the org. hibernate. id. IdentifierGenerator interface. This is a very simple interface; some applications can choose to provide their own specific implementations. Of course, Hibernate provides many built-in implementat
The Oracle view does not have a primary key by default. Therefore, when you use hibernate to generate a java class in reverse direction, a composite primary key is automatically used to generate a class with the class name + ID, which makes it difficult for later development.
The Oracle view does not have a
the next, such as:
+ GG
+-II
How do you make it start from 0? (Or is it 1?) )
Really do not want to waste points, my problem is more, points or save a bit of it. If there is a satisfactory answer I will add points, if it can be fully resolved I will add 80 points, including the direct deletion of the phpMyAdmin database in the table records will not be a problem.
------Solution--------------------
Run SQL:
ALTER TABLE ' Your table name ' Auto_incre
id 7-11, corresponding to the number of SQL statements for inserting data. Because we have not submitted the file, this result can only be seen in client 2.
Here we can see that the auto-increment primary key is globally unique. If a transaction is rolled back, the auto-increment part will not be affected. The auto-increment
ainner join position pp on pp. lngpositionid =. flnginpositionidleft join employee e on e. lngemployeeid =. flngemployeeidwhere. flnginid
The preceding is a view in Oracle. This view is always not added several times.
The view is not added after vertices.
The reason is that in view SQL, the union all keyword EF cannot infer which is the primary key.
Solution:
At some point, our business needs to execute the INSERT statement before returning the primary key, you can use the primary key mappingFirst, define SQL, take MySQL as an example1 ID= "AddUser" usegeneratedkeys= "true" keyproperty= "User _id " parametertype=" Com.entity
can be fully resolved I will add 80 points, including the direct deletion of the phpMyAdmin database in the table records will not be a problem.
Reply to discussion (solution)
Run SQL:
ALTER TABLE ' Your table name ' Auto_increment=1
The precondition is that the current table data is empty;
The first one is how to get rid of the ORDER BY clauseOne more time.The second is when the last record inserted in PHP is viewed in phpmyadmin. Why not
Hibernate the primary key generation policy
All primary key generators implement the Org.hibernate.id.TableLoGenerator interface
The following is a discussion of the shortcut name of the Hibernate built-in generator and the use of
Divided into the following categories:
Increment,identity,sequence,
Hilo, Seqhilo,
By default, the Oracle view does not have a primary key. Therefore, when a java class is generated in reverse direction using hibernate, a composite primary key is automatically used to generate a class name + ID, Which is troublesome for later development.
Therefore, adding a pri
part of the relational model theory, such as a Primary Key or a Foreign Key, used for data integrity check and uniqueness constraints. The Index is at the implementation level. For example, you can create an Index on any column of the table. When the column to be indexed is in the Where condition of the SQL statement,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.