Questions tagged [auto-increment]

a database constraint that automatically increases from the last record when making an INSERT

AUTO_INCREMENT is a flag set on a field in a database table that forces the RDBMS to create a unique identifier for the record. This is useful when no other obvious primary key field is apparent in a record.

Useful questions

Related tags

2677 questions
19
votes
6 answers

Add auto increment back to primary key column in Rails

By mistake I removed the autoincrement option from id field of my table. Can anyone tell me how I can reinsert the option of autoincrement back through migration?
Somesh
19
votes
1 answer

Mysql - Add auto_increment to primary key

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…
Ricko M
  • 1,784
  • 5
  • 24
  • 44
19
votes
6 answers

using Notepad++ how can i make a macro type situation in which a number increments?

for example i have about 500 lines. in the beginning of each line i want to add a number. so in line 1 i would want "1)" and then line 2 i would want "2)" i know i can do a macro in n++, but it wouldn't be incremental. is there any possible way to…
Bilal
  • 193
  • 1
  • 1
  • 4
19
votes
2 answers

Trying to do LOAD DATA INFILE with REPLACE and AUTO_INCREMENT

I am trying to load a file onto a MySQL database, having the primary key auto_incremented and I would like the data to be updated if i find any duplicate rows. However, the REPLACE keywords only works on primary key, which is auto generated so i'm…
jonasMcFerreira
  • 281
  • 1
  • 2
  • 9
18
votes
2 answers

Set AUTO_INCREMENT using SqlAlchemy with MySQL on Columns with non-primary keys?

I can't figure out how to set AUTO_INCREMENT on a UNIQUE column using SqlAlchemy 0.6.0 with MySQL 5. I know this can be done in MySQL, but I don't want to have to distribute extra .sql scripts in order to set up the databases for my application. I…
anthony.theocharis
  • 181
  • 1
  • 1
  • 6
17
votes
2 answers

Too many auto increments with ON DUPLICATE KEY UPDATE

I have a basic table with columns: id (primary with AI) name (unique) etc If the unique column doesn't exist, INSERT the row, otherwise UPDATE the row.... INSERT INTO pages (name, etc) VALUES 'bob', 'randomness' ON DUPLICATE KEY UPDATE name =…
Nathan Waters
  • 1,173
  • 4
  • 13
  • 23
17
votes
7 answers

SQL - INSERT and catch the id auto-increment value

What is the best way to get the auto-id value in the same SQL with a SELECT? A forum said adding this "; has Return Scope_Identity()" in the end of the SQL works in ASP. Is there a corresponding way in PHP?
Kaptah
  • 9,785
  • 4
  • 22
  • 19
17
votes
6 answers

How to turn off auto_increment in Rails Active Record

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…
Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327
17
votes
2 answers

MySQL Auto Increment Columns on TRANSACTION, COMMIT, and ROLLBACK

When using MySQL START TRANSACTION and the decision is made by MySQL to roll back - In the case that a table had an AUTO_INCREMENT column - does the column get... decremented during the roll back? Or should it? I am having some issues where the…
user1502852
17
votes
2 answers

What is the limit of auto_increment (integer) in mysql

I have a mysql database in which i am using auto_increment(integer), can you tell me till what integer it can incremented. How we can increase the limit of auto_increment?
Eka
  • 14,170
  • 38
  • 128
  • 212
16
votes
3 answers

UUID versus auto increment number for primary key

Why should I choose UUID over an auto increment number for my entity's primary key? What are the pros and cons?
viam0Zah
  • 25,949
  • 8
  • 77
  • 100
16
votes
7 answers

Troubles of adding a new ID (auto increment) after table exist

I have a table with 38.000 records, but without any auto increment column like ID. Now I have to add an ID column, and I'm wondering could there be troubles?
Bobo
  • 197
  • 1
  • 2
  • 7
16
votes
5 answers

Auto increment a value in firebase with javascript

Hello I'm working on some firebase project and i can save my datas via javascript into firebase database. But i couldn't figure it out to auto increment child value (my child value is duyuru, you can see the details in the below) of my database. I'm…
16
votes
3 answers

Regular Expression Notepad increment numbers in every line

I've to add numbers incrementally in the beginning of every line using Notepad++. It is the not the very beginning. But, like when ID = '1' then data when ID = '2' then data when ID = '3' then data . . . . when ID = '700' then Is…
Rohin
  • 516
  • 3
  • 7
  • 20
16
votes
5 answers

Clearing LAST_INSERT_ID() before inserting to tell if what's returned is from my insert

LAST_INSERT_ID() returns the most recent id generated for the current connection by an auto increment column, but how do I tell if that value is from the last insert and not from a previous insert on the same connection? Suppose I am using a…
Bohemian
  • 412,405
  • 93
  • 575
  • 722