auto-increment

Is there any harm in resetting the auto-increment?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 13:38:52
I have a 100 million rows, and it's getting too big. I see a lot of gaps. (since I delete, add, delete, add.) I want to fill these gaps with auto-increment. If I do reset it..is there any harM? If I do this, will it fill the gaps?: mysql> ALTER TABLE tbl AUTO_INCREMENT = 1; Potentially very dangerous, because you can get a number again that is already in use. What you propose is resetting the sequence to 1 again. It will just produce 1,2,3,4,5,6,7,.. and so on, regardless of these numbers being in a gap or not. Update: According to Martin's answer, because of the dangers involved, MySQL will

Is Access's AutoNumber (Increment) guaranteed to increment?

坚强是说给别人听的谎言 提交于 2019-11-28 13:06:49
For a particular table, I have my ID field set to AutoNumber (Increment). If I add 5 rows to this table in quick succession, is each guaranteed to have a larger ID than the last? For instance, does autonumbering ever restart from 1 if some earlier values have been deleted? The only time I have ever had trouble with Access autonumbers is when, in error, I set the value of an autonumber key field to a number lower than the current maximum using an append query. Gaps had been created in the numbering by record deletions. Access allows you to force a value into an autonumber field, and sometimes

MySQL Auto Increment Custom Values

佐手、 提交于 2019-11-28 11:36:02
I am trying to make a column in a mysql database that auto increments by one but goes from 0-Z and then rolls. For example 000, 001, 002, ..., 009, 00A, 00B, ..., 00Z, 010, ..., 0ZZ, ..., 100. I would like to have the database create the column through an auto incrementing field. The ideas I have are: Create a column for each character that goes from 0-36, then auto increment row N (where N is the least significant digit) by 1. Then add a trigger on each column to add 1 to column N-1 when column N reaches 36. Create a table with 36 rows where each row contains a character 0-Z and pull the

How to turn off auto_increment in Rails Active Record

老子叫甜甜 提交于 2019-11-28 10:58:13
Is it possible to create primary key without auto_increment flag in ActiveRecord ? I can't do create table :blah, :id => false because I want to have primary key index on the column. I looked up documentation but didn't find anything useful. Is it possible to create primary key without auto_increment? Try this? create_table(:table_name, :id => false) do |t| t.integer :id, :options => 'PRIMARY KEY' end Blake Miller Okay, the question is old and the OP did not specify versions. None of the answers given here worked for me with these versions: mysql2 0.3.11 rails 3.2.13 mysql 5.5 I ended up going

sqlite: multi-column primary key with an auto increment column

二次信任 提交于 2019-11-28 10:25:56
I basically want to convert a table from mysql to sqlite with the following scheme: create table items ( id integer auto_increment, version integer default 0, primary key (id, version) ); Essentially, I want ID to auto increment whenever I insert anything into the table, with VERSION starting off at 0, but still allow multiple items with the same ID as long as VERSION is different. I'm trying to replicate this behavior with Sqlite however, I can't seem to get table creation working. It seems like you are only allowed one column as autoincrement and it has to be the primary key. If I make ID

Change the step auto_increment fields increment by

霸气de小男生 提交于 2019-11-28 09:17:21
How do I change the amount auto_increment fields in MySQL increment by from the default (1) to n? If you want to change autoincrement step from 1 to N then there is a solution. It could be done on MySQL server side: look for '--auto-increment-increment' startup option or use following command SET @@auto_increment_increment=2; , but be warned that this is a server wide change (all tables will increment by 2). Unortodox solutions could that could be considered: Launch two MySQL servers on same machine, with different ports (one with auto_increment_increment=1 other with auto_increment_increment

How to return the value of AUTO INCREMENT column in SQLite with VB6

时光毁灭记忆、已成空白 提交于 2019-11-28 08:31:54
I have a table in SQLite: CREATE TABLE "EventType" ( [EventTypeID] INTEGER PRIMARY KEY, [EventTypeName] VARCHAR(50) NOT NULL UNIQUE ); Since EventTypeID is an integer and a primary key, that automatically makes it an auto-incrementing column, and that works fine. I'd like to insert a row into the table and get the newly incremented value from VB6. Dim oRs as Recordset dim oCmd as new Command oCmd.ActiveConnection = GetConnection() oCmd.Source = "insert into EventType (EventTypeName) values ('blah')" oCmd.Execute Is there an automatic way to retrieve the newly created EventTypeID without having

Auto-increment a value in Firebase

落爺英雄遲暮 提交于 2019-11-28 06:34:31
How do I auto increment a value stored in Firebase from an Android client? Currently: I declare int id = 1 . When I increment, I see the values 2, 3 etc. being stored. That's fine, but when I re-run the project, id is set equal to 1 again. I want it to behave like a static variable, so I can create an id which will go from 1 to infinity without resetting. UPDATED FAILED I used the following to pass the Firebase reference and a string to the function incrementCounter. if(language_chosen.equalsIgnoreCase("english")) { Firebase publRef = f.child("Language").child("English").child("Message");

Mysql - Add auto_increment to primary key

纵然是瞬间 提交于 2019-11-28 06:28:50
I have a strange problem with mysql. I am trying to alter a table's column which is a primary key and has an auto_increment constraint defined on it. This is also a foreign key reference for multiple other tables. I need to change the length of this column in both , parent and all children. set foreign_key_checks=0; alter table Parent modify Identifier smallint(10) unsigned; alter table Child_1 modify FK_Identifier smallint(10) unsigned; alter table Child_2 modify FK_Identifier smallint(10) unsigned; alter table Child_3 modify FK_Identifier smallint(10) unsigned; alter table Child_4 modify FK

auto_increment usage in composite key

≯℡__Kan透↙ 提交于 2019-11-28 05:38:26
问题 I am having a table with the composite key emp_tbl( companyId int not null, empId int not null auto_increment, name varchar2, .... ... primary key(companyId,empId) ); In mysql whats happening is while i starts inserting the data Emp_tbl companyId empId 1 1 1 2 1 3 2 1 2 2 Note that when the companyId changes the auto_increament value is resetted to 1 again. I want to disable that. I mean i don't want to reset the auto_increament. I am expecting the result like this. companyId empId 1 1 1 2 1