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
8
votes
3 answers

Find next value of AUTO_INCREMENT column in MySQL

I am using MySQL. I want to retrieve the next value that the AUTO_INCREMENT column will take without entering a new record. create table ABC(id int(10) NOT NULL AUTO_INCREMENT,name char(10)); In oracle I would have used sequencename.nextval(); But…
Xperiaz X
  • 216
  • 1
  • 6
  • 16
8
votes
2 answers

MySQL Load Data Infile auto incremented ID value

I want to insert an ID column to my table and get data of this table from a text file. For example my text file is like that: 12 1212 4989 121 121 23 123 110 789 99 234 544 ... and it has approximately 20M rows. I…
JoshuaJeanThree
  • 1,382
  • 2
  • 22
  • 41
8
votes
4 answers

Un-committed database transactions and auto-increment columns

I encountered some curious behavior today and was wondering if it is expected or standard. We are using Hibernate against MySQL5. During the course of coding I forgot to close a transaction, I presume others can relate. When I finally closed the…
Dexygen
  • 12,287
  • 13
  • 80
  • 147
8
votes
3 answers

Auto increment a value in Django with respect to the previous one

Is there a way to autoincrement a field with respect to the previous one...e.g if the previous record has the value 09-0001, then the next record should be assigned 09-0002 and so one...ideas? I'm thinking of overriding the save method, but how…
Stephen
7
votes
5 answers

How can I make a primary key as AUTOINCREMENT

I have table in Database and the primry key is 'ID', Just I want to ask how can I make it AUTOINCREMENT I know that's esay Q, but I dont know how can I do it. thanks
turki2009
7
votes
5 answers

How is the MySQL auto_increment step size determined

I have a table of web pages, with the primary key as hash of the URL, and an auto_increment ID column, which is also a unique key. What I'm a bit confused by is why successive inserts don't increment the ID field by 1. When I first created the table…
Vijay Boyapati
  • 7,632
  • 7
  • 31
  • 48
7
votes
1 answer

MySQL, C++ - Programmatically, How does MySQL Autoincrement Work?

From the latest source code (not certain if it's C or C++) of MySQL, how does it do an autoincrement? I mean, is it efficient in that it stores like a metadata resource on the table where it last left off, or does it have to do a table scan to find…
Volomike
  • 23,743
  • 21
  • 113
  • 209
7
votes
3 answers

MySQL: Forgot to set Auto Increment

I set up a database, with an auto incrementing column that was meant to be an ID. The problem is that I forgot to check off auto increment when creating the table in phpMyAdmin...and didn't notice until now! So what I have is something like: ID | …
Nick Budden
  • 621
  • 9
  • 20
7
votes
5 answers

Oracle: insert without columns specification

I have an oracle table with a sequence and a trigger to autoincrement a column. Now I want to make an insert. Normally I should write: INSERT INTO table (column1, column2,...) VALUES (value1, value2) but I just want to insert a record with no…
Neo
  • 1,337
  • 4
  • 21
  • 50
7
votes
0 answers

Why does SQLITE create empty sqlite_sequence table?

I have a database of several tables in which the first field is defined as: 'ID' INTEGER NOT NULL UNIQUE ... PRIMARY_KEY('ID') I do not use the AUTOINCREMENT keyword for any of these tables yet my db contains an empty sqlite_sequence table which I…
MartinL
  • 71
  • 1
  • 2
7
votes
2 answers

Scoped AUTO_INCREMENT in MySQL?

I am using MySQL in a rails application. I have a users table (standard stuff like id, name etc) and a books table (again with id, user_id and title etc). I would like to have a column (lets call it user_book_id) that should be auto incremented like…
unamashana
  • 635
  • 1
  • 5
  • 14
7
votes
5 answers

How do i prevent the duplicate id from the imported table in MariaDB?

(Before that, i apologize for my bad English) I have study cases like this: I am currently having a trouble with my Web Application. I made a Web application for a certain company. I made the app using CodeIgniter 3. I built the database using…
Gagantous
  • 432
  • 6
  • 29
  • 69
7
votes
1 answer

Are race conditions possible with PostgreSQL auto-increment

Are there any conditions under which records created in a table using a typical auto-increment field would be available for read out of sequence? For instance, could a record with value 10 ever appear in the result of a select query when the record…
Steve Jorgensen
  • 11,725
  • 1
  • 33
  • 43
7
votes
4 answers

How do I view the auto_increment value for a table

The only way I know is show create table MyTable
700 Software
  • 85,281
  • 83
  • 234
  • 341
7
votes
5 answers

Prevent InnoDB auto increment ON DUPLICATE KEY

I am currently having problems with a primary key ID which is set to auto increment. It keeps incrementing ON DUPLICATE KEY. For Example: ID | field1 | field2 1 | user | value 5 | secondUser | value 86 | thirdUser | value From the…
0x0
  • 363
  • 1
  • 4
  • 19