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
1
vote
1 answer

DELETE in Postgres doesn't decrement serial PK?

If in SQL Server we have a table with auto-increment, and 10 rows, and the last row has id = 10. When you delete the last row, the next you insert will get the id = 10 too, right? But in Postgres, using bigserial as PK, when I delete the row with…
jean
  • 11
  • 1
  • 2
1
vote
2 answers

Get max id of all sequences in PostgreSQL

We have a monitor on our databases to check for ids approaching max-int or max-bigint. We just moved from MySQL, and I'm struggling to get a similar check working on PostgreSQL. I'm hoping someone can help. Here's the query in MySQL SELECT…
John Hinnegan
  • 5,864
  • 2
  • 48
  • 64
1
vote
0 answers

Next and Previous Slide Button Functionality i++, i--

I had a great experience asking a question last time and thought I'd come back for more help. You guys are wonderful. Thank you in advance. I am working with a featured post slider that advances through 4 posts automatically. I would like to add…
lightyrs
  • 2,809
  • 2
  • 29
  • 32
1
vote
4 answers

how to auto increase data field in java oop class

I have this class public class NInfo { private int val; private static int indx=1; public NInfo(int val) { this.val = val; this.indx++; } } I would like to auto increase the indx in every new object that I create starting 1 this code…
Tamir Moav
  • 21
  • 1
  • 4
1
vote
1 answer

Sphinx create attribute for mysql primary key auto increment id

I am trying to create sphinx index for same copy for my mysql table but there i got a error for my auto increment id. So i can't create a same field name of auto increment id. Error: WARNING: attribute 'u_g_id' not found - IGNORING Here is my…
Lingesh
  • 65
  • 1
  • 7
1
vote
1 answer

Find out if ID was auto-incremented in before insert-trigger?

In MySQL I need to know if it's possible in a BEFORE INSERT trigger to find out if the primary key ID (NEW.Id) is being automatically generated by the auto-increment value or if the ID was manually set. The reason for this is that in my application…
Dylan
  • 9,129
  • 20
  • 96
  • 153
1
vote
3 answers

What is an elegant way to make two fields auto increment?

In SQL Server, I have two fields, one is primary and has an identity (AN_ID) then I have another one that for legacy reasons (don't ask) has to be updated reflecting the AN_ID. Currently they have the exact same value. I was wondering if there are…
0plus1
  • 4,475
  • 12
  • 47
  • 89
1
vote
1 answer

composite primary key and autoincrement column but NOT primary key

I'm trying to achieve this: INSERT INTO `tbl_result` (`var1`, `var2`, `var3`, `year`, `result`) VALUES (%f, %f, %d, %d, %f) ON DUPLICATE KEY UPDATE result=%f; These are results of a realtime calculator that I want to uniquely store in the…
Pedro Costa
  • 2,968
  • 2
  • 18
  • 30
1
vote
4 answers

Get current auto_increment value

I am doing mysql insert for my table using php. Autoincrement column name is "link_id" and "alias" colum is used to make SEO friendly url. During my insert, I would like to attach link_id value at the end of my alias column. So I need to know what…
Ossi
  • 788
  • 2
  • 14
  • 21
1
vote
1 answer

Strictly auto-increment value in MySQL

I have to create a MySQL InnoDB table using a strictly sequential ID to each element in the table (row). There cannot be any gap in the IDs - each element has to have a different ID and they HAVE TO be sequentially assigned. Concurrent users create…
user1156544
  • 1,725
  • 2
  • 25
  • 51
1
vote
1 answer

mysql cluster auto increment out of sync

I have two mysql cluster data nodes as Master and slave. But after certain number of rows there is difference between two auto_increment values from one node to another. The difference is of Node 2 is ahead than node 1 by 11. can anyone suggest any…
MySQL DBA
  • 5,692
  • 21
  • 54
  • 71
1
vote
2 answers

Set value for SQL Server database table auto increment field

I am using Microsoft SQL Server 2008. In database I have a table with an auto increment field (ID). I already have two rows inserted in the table, so the ID of the next row will be 3. What I want to do is that when the next row will be inserted,…
user1080381
  • 1,597
  • 1
  • 16
  • 22
1
vote
1 answer

SQL insert auto increment value

I am currently working on a database that stores statements in 2 tables, and has another table linking statements together. The first 2 tables auto increment the primary ID on every entry, however I need to know the new ID's that have been given to…
Jon8672
  • 63
  • 2
  • 5
1
vote
5 answers

Set AUTO_INCREMENT starting value in a InnoDB table to zero?

Is there any to get the an AUTO_INCREMENT field of a InnoDB to start counting from 0 not 1 CREATE TABLE `df_mainevent` ( `idDf_MainEvent` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`idDf_MainEvent`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Charles Faiga
  • 11,665
  • 25
  • 102
  • 139
1
vote
2 answers

How retrieve in PHP the generated PRIMARY KEY from an AUTO_INCREMENT column for each row with an INSERT of multiple rows in MySQL?

I have an INSERT with syntax for insert multiple rows: INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9); With MySQL function LAST_INSERT_ID() can retrieve the primary key of an generated AUTO_INCREMENT column, but how can I retrieve the…
Jose Nobile
  • 3,243
  • 4
  • 23
  • 30