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
38
votes
6 answers

How do I change the Auto Increment counter in MySQL?

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…
Chris Olson
  • 1,021
  • 4
  • 12
  • 19
37
votes
4 answers

I need to auto_increment a field in MySQL that is not primary key

Right now, I have a table whose primary key is an auto_increment field. However, I need to set the primary key as username, date (to ensure that there cannot be a duplicate username with a date). I need the auto_increment field, however, in order to…
littleK
  • 19,521
  • 30
  • 128
  • 188
36
votes
7 answers

Django BigInteger auto-increment field as primary key?

I'm currently building a project which involves a lot of collective intelligence. Every user visiting the web site gets created a unique profile and their data is later used to calculate best matches for themselves and other users. By default,…
letoosh
  • 511
  • 2
  • 6
  • 13
36
votes
5 answers

Upper limit for autoincrement primary key in SQL Server

What is the upper limit for an autoincrement primary key in SQL Server? What happens when an SQL Server autoincrement primary key reaches its upper limit?
Dema
  • 6,867
  • 11
  • 40
  • 48
36
votes
4 answers

SQL-How to Insert Row Without Auto incrementing a ID Column?

I have a table that has a forced auto increment column and this column is a very valuable ID that is retained through out the entire app. Sorry to say it was poor development on my part to have this be the auto incrementing column. So, here is the…
SpoiledTechie.com
  • 10,515
  • 23
  • 77
  • 100
35
votes
2 answers

Reset autoincrement in Microsoft SQL Server 2008 R2

I created a primary key to be autoincrement. I added two rows: ID=1, ID=2 I deleted these two rows. I added a new row, but the new row's ID was: ID=3 How can I reset or restart the autoincrement to 1?
victorio
  • 6,224
  • 24
  • 77
  • 113
33
votes
5 answers

SQLite auto-increment non-primary key field

Is it possible to have a non-primary key to be auto-incremented with every insertion? For example, I want to have a log, where every log entry has a primary key (for internal use), and a revision number ( a INT value that I want to be…
iliaden
  • 3,791
  • 8
  • 38
  • 50
31
votes
7 answers

Create autoincrement key in Java DB using NetBeans IDE

I'm coming from MySQL world, please help. Is it possible to create autoincrement key from NetBeans IDE in JavaDB? Do you use some more advanced db clients, which? Thanks.
umpirsky
  • 9,902
  • 13
  • 71
  • 96
30
votes
18 answers

mysql Failed to read auto-increment value from storage engine

I am having mysql table with one id field as auto-increment . When I insert values to the table am getting error as 1467 - Failed to read auto-increment value from storage engine Also the show table status shows me that the field with auto…
ashu
  • 1,339
  • 7
  • 27
  • 43
30
votes
2 answers

SQL Server 2005 ROW_NUMBER() without ORDER BY

I am trying to insert from one table into another using DECLARE @IDOffset int; SELECT @IDOffset = MAX(ISNULL(ID,0)) FROM TargetTable INSERT INTO TargetTable(ID, FIELD) SELECT [Increment] + @IDOffset ,FeildValue FROM SourceTable WHERE…
Fragilerus
  • 1,829
  • 3
  • 15
  • 22
30
votes
3 answers

What size INT should I use for my autoincrement ids MySQL

Currently we're using INT(21)* for all autoincrement id columns in out 30+ table database. We are a blogging site, and have tables storing members, comments, blog posts and the like. I'm quite sure we will never reach the limit of our INT(21) id…
Michael Robinson
  • 29,278
  • 12
  • 104
  • 130
30
votes
7 answers

Defining Composite Key with Auto Increment in MySQL

Scenario: I have a table which references two foreign keys, and for each unique combination of these foreign keys, has its own auto_increment column. I need to implement a Composite Key that will help identify the row as unique using combination of…
Nirav Zaveri
  • 687
  • 1
  • 9
  • 28
30
votes
6 answers

Setting SQLAlchemy autoincrement start value

The autoincrement argument in SQLAlchemy seems to be only True and False, but I want to set the pre-defined value aid = 1001, the via autoincrement aid = 1002 when the next insert is done. In SQL, can be changed like: ALTER TABLE article…
Gorthon
  • 303
  • 1
  • 3
  • 5
29
votes
3 answers

How to make Primary key Auto increment while using Composite Primary keys in Room persistent library?

I am using Room persistent library. I have requirement to add two primary keys in one table and one of the primary key should be auto increment. I don't know exact syntax to achieve this. Below is my Model class: @Entity(tableName = "newsPapers",…
29
votes
2 answers

how to auto increment primary key in visual studio built in sql server?

I am using Visual Studio 2010 premium, and I created a database by using Visual Studio database tool. I set a field as primary key and I want to make it auto incremented. But when I look at the properties it is not active. I mean I cannot set using…