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
12
votes
4 answers

How to re-assign AUTO_INCREMENT column for every row in a MySQL table using PHP

I have an image gallery which website members can upload images to. When an image is uploaded, a MySQL row is written, containing various pieces of information about the image, member, etc. This row uses AUTO_INCREMENT to create its ID, so that…
Drew
  • 836
  • 4
  • 12
  • 24
12
votes
2 answers

How to add auto increment id according to a group in mysql

Here is the format of the table: indexer group name id 1 abc a 2 abc b 3 xyz c 4 abc e 5 xyz d Now i want it to be like, indexer group name id 1 abc a 1 2 abc b 2 3 xyz c 1 4 …
Heider Kumar
  • 135
  • 1
  • 1
  • 7
12
votes
7 answers

Insert into a table and set another column to autoincremented column value

Let's say I have a simple table: create table foo { id INTEGER PRIMARY KEY AUTOINCREMENT, bar INTEGER } And I want to insert a new row, such that id == bar where value for id is chosen by the database, a.k.a. auto-increment. Something like…
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
12
votes
4 answers

Inserting a row to a table with auto_increment column

I'm working on a table that has 4 columns and the first one is an auto incrementing integer called id. If I'm going to insert into this table using mysqli prepared statements I keep having trouble inserting a query that works. Using phpMyAdmin It…
fdfdsfsdfsdfds
  • 121
  • 1
  • 1
  • 3
12
votes
3 answers

Insert statement asked me to insert for autoincrement column

I use PostgreSQL. I have created the following table: CREATE TABLE "Task" ( "taskID" serial NOT NULL, "taskType" text NOT NULL, "taskComment" text NOT NULL, "taskDate" date NOT NULL, CONSTRAINT "Task_pkey" PRIMARY KEY ("taskID") ) I put…
Aan
  • 12,247
  • 36
  • 89
  • 150
12
votes
3 answers

In H2 database, the auto_increment field is incremented by 32?

I have this simple Table (just for test) : create table table ( key int not null primary key auto_increment, name varchar(30) ); Then I execute the following requests: insert into table values ( null , 'one');// key=1 insert into table values (…
Marwen Trabelsi
  • 4,167
  • 8
  • 39
  • 80
11
votes
8 answers

SqlServer create table with MySql like auto_increment primary key

I want to make a table in SqlServer that will add, on insert, a auto incremented primary key. This should be an autoincremented id similar to MySql auto_increment functionality. (Below) create table foo ( user_id int not null auto_increment, …
Aldur
  • 3,025
  • 5
  • 21
  • 14
11
votes
3 answers

mysql change the column id to start from 1 and auto increment from there

I was looking at my table in phpmyadmin and noticed that the id starts at 13410 and increase by 1. I would like to reset and start from one. I've read many people say its better to leave it alone or its going to get complicated if you messed with it…
merrill
  • 593
  • 5
  • 14
  • 34
11
votes
2 answers

What is the acceptable method for generating an auto incrementing primary key in PostgreSQL?

Is there no easy way to do this without sequences and triggers? I have average SQL skills, and I want to use the industry standard method for pl/sql (PostgreSQL). I'm basically converting over this example table from Spring Security: create table…
user4903
11
votes
1 answer

Set AUTO_INCREMENT value through variable in MySql

I have a table with an auto_increment column. I save the last value of the column in another table called ids_tbl, and when mysql restarts, read the value from ids_tbl and re-set the AUTO_INCREMENT value. If I do this: alter table outgoing_tbl…
Sinai
  • 620
  • 1
  • 14
  • 36
11
votes
1 answer

Hibernate entities auto-increment id's across tables rather than per table

Currently I have three tables: Company, Group, Person. The three tables are connected by Company is one-to-many with Group and Group is one-to-many with Person. In all three classes (Company.java, Group.java, Person.java), I coded the auto-increment…
000000000000000000000
  • 780
  • 4
  • 15
  • 47
11
votes
2 answers

how to use em.merge() to insert OR update for jpa entities if primary key is generated by database?

I have an JPA entity like this: @Entity @Table(name = "category") public class Category implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) …
Bobo
  • 8,777
  • 18
  • 66
  • 85
11
votes
2 answers

Resetting AUTO_INCREMENT is taking a long time in MySQL

ALTER TABLE tablename AUTO_INCREMENT = 10000000 This query is taking long time to update. Why? I need to optimize this query.
user320343
  • 353
  • 1
  • 3
  • 11
11
votes
6 answers

SQLite auto increment not working

ok this isn't spamming and it's supposed to be simple I don't know why it's not working this is my code: gamesdatabase = openOrCreateDatabase("GamesDatabase", MODE_PRIVATE, null); gamesdatabase.execSQL("CREATE TABLE IF NOT EXISTS Games (ID INTEGER…
BezrA
  • 223
  • 1
  • 4
  • 11
11
votes
2 answers

mysql unlimited primary keys auto increment

I have a question with im really unsure with. First feel free to downvote me if its a must but i would really like to hear a more experienced developers opinion. I am building a site where i would like to build similar functionality like google…
Side
  • 1,753
  • 9
  • 35
  • 64