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
16
votes
2 answers

How can i change _id field in MongoDB Collection to User_id?

I am new user for MongoDB Database. In MongoDb whatever insert into some collection defaultly one field is added that is _id field. For Example: db.users.insert({"User_id":"1","User_Name":"xxx","Address":"yyyy"}) db.users.find() It shows { "_id" :…
selvam
  • 1,177
  • 4
  • 18
  • 40
16
votes
1 answer

SQLAlchemy: How to make an integer column auto_increment (and unique) without making it a primary key?

I am using Flask extension for SQLAlchemy to define my database model. I want an id column to be int type and with auto_increment property but without making it a primary key. How do I achieve it? I tried this: from flask import Flask, jsonify from…
ajay
  • 9,402
  • 8
  • 44
  • 71
15
votes
4 answers

"Compile with /main to specify the type that contains the entry point."

Per the code below, I am getting the following message. I am fairly certain "why" I am getting it, I just don't know how to rearrange the code to move/remove/replace one of the error causing statements. "Compile with /main to specify the type that…
Geo
  • 339
  • 3
  • 7
  • 21
15
votes
7 answers

Getting the next AUTO_INCREMENT value of a SQLite database

Using the typical SQLiteDatabase object in Android's API, what can I do to get the next AUTO_INCREMENT value of a particular column (ie. id) without affecting the value itself. Is there a method for that? Or what query should I execute to get that…
Brian
  • 7,955
  • 16
  • 66
  • 107
15
votes
6 answers

SQL GUID Vs Integer

I have recently started a new job and noticed that all the SQL tables use the GUID data type for the primary key. In my previous job we used integers (Auto-Increment) for the primary key and it was a lot more easier to work with in my opinion. For…
Dalbir Singh
  • 2,629
  • 3
  • 26
  • 29
15
votes
1 answer

Serial numbers per group of rows for compound key

I am trying to maintain an address history table: CREATE TABLE address_history ( person_id int, sequence int, timestamp datetime default current_timestamp, address text, original_address text, previous_address text, …
Rus925
  • 358
  • 4
  • 10
15
votes
1 answer

Is there a set identity_insert on equivalent for SQLite?

In TSQL there is SET IDENTITY_INSERT ON; is there a functional equivalent in SQLite?
DiverseAndRemote.com
  • 19,314
  • 10
  • 61
  • 70
15
votes
3 answers

Mysql auto increment jumps when insert-select

I am testing insert-select query and noticed an weird result. CREATE TABLE `test` ( `cnt` int(11) NOT NULL AUTO_INCREMENT, `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, PRIMARY KEY (`cnt`) ) CREATE TABLE `test_current` ( `a` int(11)…
user1640242
  • 221
  • 1
  • 3
  • 5
15
votes
2 answers

How to set up manually the next value of auto_increment?

I added some rows into the table manually and also I set up the ID (auto_increment) manually. Now when I try to add new row through my app into DB table, to DB table I am getting the error , that the created ID value already exist. How can I set…
user984621
  • 46,344
  • 73
  • 224
  • 412
14
votes
5 answers

Compact or renumber IDs for all tables, and reset sequences to max(id)?

After running for a long time, I get more and more holes in the id field. Some tables' id are int32, and the id sequence is reaching its maximum value. Some of the Java sources are read-only, so I cannot simply change the id column type from int32…
Lenik
  • 13,946
  • 17
  • 75
  • 103
14
votes
5 answers

How to change a table ID from serial to identity?

I have the following table in Postgres 10.10: Table "public.client" Column | Type | Collation | Nullable | Default …
Christian Hick
  • 401
  • 3
  • 10
14
votes
2 answers

Add an auto_increment column in Magento setup script without using SQL

Previously I asked how to ALTER TABLE in Magento setup script without using SQL. There, Ivan gave an excellent answer which I still refer to even now. However I have yet to discover how to use Varien_Db_Ddl_Table::addColumn() to specify an…
clockworkgeek
  • 37,650
  • 9
  • 89
  • 127
14
votes
5 answers

How to return the value of AUTO INCREMENT column in SQLite with VB6

I have a table in SQLite: CREATE TABLE "EventType" ( [EventTypeID] INTEGER PRIMARY KEY, [EventTypeName] VARCHAR(50) NOT NULL UNIQUE ); Since EventTypeID is an integer and a primary key, that automatically makes it an auto-incrementing column, and…
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
14
votes
5 answers

How does MySQL Auto Increment work?

I was just creating a new table using MySQL Query Browser, and noticed there's a tick under Auto Increment Column. How does that work? When adding to the database programatically, do I just add a number, and then the database automatically…
anon271334
14
votes
3 answers

How can I set an AUTO_INCREMENT field to start with the value 6000 in MySQL?

How can I set a non-auto-increment field to auto increment in MySQL? And how can I set the auto increment start value to 6000?
Ajay
  • 141
  • 1
  • 1
  • 3