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

SQL - Check if a column auto increments

I am trying to run a query to check if a column auto increments. I can check type, default value, if it's nullable or not, etc. but I can't figure out how to test if it auto increments. Here is how I am testing for those other things: SELECT * FROM…
Aust
  • 11,552
  • 13
  • 44
  • 74
28
votes
7 answers

Why won't this static variable increment when using generics?

I need a certain class to contain a static member that keeps track of everytime an instance of that class is instantiated, essentially so that each instance of the class has a unique index. It works with a non-generic class but this generic…
Sean Thoman
  • 7,429
  • 6
  • 56
  • 103
28
votes
5 answers

Mapping PostgreSQL serial type with Hibernate annotations

I am using Hibernate 3.3 and PostgreSQL 8.x and would like to use Hibernate annotations to map an auto-incremented column which is NOT a primary key. It doesn't matter if the column is mapped using SERIAL type or sequences in Postgres as long as it…
alecswan
  • 499
  • 1
  • 6
  • 12
28
votes
5 answers

Will MySQL reuse deleted ID's when Auto Increment is applied

http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html That document I'm reading seems to say something like: "In this case (when the AUTO_INCREMENT column is part of a multiple-column index), AUTO_INCREMENT values are reused if you…
Eae
  • 4,191
  • 15
  • 55
  • 92
27
votes
6 answers

Approaches to generate auto-incrementing numeric ids in CouchDB

Since CouchDB does not have support for SQL alike AUTO_INCREMENT what would be your approach to generate sequential unique numeric ids for your documents? I am using numeric ids for: User-friendly IDs (e.g. TASK-123, RQ-001, etc.) Integration with…
aku
  • 122,288
  • 32
  • 173
  • 203
27
votes
5 answers

void * arithmetic

#include int main(int argc,char *argv[]) { int i=10; void *k; k=&i; k++; printf("%p\n%p\n",&i,k); return 0; } Is ++ a legal operation on void* ? Some books say that it's not but K & R doesn't say anything regarding…
Onkar Mahajan
  • 944
  • 2
  • 13
  • 16
27
votes
4 answers

Autoincrement uniqueidentifier

Basically I want to use uniqueidentifier in similar way as identity. I don't want to insert values into it, It should just insert values automatically, different value for each row. I'm not able to set autoincrement on columns of type…
Rasto
  • 17,204
  • 47
  • 154
  • 245
27
votes
3 answers

Query to Re-index Primary Key of MySQL Database

I've got a table in MySQL that has a Primary Key Column. Lets say: ID | Value 1 | One 2 | Two 6 | Three 8 | Four 9 | Five How do I get it to be: ID | Value 1 | One 2 | Two 3 | Three 4 | Four 5 | Five There are no other tables. Just the…
LearningDeveloper
  • 638
  • 2
  • 11
  • 23
26
votes
4 answers

Create unique autoincrement field with mongoose

Given a Schema: var EventSchema = new Schema({ id: { // ... }, name: { type: String }, }); I want to make id unique and autoincrement. I try to realize mongodb implementation but have problems of understanding how to…
Boris Zagoruiko
  • 12,705
  • 15
  • 47
  • 79
25
votes
3 answers

What to do if the auto-increment value reaches its limit?

I am doing a little research for a problem that might occur someday. Lets say you have an InnoDB MySQL table with an id and a name field. the id field has BIGINT(20) and is AUTO_INCREMENT plus its the primary key. What do you do in a case that…
user3676604
25
votes
2 answers

Set auto increment in Core data iOS

I am using Core Data, and want to set an auto_increment ID as one of the fields which will be unique. Is it possible to set auto_increment in iOS using core data? Can anyone help me with a small example of how to implement this? Below is the code…
Anu Padhye
  • 615
  • 1
  • 6
  • 16
24
votes
2 answers

Generate an auto increment field in rails

I have a model Token, which has a field token_number that I need to auto increment (starting from 1001), if and only if the user does not provide it. The problem is that, since the user has the option to provide this field, I can't exactly query the…
Wahaj Ali
  • 4,093
  • 3
  • 23
  • 35
24
votes
5 answers

Auto-increment on Azure Table Storage

I am currently developing an application for Azure Table Storage. In that application I have table which will have relatively few inserts (a couple of thousand/day) and the primary key of these entities will be used in another table, which will have…
24
votes
3 answers

Does Postgresql SERIAL work differently?

I have a postgres table with a SERIAL id. id (serial) name age Insert usually happens from a web application. I inserted manually two new records setting the id as max (id)+1**** After these 2 insert when the web app inserts 2 record it gives…
zod
  • 12,092
  • 24
  • 70
  • 106
23
votes
2 answers

How to use time-series with Sqlite, with fast time-range queries?

Let's say we log events in a Sqlite database with Unix timestamp column ts: CREATE TABLE data(ts INTEGER, text TEXT); -- more columns in reality and that we want fast lookup for datetime ranges, for example: SELECT text FROM data WHERE ts BETWEEN…
Basj
  • 41,386
  • 99
  • 383
  • 673