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

Use Value of Current Insert's Auto_Increment in Cell

How can I get the auto_increment value that MySQL generated for the current insert row, so I can use it in the insert command? For example: INSERT INTO aTable (aField) VALUES ( AUTOINCVALUEHERE ) This does not seem like a complicated operation, but…
Bakaiya
  • 43
  • 5
1
vote
2 answers

Increment all values in mysql table

Lets say I have +-------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+-------+ | id | int(11) | YES | UNI |…
Lizard
  • 43,732
  • 39
  • 106
  • 167
1
vote
3 answers

Delete/Insert Last Record of a Table with an Auto Increment Key in SQLite

I have a table with an auto increment primary key in sqlite. Lets say that I have these records in my table: 1 hi 2 hello 3 bye 4 goodbye if I delete bye and add another record, the new record's id is going to be 5. But if I delete goodbye and add…
AliBZ
  • 4,039
  • 12
  • 45
  • 67
1
vote
2 answers

On Finding duplicate values in column of SQL Table, Increment a COUNT column by 1

While going through sql columns, if we find duplicate values then we need incrementing a count starting with 1. Any Value that matches the original value found in column "Filenum". It should look like this on the…
Haimanta
  • 11
  • 3
1
vote
1 answer

Migrations Inside of Codeigniter

Earlier today I signed up for a nettuts plus account and have been watching this series on codeigniter cms building. I am creating a migration file to create my users table. With my user ids I prefer to work with user ids that look like this 10000…
Kevin Smith
  • 731
  • 2
  • 7
  • 21
1
vote
2 answers

MySQL performance with missing values on autoincrement id as key

Example: I have a tab "books" with "id" (int autoincrement) as primary key, name, author, price etc...(not important). There's 5 books and I delete the book with id=3. When I add other books the autoincrement value will start from 6 and there's a…
CalCon
  • 246
  • 2
  • 10
1
vote
4 answers

How to make a primary key to auto increment in a database in php?

I have a database and i am putting data inside. I have one node called key , which is the primary key and other nodes. Now when i put data on my table , i put data in all the nodes except this key node. How do i make it automatically to increase…
donparalias
  • 1,834
  • 16
  • 37
  • 60
1
vote
2 answers

PostgreSQL serial pattern

Is it possible to declare a serial field in Postgres (9.0) which will increment based on a pattern? For example: Pattern: YYYY-XXXXX where YYYY is a year, and XXXXX increments from 00000 - 99999. Or should I just use a trigger? EDIT: I prefer the…
1
vote
0 answers

Auto Increment for Sub Id

I need to create a tiles table that has a structure like this for http://www.myownmealplanner.com: id user_id sub_tile_id 1 1 1 2 1 2 3 1 3 4 2 1 5 2 2 6 2 3 7 3 1 8 3 2 9 3 3 etc. I can't just create new tables…
Maureen Moore
  • 1,049
  • 2
  • 9
  • 21
1
vote
2 answers

Add incrementing numbers to string use javascript .replace regex

I have this string that I am trying to increment each word/property by adding a _# with the # being the incremented number on the left side of the {. str = 'View{Image{BackgroundImage: Image.png;Position: 0, 0;Width: 320;Height:…
Rob
  • 11,185
  • 10
  • 36
  • 54
1
vote
2 answers

Create columns that autoincrement with name in a MySQL Database

I know that this might seem like a strange question, but let me try and explain it. I have a database table called 'plan' and in it the first column is called 'username' and the columns after it are called 'question1', 'question2' and so on. I now…
EbilGenius
  • 69
  • 1
  • 9
1
vote
1 answer

AUTO_INCREMENT in two places

I came across following sql statements and you can see that AUTO_INCREMENT is in two different places. Can you explain the different, I know the first one is auto incrementing id. But what does the second one mean? CREATE TABLE `categories`( …
Isuru Madusanka
  • 1,397
  • 4
  • 19
  • 27
1
vote
3 answers

Create new MySql schema from Backup .SQL source file resets auto increment id columns?

I am developing a large database schema that I desire to make available to clients. I am new to MySql database administration. How do I restore a .sql file of the schema so that it also resets ALL auto incremental id columns back to 0 or Null…
JoJo
  • 4,643
  • 9
  • 42
  • 65
1
vote
5 answers

add primarykey with autoincrement in mysql

how to set particular column as primary key with auto increment in mysql.am using alter statement . but am getting error when i excecute the alter statement in mysql. alter statement --------------- ALTER TABLE tbl_travelplan add COLUMN TRREQNO…
vps
  • 1,337
  • 7
  • 23
  • 41
1
vote
0 answers

When running a DELETE statement, why do I get MySQL warning ER_BINLOG_UNSAFE_WRITE_AUTOINC_SELECT?

The exact warning I get is: Note | 1592 | Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statements writing to a table with an auto-increment column after selecting from another table are…
Paul Molodowitch
  • 1,366
  • 3
  • 12
  • 29