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

C# Class Auto increment ID

I am creating a class in C# called "Robot", and each robot requires a unique ID property which gives themselves an identity. Is there any way of creating an auto incremental ID for each new class object? So, If i created 5 new robots, their IDs…
Stefan Dunn
  • 5,363
  • 7
  • 48
  • 84
9
votes
2 answers

How to prevent mySQL from resetting auto increment value?

I have a table to make temporary id`s . When i delete all of the rows of my table , auto increment value for this table will reset to 0 . but i don't want to reset the auto increment. What can i do?
AMIN Gholibeigian
  • 337
  • 2
  • 6
  • 20
9
votes
5 answers

MySQL: can an AUTO_INCREMENT generate values out of order?

Assume I've got the table: CREATE TABLE test ( ID INT AUTO_INCREMENT PRIMARY KEY, InsertTime DATETIME ) ENGINE = InnoDB; And, through an Apache/PHP website, as a response to web requests, I keep doing this: INSERT INTO test (InsertTime)…
Vilx-
  • 104,512
  • 87
  • 279
  • 422
9
votes
4 answers

Max Size of SQL Server Auto-Identity Field

What is the max size of SQL Server identity field (int)? I am deleting and inserting hundereds of records at a time a few times a day in a few tables and I'm curious what effect this will have regarding the auto-identity field. I can run a job every…
Rivka
  • 2,172
  • 10
  • 45
  • 74
9
votes
5 answers

AutoIncrement fields on databases without autoincrement field

In MS Sql Server is easy create autoincrement fields. In my systems I stopped to use autoincrement fields for primary keys, and now I use Guid's. It was awesome, I've got a lot of advantages with that change. But in another non-primary key fields, I…
Click Ok
  • 8,700
  • 18
  • 70
  • 106
9
votes
1 answer

MySQL error #167 - Out of range value for column even when it is autoincremented

I have a field (called ID) that is defined as: smallint(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=32768 I have a query as follows (simplified): INSERT INTO delivery (`ConsigneeName`, `ConsigneePhone`) VALUES ('John Doe', '9999999999') And have…
Chiwda
  • 1,233
  • 7
  • 30
  • 52
9
votes
3 answers

Auto increment django model field per user

I have this model: class Invoice(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL) data = models.TextField(default=None, blank=True, null=True) number = models.PositiveIntegerField(default=0, null=False) What I need…
caruccio
  • 295
  • 3
  • 11
9
votes
1 answer

Auto increment a non-primary key field in Ruby on Rails

In a RoR migration, how do I auto increment a non-primary-key field? I'd like to do this in the db definition, and not in the model.
kingjeffrey
  • 14,894
  • 6
  • 42
  • 47
9
votes
3 answers

How efficient is Last_insert_id?

I recently came across a problem where I needed to be able to grab the last ID of a query I've inserted on a page. The process was quite simple, but I'd like some reassurance on how the process is done. Here's how my code is: $query30 =…
Josh Potter
  • 1,629
  • 2
  • 13
  • 11
9
votes
3 answers

Reserving mySQL auto-incremented IDs?

We want to obtain an auto-increment ID from mySQL without actually storing it until the other non-mysql related processes are successfully completed, so that the entry is not stored if an exception or application crash happens. We need to use the ID…
Saqib Ali
  • 3,953
  • 10
  • 55
  • 100
9
votes
3 answers

What happens when auto increment primary key in MySQL comes to maximum

I have auto increment, primary key in MySQL called ID and it is INT. As my app grows and I'm getting more users they are making more entries. What happens when my INT comes to its maximum value 2 147 483 647? Can I just switch to BIGINT?
FosAvance
  • 2,363
  • 9
  • 36
  • 52
9
votes
2 answers

In doctrine2 is it possible to have an autoincrement column that is not the primary key?

In doctrine2 I have an entity that has a primary key that's feeded from a webservice, and also has an index that should be an auto increment. I can set manually in mysql but can't make this work in doctrine2.
9
votes
6 answers

Get next auto increment

I know this isn't so complicated but I can't remember how to do. I just need to know the next auto increment. $result = mysql_query(" SHOW TABLE STATUS LIKE Media "); $data = mysql_fetch_assoc($result); $next_increment =…
Johan
  • 18,814
  • 30
  • 70
  • 88
9
votes
2 answers

How should I declare auto increment variable in the virtual table of stored procedure

I have a stored procedure like this create procedure onedata as begin declare @input_data table (Id int NOT NULL AUTO_INCREMENT, name varchar(500) . .... ) insert into @input_data ..... .... end But i am not able to declare Id to be…
Linnet
  • 101
  • 1
  • 3
  • 8
9
votes
2 answers

how to set H2 primary key id to auto_increment?

i am using sql, H2, and i am trying to make so that the ID of Usertable is auto_incremented. i tried all sql commands in H2 sql interface, didnot work out. alter table user alter column int not null auto_increment; this common one is even not…
doniyor
  • 36,596
  • 57
  • 175
  • 260