auto-increment

SQL-How to Insert Row Without Auto incrementing a ID Column?

I have a table that has a forced auto increment column and this column is a very valuable ID that is retained through out the entire app. Sorry to say it was poor development on my part to have this be the auto incrementing column. So, here is the problem. I have to insert into this table an ID for the column that has already been cre...

How to prevent primary serial primary key from being updated with number not in sequence?

CREATE TABLE u_account ( Jid serial primary key, score int4 ); The primary key works fine (updates itself) ok when I update it like this; INSERT INTO u_account ('score') VALUES ('122233344'); However when I insert a value like this; INSERT INTO u_account VALUES ('122233344'); This updates the primary key; I don't want the primar...

Auto increment a value in Django with respect to the previous one

Is there a way to autoincrement a field with respect to the previous one...e.g if the previous record has the value 09-0001, then the next record should be assigned 09-0002 and so one...ideas? I'm thinking of overriding the save method, but how exactly I'm not so sure ...

auto_increment no longer increments

In a MySQL table the id column is set to auto_increment and the next auto_increment is set to 128 in phpmyadmin, but any new rows added have 127 as the value in the id row. I have no idea why. Changed the column from tiny-int to int and everything working now, cheers. ...

How to force MySQL to take 0 as a valid auto-increment value

Long story short, I have a SQL file that I want to import as a skel style file, so this will be done repeatedly, programmatically. I can edit the SQL file however I want, but I'd rather not touch the application itself. This application uses userid = 0 to represent the anonymous user. It also has a relevant (blank) entry in the database...

I need to auto_increment a field in MySQL that is not primary key

Hey everyone, Right now, I have a table whose primary key is an auto_increment field. However, I need to set the primary key as username, date (to ensure that there cannot be a duplicate username with a date). I need the auto_increment field, however, in order to make changes to row information (adding and deleting). What is normally ...

Oracle and auto_increment/identity

In modern versions of Oracle, is there some "standard" (stored procedure, additional CREATE syntax, etc.) way to setting up a table with auto_increment/identity style column, or are we still stuck manually creating the table, creating the sequence, and creating the trigger. Update: I realize Oracle has no concept of an auto_increment. ...

Is there an autoincrement-per-user field in Django?

I was wondering if there is already a way to create a separate autoincrement-ID-per-user field in Django? Basically, I'm storing many related models and I need the IDs generated to be autoincrement per user. I don't want to change how id works, just need a new field that I can add which is unique=True per user. Any suggestions (other ...

Conditional Auto increment in xsl

I have an XML some thing like <V> <W> <X>1</X> </W> <W> <Y>1</Y> </W> <W> <X>1555</X> </W> <W> <X>1</X> </W> </V> i want to make it something like this <entity ID="start"> <f ID="NewField">0001</f> <f ID="NewField">0001</f> <f ID="NewField">0002</f> <f ID="NewField">0003</f> </enti...

Get next auto increment

I know this isn't so complicated but I can't remember how to do. I just need to know the next auto increment. $result = mysql_query(" SHOW TABLE STATUS LIKE Media "); $data = mysql_fetch_assoc($result); $next_increment = $data['Auto_increment']; ...but i won't work for me, what am I doing wrong? ...

Is ther a way to retrieve the autoincrement ID from a prepared statement

Is there a way to retrieve the auto generated key from a DB query when using a java query with prepared statements. For example, I know AutoGeneratedKeys can work as follows. stmt = conn.createStatement(); stmt.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS); if(returnLastInsertId) { ResultSet rs = stmt.getGeneratedKeys(); ...

help creating a custom auto increment function in mysql

Hello, I would like to create an auto increment function that allows me to maintain uniqueness in designated columns across multiple tables. I understand that this is not supported under mysql's standard functions, but it appears that this can be done by hand. Could someone point me in the right direction? Thanks ...

Difference in behavior for SET IDENTITY_INSERT from SQL Server 2000 to 2005?

I have an application that (currently) needs to uses DBs served by both SQL Server 2000 and SQL Server 2005. I'm trying to move a DB programmatically from one server to the other. All of the tables I use each have a primary key that is autoincremented. Since these autoincremented keys are used as foreign keys in other tables, my plan ...

Un-committed database transactions and auto-increment columns

I encountered some curious behavior today and was wondering if it is expected or standard. We are using Hibernate against MySQL5. During the course of coding I forgot to close a transaction, I presume others can relate. When I finally closed the transaction, ran the code and checked the table, I noticed the following. All the times I...

MySQL Auto Increment Values After DELETE without WHERE

i noticed after i ran DELETE FROM tablename my ID (auto increment) valus became weird 7, 8, 9, 0, 1, 12, 3, 4, 15 in this order when i do a SELECT * FROM tablename i know that the certification guide says that IDs may or may not be reset when DELETE without WHERE is used to empty a table, but what caused the ID sequence to be s...

IDs for Information on More Than One DB/Server

I'm working on a project that I want to have be as flexible and scalable as possible from the beginning. A problem I'm concerned about is one best described by Joshua Schacter in Founders at Work, who noted it as one detail he wish he would've planned for ahead of time. Scaling past one machine, one database, is very challenging, eve...

Get autoincrement id after an insert query performed with a prepared statement

If I execute an insert query with a stored procedure with php and the mysqli_* functions, is there a way to retrieve the value of an autoincrement id field? mysqli->insert_id does not seem to work. ...

In MySQL 5.0, can one insert into a table with an auto_increment column without updating the auto_increment value?

I have a MySQL database, containing a table with an auto_increment primary key. Consider the following definition as sufficient for this example: create table test(id integer not null auto_increment primary key) engine=innodb; Now, typically I would insert into this table using the following syntax: insert into test() values(); Th...

Is there a way to emulate auto_increment on a second column in MySQL?

I think this is more clear than my last version: I have a table that already has a PK field starting with 1 that is already set for auto-increment. I would like to add a new field that does not start with 1, instead starting with an arbitrary number (think invoice number) and also automatically increments. Apparently, you can only have ...

MySQL - second sequence in table (e.g. by category)

Hi all, I'm trying to find the most efficient way to do something and would appreciate your advice! I have a table with the following columns: id category category_sequence other_columns id is an auto-increment column and the primary key. The category is selected by the user on the UI. What I'd like to do is generate a category_seq...