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
23
votes
10 answers

Can you access the auto increment value in MySQL within one statement?

I have a MySQL database which contains a table of users. The primary key of the table is 'userid', which is set to be an auto increment field. What I'd like to do is when I insert a new user into the table is to use the same value that the auto…
TheKeys
  • 675
  • 2
  • 7
  • 14
23
votes
9 answers

Auto-increment in Oracle without using a trigger

What are the other ways of achieving auto-increment in oracle other than use of triggers?
Lakshmi
  • 1,759
  • 4
  • 18
  • 23
23
votes
2 answers

MySQL insert into table with auto-increment while selecting from another table

I have a table with an auto-increment primary key: create table rt_table ( rtID int PRIMARY KEY AUTO_INCREMENT, rt_user_id BIGINT, /*user being retweeted*/ rt_user_name varchar(70), /*user name of rt_user_id*/ …
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
23
votes
4 answers

When using UUIDs, should I also use AUTO_INCREMENT?

We're building a new web app that will have an offline iPad/Android app version on a number of local devices that will involve inserts of new data. As such we require the use of UUIDs to allow for the necessary two-way synchronization with the…
Michael
  • 11,912
  • 6
  • 49
  • 64
22
votes
3 answers

AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY - android

I'm trying to create a table in my DB with an ID that is autoincrement itself but whenever I try to add the AUTOINCREMENT keyword to my query it tells me that : AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY Here is my…
David Lasry
  • 1,407
  • 4
  • 26
  • 43
21
votes
3 answers

How to tell Entity Framework that my ID column is auto-incremented (AspNet Core 2.0 + PostgreSQL)?

Code is simple. Tag.cs entity: public partial class Tag { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int Id { get; set; } public string Name { get; set; } public string Description { get; set;…
Andrey Kotov
  • 1,344
  • 2
  • 14
  • 26
21
votes
4 answers

How to create Autoincrement column in SQLite using EF core?

I am using Entity Framework Core 2.0 for Sqlite code first in my UWP and .NET Standard app. My model has an entity of type Primary Key integer which should be served as auto increment according to SQLite documentation. But in real for every row that…
21
votes
7 answers

How to fill in the "holes" in auto-increment fields?

I've read some posts about this but none cover this issue. I guess its not possible, but I'll ask anyway. I have a table with more than 50.000 registers. It's an old table where various insert/delete operations have taken place. That said, there are…
Paulo Bueno
  • 2,499
  • 6
  • 42
  • 68
21
votes
1 answer

How to insert values into auto identity column in MYSQL

I would like to insert values into mysql innodb table Auto_Increment column. I am loading some data from an old table to new table which has an identity, and need to preserve the existing values from the old table, so I need to preserve the existing…
VInayK
  • 1,501
  • 6
  • 34
  • 47
21
votes
3 answers

SQL create statement incorrect syntax near auto increment

I created the following table, but I got the error below; Incorrect syntax near 'AUTO_INCREMENT'. SQL: CREATE TABLE [dbo].[MY_TABLE] ( [ID] INT NOT NULL AUTO_INCREMENT, [NAME] NVARCHAR (100) NULL, [SCHOOL] NVARCHAR…
Sharon Watinsan
  • 9,620
  • 31
  • 96
  • 140
20
votes
1 answer

Remove autoincrement from postgresql field

I have an existing table in a db, FK'd from several others, SQL below: CREATE TABLE forecastsource ( source_id integer DEFAULT nextval(('public.forecastsource_source_id_seq'::text)::regclass) NOT NULL, source_name character varying NOT…
Marc
  • 3,259
  • 4
  • 30
  • 41
20
votes
5 answers

Reset the row number count in SQLite3/MySQL

I am using SQLite3. I load a table with say 30 rows using integer as Primary ID and it auto-increments. Now I delete all the rows from the table and then, reload some new information onto the table. Problem is: the row count (my PrimaryID) now…
Maddy
  • 2,520
  • 14
  • 44
  • 64
20
votes
4 answers

Autonumber with Entity Framework

I want to loop through a collection of objects and add them all to a table. The destination table has an auto-increment field. If I add a single object there is no problem. If I add two objects both with the primary key of zero, the entity…
dcompiled
  • 4,762
  • 6
  • 33
  • 36
20
votes
8 answers

How to import text file to table with primary key as auto-increment

I have some bulk data in a text file that I need to import into a MySQL table. The table consists of two fields .. ID (integer with auto-increment) Name (varchar) The text file is a large collection of names with one name per line…
webworm
  • 10,587
  • 33
  • 120
  • 217
19
votes
3 answers

PostgreSQL: Auto-increment based on multi-column unique constraint

One of my tables has the following definition: CREATE TABLE incidents ( id serial NOT NULL, report integer NOT NULL, year integer NOT NULL, month integer NOT NULL, number integer NOT NULL, -- Report serial number for this period ... …
l0b0
  • 55,365
  • 30
  • 138
  • 223