auto-increment

How do I change the Auto Increment counter in MySQL?

喜你入骨 提交于 2019-12-03 01:08:06
I have an ID field that is my primary key and is just an int field. I have less than 300 rows but now every time someone signs up that ID auto inc is inputted really high like 11800089, 11800090, etc.... Is there a way to get that to come back down so it can follow the order (310,311,312) . Thanks! ALTER TABLE tbl AUTO_INCREMENT=310; Beware though, you don't want to repeat an ID. If the numbers are that high, they got that way somehow. Be very sure you don't have associated data with the lower ID numbers. http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html There may be a quicker

PHP short unique ID generation using auto_increment?

强颜欢笑 提交于 2019-12-03 00:25:24
I would like to generate a short, unique ID without having to check for collisions. I currently do something like this, but the ID I currently generate is random and checking for collisions in a loop is annoying and will get expensive if the number of records grows significantly. Normally worrying about collisions isn't an issue, but the unique ID I want to generate is a short unique string 5-8 characters, alpha-numeric, like tinyurl does. EDIT: I would like to start out with 5 characters and if I hit 60 million entries, then go to 6.. so on and so forth. To this end, I was thinking I could

Should I implement auto-incrementing in MongoDB?

送分小仙女□ 提交于 2019-12-03 00:14:19
问题 I'm making the switch to MongoDB from MySQL. A familiar architecture to me for a very basic users table would have auto-incrementing of the uid . See Mongo's own documentation for this use case. I'm wondering whether this is the best architectural decision. From a UX standpoint, I like having UIDs as external references, for example in shorter URLs: http://example.com/users/12345 Is there a third way? Someone in IRC Freenode's #mongodb suggested creating a range of IDs and caching them. I'm

MySQL: is out-of-order inserts into PK B+ Tree slower than out-of-order inserts into Secondary Index B+ Tree?

断了今生、忘了曾经 提交于 2019-12-02 21:29:21
问题 One of the main reasons given for using auto-increment PK in MySQL is that it guarantees all inserts into the clustered PK index will be in order and hence fast. I understand that. But what about secondary indexes? Say my table has a secondary index. Inserts will be in-order with respect to the PK clustered index, but out-of-order with respect to the secondary index B+ Tree. So wouldn't the inserts still be slow because MySQL needs to be constantly re-arranging the secondary index B+ Tree as

Set a custom identity value on a auto increment field

和自甴很熟 提交于 2019-12-02 21:06:30
问题 I have in my DB (Sql server 2008) a id column with auto numeric set on. I'm using EF and linq2entities In some specific scenario I would like to be able to set a custom Id number (obviously I'm totally sure this value is not repeated), for example I would use it to "fill" missing Id numbers caused by deletions. I want to keep the auto increment prop in database, the problem is that when I do the linq sentence, the database assign the next Id number, not the one that I like. Maybe it's a

MySQL auto-increment based on group

百般思念 提交于 2019-12-02 15:43:14
问题 The problem is related to autoincrement with mysql. What I'm trying to achieve is to increment an ID value based on the customer number. So basically i insert data sets without any order into a table. Each time a new customer is inserted, i would like the id column to be incremented, but of course kept for every row related to the customer, see the table below. Is there any way to achieve that via sql? I tried my luck with multiple primary keys and also looked into partioning, but was not

Should I implement auto-incrementing in MongoDB?

大城市里の小女人 提交于 2019-12-02 13:57:57
I'm making the switch to MongoDB from MySQL. A familiar architecture to me for a very basic users table would have auto-incrementing of the uid . See Mongo's own documentation for this use case . I'm wondering whether this is the best architectural decision. From a UX standpoint, I like having UIDs as external references, for example in shorter URLs: http://example.com/users/12345 Is there a third way? Someone in IRC Freenode's #mongodb suggested creating a range of IDs and caching them. I'm unsure of how to actually implement that, or whether there's another route I can go. I don't

Autoincrement, but omit existing values in the column

妖精的绣舞 提交于 2019-12-02 10:48:05
问题 I have a table: create table DB.t1 (id SERIAL,name varchar(255)); and insert some data: insert into DB.t1 (name) values ('name1'); insert into DB.t1 (id,name) values (5,'name2'); insert into DB.t1 (name) values ('name3'); insert into DB.t1 (name) values ('name4'); insert into DB.t1 (name) values ('name5'); insert into DB.t1 (name) values ('name6'); insert into DB.t1 (name) values ('name7'); select * from DB.t1; Then I can see: 1 name1 5 name2 2 name3 3 name4 4 name5 5 name6 -- how to make

MySQL auto-increment based on group

倾然丶 夕夏残阳落幕 提交于 2019-12-02 10:09:18
The problem is related to autoincrement with mysql. What I'm trying to achieve is to increment an ID value based on the customer number. So basically i insert data sets without any order into a table. Each time a new customer is inserted, i would like the id column to be incremented, but of course kept for every row related to the customer, see the table below. Is there any way to achieve that via sql? I tried my luck with multiple primary keys and also looked into partioning, but was not able to figure it out by myself. you can use a query like this: INSERT INTO autoinc (cid,info,customer)

Get back the primary key value after insertion to db2 table by KeyHolder

二次信任 提交于 2019-12-02 09:23:50
Good day, I have a table in db2, where the primary is_autoincrement is set to Yes . Means that everytime insert data to this table, no need to pass in the primary key value, because it will auto generate. However, I need to get back the primary key value after insertion. The code is something as follow: public integer insertRecord() { //insertion sql code here KeyHolder keyHolder = new GeneratedKeyHolder(); PreparedStatementCreatorFactory factory = new PreparedStatementCreatorFactory( getInsertBatch2( ), new int[] { java.sql.Types.TIMESTAMP, java.sql.Types.VARCHAR, java.sql.Types.SMALLINT,