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

multiple auto increment in mysql

I'm using php and mysql. I have a table with the id column set to auto increment as the primary key. I'm trying to add another column called sort_order. The sort_order column should auto increment when the row is inserted. Then a user will be able…
dardub
  • 3,166
  • 5
  • 29
  • 31
6
votes
2 answers

do I have to specify integer length when creating an id field in MySQL through phpMyAdmin?

I saw someone not set the length in a tutorial but it was specifically for counting the total number of users and just set to auto-increment. I've been of the habit of always specifying a length because I thought it was mandatory, but I wanted to…
Simon Suh
  • 10,599
  • 25
  • 86
  • 110
6
votes
2 answers

auto increment after delete from a table

Possible Duplicate: MySQL: Reorder/Reset auto increment primary key? if I delete from my table a ligne and in this table i have an auto increment ID , DELETE From table where id=2 after this the table will be like this ID | NAme 1 …
Dilllllo
  • 448
  • 5
  • 10
  • 24
6
votes
8 answers

Why can't I create new posts in Wordpress? Warning: Creating default object from empty value in /public_html/wp-admin/includes/post.php on line 716

I have run into a problem where I can no longer create new posts on my Wordpress site. I think this started after a Wordpress update a while ago. I also have problems uploading images and I see ghost comments (an icon about new comments but no…
Saga
  • 91
  • 1
  • 7
6
votes
5 answers

How do I add auto_increment to a column in SQL Server 2008

I am using SQL Server 2008 and a primary key of a database table I am using is not an IDENTITY column (not sure why). I need to change that. I am in SQL Server Management Studio in design view, under column properties and for some reason I can't…
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321
6
votes
6 answers

Multiple autoincrement ids based on table column

I need help in database design. I have following tables. Pseudo code: Table order_status { id int[pk, increment] name varchar } Table order_status_update { id int[pk, increment] order_id int[ref: > order.id] order_status_id int[ref: >…
Jashwant
  • 28,410
  • 16
  • 70
  • 105
6
votes
2 answers

What is difference between BIGSERIAL and SERIAL?

I'm new on PostgreSQL for auto-increment we have to use BigSerial or Serial, so can anyone please explain which one we have to use when creating a table. Which one be the best please explain scenario wise.
6
votes
5 answers

Entity Framework Core does not respect Identity columns

Entity Framework is not respecting my Identity columns. It insists on trying to insert a value into an Identity (auto-increment) column in my MS SQL DB, which is obviously an error since the DB is supposed to supply the…
Fizzy
  • 352
  • 1
  • 2
  • 8
6
votes
2 answers

MySQL duplicate ID

Could it somehow happen that MySQL generates the same autoincrement ID twice? We have the following situation: a bill with id=100 was created; then it was deleted; then another bill was created and it has the same id = 100; The structure of the…
Andrey Minogin
  • 4,521
  • 6
  • 38
  • 60
6
votes
5 answers

Android Room - How to reset auto generated table primary key on each app run

I'm using Room in order to persist data. I have a Entity that has an automatically generated (autoGenerate) primary key that mimics a ticket system. On every application run I need this key to start from 0. Entity: @Entity public class…
Eggcellentos
  • 1,570
  • 1
  • 18
  • 25
6
votes
4 answers

SQL Server: insert next available int

I'm dealing with a table in SQL Server that has a serial_no column, which is defined as a non null int. It doesn't appear to be an auto incrementing field, as if I leave that column out of my insert statement I get an error saying that the serial_no…
Paul Wieland
  • 765
  • 2
  • 10
  • 29
6
votes
5 answers

Reset MySQL auto_increment when a large number already exists?

I have a table with an auto incrementing column. I need to set one of the rows to 1000 and never touch it again, but now that I've set it to 1000, auto increment keeps starting at 1001 and refuses to start at 1. Is there any way to get around this?
Charles Zink
  • 3,482
  • 5
  • 22
  • 24
6
votes
3 answers

How new Identity Jump feature of Microsoft SQL Server 2012 handles the range of data type?

I thought it was a bug but after reading this article http://www.codeproject.com/Tips/668042/SQL-Server-2012-Auto-Identity-Column-Value-Jump-Is, I found that it's a new feature of SQL Server 2012. This feature increments your last identity column…
6
votes
1 answer

H2 equivalent of Postgres `SERIAL` or `BIGSERIAL` column?

In Postgres, defining a column with SERIAL/BIGSERIAL has a triple effect as discussed here: Define a int/bigint column. Create a sequence object to generate auto-incrementing numbers. Set the default of the column to call nextval() on the…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
6
votes
2 answers

SQLite: *prevent* PRIMARY KEY value from resetting after delete all rows

I have a SQLite table, with a few columns, including an "ID" column which is INTEGER PRIMARY KEY. When I insert, this value increments as expected. However, when I delete all rows, this column's value reverts to 1 on the next insert. Is there a way…
dlchambers
  • 3,511
  • 3
  • 29
  • 34