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
7
votes
1 answer

How to enable auto-increment in letters(A, B, C, D...) in SQL SERVER 2008?

I am new for SQL SERVER. I found how to auto increment numbers for column. CREATE TABLE Region ( RegionId int IDENTITY(1,1), RegionName varchar(50), ); Question: How to enable "auto increment" in letters(A, B, C, D...) like this?
Joe Richard
  • 1,520
  • 7
  • 20
  • 31
7
votes
2 answers

How to define an auto-increment number for LDAP structure?

I have one attribute (groupIDNumber), I want to make it work as auto-increment number? How can we define that attr? Thank for your help, -nm
nm.
  • 71
  • 1
  • 2
7
votes
8 answers

PHP short unique ID generation using auto_increment?

I would like to generate a short, unique ID without having to check for collisions. I currently do something like this, but the ID I currently generate is random and checking for collisions in a loop is annoying and will get expensive if the number…
Daren Schwenke
  • 5,428
  • 3
  • 29
  • 34
7
votes
3 answers

DBCC CHECKIDENT RESEED -- is new value required?

All the documentation I read about reseeding suggests something along the lines of: SET @maxIdentityValue = (SELECT MAX(id) FROM tablename) run DBCC CHECKIDENT('tablename', RESEED, @maxIdentityValue) And yet it appears to me that a simple DBCC…
Jordan Reiter
  • 20,467
  • 11
  • 95
  • 161
7
votes
4 answers

Primary key id reaching limit of bigint data type

I have a table that is exposed to large inserts and deletes on a regular basis (and because of this there are large gaps in the number sequence of the primary id column). It had a primary id column of type 'int' that was changed to 'bigint'. Despite…
DrNoFruit
  • 185
  • 1
  • 3
  • 12
7
votes
4 answers

MySQL: Multiple Primary Keys and Auto Increment

I'm quite new to setting up tables in MySQL and there is something I'd like to do which is a bit more advance than I'm able to do. I have two columns as part of a composite primary key, one is a Date and an ID I would like to be an auto increment…
AdmiralJonB
  • 2,038
  • 3
  • 23
  • 27
7
votes
4 answers

How can I get the auto incrementing field name or the primary key fieldname from a mysql table?

In PHP, how do I get the field name of the field that's been set as to auto increment when a new rec is added to it? In most cases, it's the same as the PRIMARY_KEY of the table but not necessarily always. So this question has 2 parts with the…
Average Joe
  • 4,521
  • 9
  • 53
  • 81
7
votes
4 answers

Increment autoincrement id field by one

I have a MySQL 5 server and a table in it with an autoincrement on an id field (primary key). Now I want to add a record in between and so I have to increase all other ids by one. This is what I tried: UPDATE myTable SET id=id+1 WHERE id >= 53 This…
testing
  • 19,681
  • 50
  • 236
  • 417
6
votes
5 answers

Unable to find a generated key in Java using PreparedStatement's getGeneratedKeys()

I have a query as follows: String SQL = "insert into table (id, name) values (sequence.nextval, ?)"; I then make a PreparedStatement like this: //initiate connection, statement etc pStatement = connection.prepareStatement(SQL,…
arnehehe
  • 1,386
  • 1
  • 17
  • 33
6
votes
1 answer

MySQL table incrementing by 10 for some reason

The id field in a mysql table is incrementing by 10 (11, 21, 31) for some reason. Here is the table definition: CREATE TABLE `clients` ( `id` int(11) NOT NULL auto_increment, `first_name` varchar(255) default NULL, `last_name` varchar(255)…
Nathan Verni
6
votes
3 answers

Updating generator value issue

I'm currently working on modifying a Firebird v. 1.5 database. The database structure will be modified running queries from a delphi application using interbase components, the problem I'm facing is that I need to run a lot of queries, some of which…
user497849
6
votes
2 answers

SQL Server: Retrieve auto-incremented ID inside a stored procedure?

My database has a parent table with an auto-incrementing primary key identity 'ID', and a normal 'TIMESTAMP column'. I have child tables with a foreign key that refer to the parent 'ID' column. I want to write a stored procedure that inserts a new…
CookieOfFortune
  • 13,836
  • 8
  • 42
  • 58
6
votes
2 answers

Macro, automatically adding one to a value

I have a problem with macro in notepad++ Just needs to have value automatically changed to +1 (from current value) So the values should be like this 1000, 1001, 1002, 1003 and so on for the coming values between the MEDIA_ID tags..
user1067455
  • 61
  • 1
  • 3
6
votes
1 answer

Master-Master replication broken with "Duplicate entry for key 'PRIMARY'" due to AUTOINCREMENT

We use Master-Master replication to avoid situations in which writing to replica will get it out of sync with the real master and in case we wish to switch masters. However, there's a seemingly known problem with AUTOINCREMENT fields which causes a…
Collector
  • 2,034
  • 4
  • 22
  • 39
6
votes
7 answers

How do I make another MySQL auto increment column?

MySQL doesn't support multiple auto increment columns. CREATE TABLE IF NOT EXISTS `parts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `order` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT…
Basem
  • 443
  • 2
  • 7
  • 15