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

How to reuse auto_increment values?

Possible Duplicate: Fragmentation of id's (auto_increment column) in mysql I have this column in my database. Let's say its name is 'threadid'. It contains unique ids given to each thread for distinction. threadid 9 8 7 6 5 4 3 2 1 Let's say I…
Visualizer7
  • 325
  • 1
  • 5
  • 13
8
votes
2 answers

getting an insert ID from Webkit's HTML5 database storage

Webkit (on iPhone and Safari, at least) supports HTML5's database storage via SQLite. I'm trying to figure out how best to get the insert ID (there's an autoincrement field 'id' in the database) for the following…
ceejayoz
  • 176,543
  • 40
  • 303
  • 368
8
votes
5 answers

How to get the auto-increment primary key value in MySQL using Hibernate

I'm using Hibernate to access MySQL, and I have a table with an auto-increment primary key. Everytime I insert a row into the table I don't need to specify the primary key. But after I insert a new row, how can I get the relative primary key…
Neo
  • 169
  • 2
  • 4
  • 12
8
votes
3 answers

MySQL - autoincrement to guid

I have a table with an auto-increment ID field as shown below. +------------+-------------------------------------+ | company_id | name | +------------+-------------------------------------+ | 1 |…
Gaurav Sharma
  • 4,032
  • 14
  • 46
  • 72
8
votes
9 answers

How can I automatically increment numbers in C#?

I am using C# 2008 Windows Forms application. In my project there is a TextBox control and in that I want make an auto generate numbers for samples s00, next when I come back to form again it should be increment like s01,s02,s03......like that…
vamshi
  • 199
  • 2
  • 3
  • 5
8
votes
1 answer

Pylons, SQlite and autoincrementing fields

Hey! Just started working with Pylons in conjunction with SQLAlchemy, and my model looks something like this: from sqlalchemy import Column from sqlalchemy.types import Integer, String from helloworld.model.meta import Base class Person(Base): …
Maxfrank
  • 244
  • 2
  • 8
8
votes
4 answers

Can't set auto-increment via SQL Server Express Management Studio?

I just tried inserting value in to a database and that work. Now I insert again and I get an error for identical primary key. I can't find any option to alter it to be auto-increment. I'm updating the table via Linq-To-Sql. User u = new…
KdgDev
  • 14,299
  • 46
  • 120
  • 156
8
votes
4 answers

How to update id set from 1?

I have an id i.e primary key and auto increment. Is there any query to update my existing id and make my id start from 1 and next id 2 and so on.. For example id name 3 ABC 5 XYZ 9 PQR NOTE: id is already primary and auto increment and I…
Krity Shrestha
  • 333
  • 1
  • 4
  • 10
8
votes
8 answers

Is there any reason not to use auto_increment on an index for a database table?

I've inherited the task of maintaining a very poorly-coded e-commerce site and I'm working on refactoring a lot of the code and trying to fix ongoing bugs. Every database insert (adding an item to cart, etc.) begins with a grab_new_id function which…
goldenapples
  • 386
  • 1
  • 15
8
votes
4 answers

MySQL - how to use VARCHAR as AUTO INCREMENT Primary Key

I am using a VARCHAR as my primary key. I want to auto increment it (base 62, lower/upper case, numbers), However, the below code fails (for obvious reasons): CREATE TABLE IF NOT EXISTS `campaign` ( `account_id` BIGINT(20) NOT NULL, `type`…
Kenny Cason
  • 12,109
  • 11
  • 47
  • 72
8
votes
2 answers

Domain Driven Design Auto Incremented Entity Key

Just starting with Domain Driven Design and I've learned that you should keep your model in a valid state and when creating a new instance of a class it's recomended to put all required attributes as constructor parameters. But, when working with…
gsonego
  • 83
  • 1
  • 6
8
votes
1 answer

SQL: Creating a Relational table with 2 different auto_increment

I have 2 tables, each with their own auto incremented IDs, which are of course primary keys. When I want to create a 3rd table to establish the relation between these 2 tables, I always have an error. First one is that you can have only 1…
Ahmet Ertan
  • 103
  • 1
  • 5
8
votes
1 answer

Make PostgreSQL choose the next minimal available id

I would like to make PostgreSQL choose the first next available id so that no error occurs in the following case: CREATE TABLE test( id serial PRIMARY KEY, name varchar ); Then: INSERT INTO test VALUES (2,'dd'); INSERT INTO test (name) VALUES…
user4495098
  • 93
  • 1
  • 4
8
votes
4 answers

c# adding row to datatable which has an auto increment column

I've a datatable, with column A, B, C. I've set column A's "is identity" property to true, but I can't add any row to the table now. The code I'm trying is this: dsA.dtA row = dsA.dtA.NewdtARow(); row.B = 1; row.C = 2; dsA.dtA.Rows.Add(row); I'm…
John Smith
  • 2,291
  • 4
  • 22
  • 33
8
votes
2 answers

Sequences with composite primary key

Using PostgreSQL, how do I manage a sequence (auto incremented Integer id) for the following scenario- Table named 'businesses' which has 'id' and some more columns. Table named 'users' which has: a composite primary key, composed of a…
Alon Amir
  • 4,913
  • 9
  • 47
  • 86