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

Autoincrementing letters in Perl

I do not understand autoincrementing letters in Perl. This example seems perfectly understandable: $a = 'bz'; ++$a; ca #output b gets incremented to c. There is nothing left for z to go to, so it goes back to a (or at least this is how I see the…
Brian
  • 1,571
  • 1
  • 15
  • 20
14
votes
3 answers

Custom SERIAL / autoincrement per group of values

I'm trying to make a blog system of sort and I ran into a slight problem. Simply put, there's 3 columns in my article table: id SERIAL, category VARCHAR FK, category_id INT id column is obviously the PK and it is used as a global identifier for all…
yhware
  • 502
  • 3
  • 13
  • 26
14
votes
1 answer

Easiest way to create an auto increment field in Firebird database

Is there an easy way to create auto increment field using Firebird? I have installed the FlameRobin admin tool, but the process of creating an auto increment field through the tool is complex. Can I not create such an identity field just by clicking…
gomesh munda
  • 838
  • 2
  • 14
  • 32
14
votes
2 answers

Auto-increment a value in Firebase

How do I auto increment a value stored in Firebase from an Android client? Currently: I declare int id = 1. When I increment, I see the values 2, 3 etc. being stored. That's fine, but when I re-run the project, id is set equal to 1 again. I want it…
14
votes
7 answers

Get all inserted IDs when inserting multiple rows using a single query

I've already looked at other answers and I still feel that my question is relevant and deserves a separate entry. I have a table named settings(which stores user settings) and I have to insert multiple settings for each user. Initially, I had…
GarbageGigo
  • 303
  • 2
  • 10
14
votes
2 answers

Reference value of serial column in another column during same INSERT

I have a table with a SERIAL primary key, and also an ltree column, whose value I want to be the concatenation of those primary keys. e.g. id | path ---------- 1 1 2 1.2 3 1.2.3 4 1.4 5 1.5 I'm curious if there's a way to do such an…
Aaron Fi
  • 10,116
  • 13
  • 66
  • 91
14
votes
5 answers

If I have a table with only an auto-increment column, how do I insert into it?

A colleague asked me, if you have a table in SQL Server with only an auto-increment column, how do you insert a new row into that table? INSERT INTO MyTable() VALUES() ...doesn't work. As for why... I'm not really sure. But I found the question…
Scott Whitlock
  • 13,739
  • 7
  • 65
  • 114
13
votes
3 answers

H2 auto-increment not working after update from 1.4.200 to 2.1.212

We are upgrading an application from spring-boot 2.4.3 to 2.7.0. Hibernate core version is 5.6.9.Final. 2.7.0 is the first one to use H2 database 2.1.212 and we are using it for tests. I made some changes based on their guide to migrate to 2.0 but…
Cristian
  • 417
  • 1
  • 9
  • 18
13
votes
1 answer

How to create a auto incremented column in Documentdb

I want to create a document in azure documentdb with an auto-increment column. Is this possible? If yes, please guide me. Any help would be greatly appreciated. Database db = CreateOrReadDocumentDb("EmployeeDb").Result; DocumentCollection dc =…
satish kumar V
  • 1,695
  • 6
  • 33
  • 47
13
votes
3 answers

SQL Server unique auto-increment column in the context of another column

Suppose the table with two columns: ParentEntityId int foreign key Number int ParentEntityId is a foreign key to another table. Number is a local identity, i.e. it is unique within single ParentEntityId. Uniqueness is easily achieved via unique…
Anthony Serdyukov
  • 4,268
  • 4
  • 31
  • 37
13
votes
2 answers

How to manually set seed value as 1000 in MySQL

I am using MySQL 5. I need to set the seed value as 1000 for my auto increment field. How can I set it?
user186164
13
votes
4 answers

mysql ID auto increment doesn't starts from 0

i have a table with ID , this ID is auto increment and primary key ,the first time i inserted to that table , the ID starts from 0 , but after i removing all the values from that table and inserted again to it , the ID doesn't start from 0 , but…
LinCR
  • 391
  • 3
  • 6
  • 14
12
votes
7 answers

How do I return a new IDENTITY column value from an SQLServer SELECT statement?

I'm inserting into an SQLServer table with an autoincrementing key field. (I believe this is called an IDENTITY column in SQLServer.) In Oracle, I can use the RETURNING keyword to give my INSERT statement a results set like a SELECT query that will…
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
12
votes
5 answers

Incrementing a unique ID number in the constructor

I'm working on an object in C# where I need each instance of the object to have a unique id. My solution to this was simply to place a member variable I call idCount in the class and within the constructor I would have: objectID =…
ivarlee
  • 161
  • 2
  • 2
  • 6
12
votes
5 answers

Is mysql auto increment safe to use as userID?

I am working on website that allows people to create profiles online. I was wondering if it is the right choice to use MySQL AUTO_INCREMENTed IDs as my user ids. Also bearing in mind that I might have to duplicate the database across multiple…
Sthe
  • 2,575
  • 2
  • 31
  • 48