Auto-increment and MySQL

I posted this in JDBC also but here too since I know many of you have probably dealt with this.
I have a database that looks like this (simplified)
idnum seqno
1234 1
1231 1
2342 1
2342 2
2342 3
3452 1
5676 1
3425 1
3425 2
I want the column "seqno" to auto_increment ONLY when the idnum is the same is the last. I can do this in Java but that means I have to do a SELECT to get the last seqno for the specified idnum and was hoping there was some way to do this in the database. Anyone know if this is possible?
thanks in advance,
Chuck

You can't do this with auto_increment. Using a SELECT to check for an idnum being used already will be the easiest way to go. Anything else would be too much work :)

Similar Messages

  • How to use auto-increment and search option for MS Access DB

    Dear All,
               I have configured our invoice in Adobe Livecycle and connected it to MS Acess 2007 as per http://forms.stefcameron.com/2006/09/18/connecting-a-form-to-a-database/.
    All is working fine, I can insert, retrieve data from DB to invoice and vice versa.
    Now I want few things to be implemented on our invoice.
    When ever I open our invoice, it populate the first entry from DB, Is it possible to populate the last entry ?
    Auto increment invoice number from MS Access DB every time we open our invoice after save.
    How to implement search option from DB for invoice number ?
    Please let me know if someone can provide me help on my scenario, so that I can share more stuff related to invoice and DB.
    Look forward to hearing soon from experts and other team members.
    Thanks & Regards
    Riyad...

    As far as I know there is not any auto increment data type in Oracle. Instead of this you should create a sequence and get the next value of the sequence while creating a row in your table.
    CREATE SEQUENCE Test_Sequence ;
    CREATE TABLE Test_Table ( Id NUMBER , Foo VARCHAR2(4) ) ;
    ALTER TABLE Test_Table ADD CONSTRAINT Test_Table_PK_Id PRIMARY KEY ( Id ) ;
    INSERT INTO Test_Table ( Id , Information ) VALUES ( Test_Sequence.NEXTVAL , 'FOO' ) ;

  • EjbCreate returns primary key - auto increment

    ejbCreate of a BMP entity bean must return the primary key.
    If i have an auto-incrementer (in MySQL) and i insert the new data in this method, how can i then find the primary key to return?
    Surely i cannot just use a select statement in another method as the other data in the table may not be unique and may not return the correct primary key.
    Help Please
    Thanks
    Dave

    Hi,
    PreparedStatement ps = con.prepareStatement("INSERT INTO food_data (description)" + " VALUES (?)");
    //Get generated primary key
    ResultSet res = ps.getGeneratedKeys();
    while (res.next())
    {     key = res.getInt(1);
    This code requires JDK 1.4.2.
    Any other soln for previous versions of JDK (1.4.1 or 1.3.1)
    Seetesh

  • Primary key column auto increment

    Hello,
    In my Azure SQL Database I noticed that weird thing is happening. I have table with primary key column with auto increment, and all works fine, on new insert that value automatically increment, but every now and then, that value, for no reason, increments
    for 1000.
    For instance i have in DB values in this order: 1, 2, 3, 4, 1001, 1002, 1003, 2004,  2005, 3001, 3002...
    Why is this happening? 

    Hello ,
    you can see this thread :
    http://stackoverflow.com/questions/17012339/windows-azure-sql-database-identity-auto-increment-column-skips-values
    It's seems that SQL Server work with sequence and block 1000 values. In the cloud, your SQL Azure Database can be move from one server to an other or restarted and so a new sequence is used. That's why you jump from 4 to 1001.
    Regards

  • Database :Auto increment in SQL server ID

    Hi,
    How can I do auto increment in SQL server primary column ID. Actualy I am writing the data into the SQL datbase table using LabVIEW and I wanted to set the auto increment to the primary key column ID.  I have three column in TEST_REPORT table i.e  Test_ID, Test_No and Test_Result. I wanted to set Test_ID as a primary key and set as a auto increment and write the value for only Test_No and Test_Result column
    When ever I am writing data into table the Test_ID is not getting auto incremented. I set that auto increment manualy through SQL server management studio.
    Please help me to fix this issue.

    Hi Palanivel,
    Thanks for the suggestion.
    Initially I was using same logic "query for TEST ID at initially"  but I have to query data from more than 20 tables  and write into it and its taking lots of space and query time.
    I am just looking for alternative of this. 
    Actually I am setting the auto incremnt  for TEST ID  through the SQL server managemnt studio but when ever I ignore the TEST ID column and write the data in rest column.  
    I gets the error message  "Insert Error: Column name or number of supplied values does not match table definition".  

  • Query on default serial(1) (auto increment)

    Hi all,
    1. is there a max integer value, when we create/add a column of type INTEGER?
    if yes,
    2. what happens when column value reaches that value?
        - does it starts from 1 again or what happens?
         Because, i want to create a table with a column of type INTEGER and it is enabled with auto increment and it is primary key. If i delete all rows(say, 100 rows) and insert values into it, it starts with 101... so i was wondering whether it starts with 1 again? or i should change the type of the column to some other type(VARCHAR()).
    thank you,
    regards,
    sudhir.

    hi
    try this sentence:
    ALTER TABLE schemaname.tablename COLUMN colname DROP DEFAULT;
    this eliminate default value and this recreate that value
    ALTER TABLE schemaname.tablename COLUMN colname ADD DEFAULT SERIAL (integer value);
    good luck

  • GenerationType.AUTO doesn't work correctly with Kodo and MySQL

    Greetings,
    I'm migrating applications from JBoss/Hibernate to WebLogic/Kodo. The following column annotation:
    @Id
    @Column(name="CUSTOMER_ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public long getCustomerId()
    is supposed to generate auto-increment primary key in mysql. This is what happens with Hibernate. With Kodo, this seems to be equivalent with GenerationType.TABLE as a table named openjpa_sequence_table is created, containing sequence values. So what should one do in order to be able to use true auto-increment strategy with MySQL and Kodo ?
    Many thanks in advance,
    Nicolas

    Hi Nicolas,
    By setting the generation strategy to AUTO, you're essentially letting the JPA provider choose which strategy to use. It looks like Kodo is using the TABLE strategy by default and Hibernate is using the IDENTITY strategy here. You can set the strategy to IDENTITY if you want Kodo to behave similarly to Hibernate. However, it's worth pointing out that there may be a reason for Kodo not using the IDENTITY strategy by default.
    The docs at: http://edocs.bea.com/wls/docs103/kodo/full/html/ref_guide_pc_oid.html#ref_guide_pc_oid_pkgen_autoinc
    point out the following:
    "Statements inserting into tables with auto-increment / identity columns cannot be batched. After each insert, Kodo must go back to the database to retrieve the last inserted auto-increment value to set back in the persistent object. This can have a negative impact on performance. "
    - Matt

  • How can I use a mySQL database schema with numeric auto increment primary key instead of GUID?

    Hello!
    I'm using the TestStand "MySQL Insert (NI)" database schema with GUID as primary key. So everything works fine.
    But I prever using numeric values as primary key, because the database is in conjunction with another database which uses numeric values as primary key.
    Is this possible?
    Has anyone an idea how I can modify the "Generic Recordset (NI)" for use with MySQL?
    Thanks!
    Configuration:
    Microsoft Windows XP
    TestStand 3.1
    MySQL 4.1.12a
    MySQL ODBC 3.51 Driver
    Brosig

    Adam -
    The TestStand Database Logging feature does not allow you to run a separate SQL command after executing the command for a statement(table), so I do not think that you can use an auto incrementing column for the tables. There is just no way to get it back in a generic way. One option that I tried is something similar to the Oracle schema where you call a store procedure to return a sequence ID for each record that you want to add.
    So you would have to create the following sequence table in MySQL:
    CREATE TABLE sequence (id INT NOT NULL);
    INSERT INTO sequence VALUES (0);
    Then create a stored procedure as shown below that will increment the sequence value and return it in a recordset:
    CREATE PROCEDURE `getseqid`()
    BEGIN
            UPDATE sequence SET id=LAST_INSERT_ID(id+1);
            SELECT LAST_INSERT_ID();
    END
    Then update the MySQL tables to use INT primary and foreign key values, so the TestStand MySQL SQL file to create all tables would have text like this:
    CREATE TABLE UUT_RESULT
     ID    INT  PRIMARY KEY,
    ~
    CREATE TABLE STEP_RESULT
     ID    INT  PRIMARY KEY,
     UUT_RESULT   INT  NOT NULL,
    ~
    Then update the schema primary and foreign key columns in the TestStand Database Options dialog box to be INT to match the table. For the primary key columns, you will have to set the Primary Key Type to "Get Value from Recordset" and set the Primary Key Command Text to "call getseqid()". This will call the stored procedure to determine the next value to use as the ID value.
    Hope this helps...
    Scott Richardson
    National Instruments

  • Prefixing and auto-increment field

    Hello
    I have a web application (php/mySQL) that has an auto-increment primary key field called job_id.
    Could anyone help me add a prefix to this?
    I want to add the year and month (YYMM/) in front of the field (e.g. 0811/1234 then 0811/1235 assuming current month and year is Nov 2008).
    Maybe Im wrong about adding the prefix to the primary key. Should I maybe add an additional field to maintain this?
    Any advice greatly appreciated...
    Regards
    Paul

    Hi Paul,
    MySQL table and column names may only consist of letters, underscores and numbers anyway, so the date format you´d like to use would lead to errors due to the forward slashes.
    Maybe Im wrong about adding the prefix to the primary key.
    I don´t know what you want to achieve with this approach, but I´d really leave the name of the Primary Key column "as is" and use a different column for storing data which contains such date values.
    Cheers,
    Günter Schenk
    Adobe Community Expert, Dreamweaver

  • Insert to 2 Tables and Auto-Increment

    I applied the Insert To 2 Tables Wizard and then added an Auto-Increment
    behavior to auto increment a field in the master table. BUT - I also
    need to auto-increment a field in the detail table. The AutoIncrement
    behavior only offers fields for the master table. So - how do I
    auto-increment the detail table?
    I know I could create a custom trigger - but how do you grab the primary
    key from the DETAIL table?
    Alec Fehl, MCSE, A+, ACE, ACI
    Adobe Community Expert
    AUTHOR:
    Microsoft Office 2007 PowerPoint: Comprehensive Course (Labyrinth
    Publications)
    Welcome to Web Design and HTML (Labyrinth Publications)
    CO-AUTHOR:
    Microsoft Office 2007: Essentials (Labyrinth Publications)
    Computer Concepts and Vista (Labyrinth Publications)
    Mike Meyers' A+ Guide to Managing and Troubleshooting PCs (McGraw-Hill)
    Internet Systems and Applications (EMC Paradigm)

    Got it. Advanced tab of the AutoIncrement server behavior - remove the
    master table and add the detail table. Then return to basic tab and add
    the appropriate field.
    Alec Fehl, MCSE, A+, ACE, ACI
    Adobe Community Expert
    AUTHOR:
    Microsoft Office 2007 PowerPoint: Comprehensive Course (Labyrinth
    Publications)
    Welcome to Web Design and HTML (Labyrinth Publications)
    CO-AUTHOR:
    Microsoft Office 2007: Essentials (Labyrinth Publications)
    Computer Concepts and Vista (Labyrinth Publications)
    Mike Meyers' A+ Guide to Managing and Troubleshooting PCs (McGraw-Hill)
    Internet Systems and Applications (EMC Paradigm)

  • MySQL Auto Increment Keys

    Is there a way to use MySQL Auto Increment Keys with Kodo?
    sean.

    Actually, I believe that the auto-increment support is in the current
    2.5.0 release (beta 2).
    -Patrick
    On Fri, 11 Apr 2003 22:11:02 -0400, Marc Prud'hommeaux wrote:
    Note that the feature isn't available in the current beta, but it will
    be available in the final release (which will be out "real soon now").
    In article <[email protected]>, Abe
    White wrote:
    I believe we've added some auto-increment support in our 2.5 beta,
    available here:
    http://solarmetric.com/Software/beta/2.5.0
    Patrick Linskey
    SolarMetric Inc.

  • Auto increment with collection is not working

    I am using KODO 3.0 with MYSQL 4.0.16. I have created two JDO object as
    follows
    BankAccount contains a collection of Contacts object. My metadata looks
    like this
    <class name="BankAccount">
    <field name="contacts">
    <collection element-type="Contacts"/>
    <extension vendor-name="kodo" key="element-dependent"
    value="true"/>
    </field>
    </class>
    <class name="Contacts" objectid-class="Contacts$contactId">
    <field name="contactId" primary-key="true">
    <extension vendor-name="kodo" key="jdbc-auto-increment"
    value="true"/>
    </field>
    </class>
    There is no problem in the persisting of BankAccount object and adding
    Contacts to it, but Contacts collation is not retrieved along with parent
    object. In the database join table, the contact Id value it is always set
    to null.
    Things are working well with out contact id in Contacts.
    Can anyone help?
    Regards,
    dharmi

    Set the following property:
    kodo.jdbc.AutoIncrementConstraints: true
    Described here:
    http://www.solarmetric.com/Software/Documentation/latest/docs/ref_guide_pc_oid.html#ref_guide_pc_oid_pkgen_autoinc

  • Retrieve new row's auto-increment key from dataprovider

    ** cross posted on SDN JSC Forum and Netbeans J2EE Nabble forum **
    I have a page that is bound to a MySQL table rowset or, alternately, a new (append()'ed) row. The row's Primary Key is a MySQL auto-increment Integer (translates to a Long.) After commit()'ing the the new row to the database, how would I then get the new row's ID (fieldname "ID")? If I refresh() the dataprovider and try to get the value an error is thrown.
    Some background: The dataprovider's backing rowset has a query parameter for the ID field. I set it to "0" if the page is creating a new row or I set it to the unique ID if the page is displaying an existing row. After the new row is committed, I need the new ID set the query parameter and synch up related rows in different tables that are keyed off the ID in this (master) table. I'd like to do this without "guessing" what the ID would be in advance as that method isn't foolproof in heavy usage.
    Additionally, it strikes me as a useful workaround if the unique ID was a UUID (mySQL UUID() function) that does not run the risk of any concurrency issues. Has anyone used this solution in VWP? How would I make the call for the underying DB (in this case MySQL, but could be anything) to generate the UUID? Is the call DB specific or is there a JDBC equivalent?
    UPDATE: never mind the GUID question, I can use the java.rmi.dgc.VMID class to autogenerate unique GUID's for this purpose. Being from a Lotus Notes background, I'm used to the power and flexibility such Unique ID's bring to the app. dev's portfolio.
    Thanks in adv. for any help .
    -Jake
    Message was edited by:
    jakeochs

    JSF together with JBoss Seam offers some real good possibilities to improve developer productivity. Right now, with JSF you can create forms where fields are persistent (saved in a database), but you have to write code to persist fields. In Notes/Domino, every field you drop in the form is automatically set to persist without writing a single piece of code. JBoss Seam aims to provide the missing glue to tie the JSF beans with business logic (EJB) and persistent layer (JPA). I think tools for Seam are still not mature. I would love to see JSC/VWB utilizing Seam. I know there is a NetBean plugin for Seam but it was written for old NetBeans (not VWP or JSC), so it doesn't work with the visual web pack where you can drag and drop JSF components.

  • How to get auto-increment value after insert on ACCESS db?

    When you insert a new record to a table with an auto-incrementing key, how do you find the value for the row you just inserted? This works differently with different databases. I know how it's done on ORACLE and mySql.
    How does it work with ACCESS through ODBC? How about MSSQL?

    I have discovered there's a LAST aggregate function which when I've tested it gets the just inserted auto-increment, but I'm not sure if it's reliable. You have to do:
    SELECT LAST(index-field) FROM table
    That ought to be faster than MAX, which I've noticed some people use. Persumable LAST will get the value from the last row in the table's natural order.
    In fact an auto-increment field has no business filling in missing slots since the main point is a a foreign key in other tables and a foreign key pointing to a deleted table row ought to be invalidated, not point to some unrelated successor record.
    I could use a separate table as a source of counters, of course, though that's one more call. In either case I'm worried about thread safety. In Oracle there are special sequence objects for this purpose which are incremented and read atomically. I'm not sure if the access driver transaction handling works adequately.
    Perhaps the safest approach might be to use a separate sequencer table and Java sychronisation to serialise access to each row in the sequencer table (assuming all the access is from the same app).

  • Set a max Upload quantity dreamwaver php and mysql

    The issue,
    using dreamweaver php and mysql I Would like to set a max
    quantity limit on file upload per user. i.e max 5 uploaded images
    allowed per user.
    Here is a basic example of the creation. Just need the
    implementation of how to set a max upoad limit.
    create table authors(
    id int not null auto increment primary key,
    name varchar(10) not null
    image_quantity tinyint(1),
    create table images(
    aid int not null,
    image_filename varchar(50),
    foreign key (aid) references authors(id)
    User id 1 would upload a file into the table images from a
    php or html webpage. i.e set values "thomas.jpeg", "1"
    i want to set a max upload of 5 images per user. (a folder
    for each user id will be created and photos stored in that).
    I could add a field of max_upload tinyint(1) to the table
    users and construct a php script that could add the amount of
    images entered by a user into the images table and add a +1 to each
    added. Problem is i dont know how to create that script or mysql
    querty in order to enter into a recorset for example.
    As anyone have any ideas of the best way to set a max
    quantity limit of uploads.
    Thank you.

    The issue,
    using dreamweaver php and mysql I Would like to set a max
    quantity limit on file upload per user. i.e max 5 uploaded images
    allowed per user.
    Here is a basic example of the creation. Just need the
    implementation of how to set a max upoad limit.
    create table authors(
    id int not null auto increment primary key,
    name varchar(10) not null
    image_quantity tinyint(1),
    create table images(
    aid int not null,
    image_filename varchar(50),
    foreign key (aid) references authors(id)
    User id 1 would upload a file into the table images from a
    php or html webpage. i.e set values "thomas.jpeg", "1"
    i want to set a max upload of 5 images per user. (a folder
    for each user id will be created and photos stored in that).
    I could add a field of max_upload tinyint(1) to the table
    users and construct a php script that could add the amount of
    images entered by a user into the images table and add a +1 to each
    added. Problem is i dont know how to create that script or mysql
    querty in order to enter into a recorset for example.
    As anyone have any ideas of the best way to set a max
    quantity limit of uploads.
    Thank you.

Maybe you are looking for

  • Is it possible to request free hardware/software if i prove need & desire?

    My name is Christopher Kelly... I'm a severely handicapped individual - im wheelchair bound and only have the use of one arm.. I type with three fingers on one hand, and have wanted to be a freelance writer / novelist my entire life.. Unfortunately,

  • After updating OS to 10.9.3 iTunes can't see my iPhone over Wi-Fi.

    After updating OS on my Retina MacBook Pro to Mavericks 10.9.3 with iTunes 11.2 I succesfully transfer one album over Wi-Fi to my iPhone 5 with iOS 7.1.1. Then I decided to transfer another, but when I drop the albums to iPhone on my iTunes, iTunes s

  • Queries regarding Year End Closing Activity

    Hi Experts/Moderator, I need solution to my queries regarding Year End Closing Activity?  1. How can we post adjustment entries to GL/AR/AP/BANK/ASSET accounts in the previous FYu20192008 in Apr/May/Jun/Julyu20192009 using Special Posting Periods, if

  • Can't pair iPhone 5 with 2005 Acura TL or 2009 Lexus RX350 after IOS 7 upgrade!

    Ever since I upgraded to IOS7, I have not been able to connect my iPhone 5 to the bluetooth in my car (2005 Acura TL). I tried to delete the pairing and re-pair, but the phone can no longer find the bluetooth device! I also tried to pair to my wife's

  • Are macs as good as they appear to be?

    Today I was trying to download something from my email (which I know where they came from.) and rename and put on to iTunes with that name but everytime I put it on iTunes it changed it back to what it was before, it took hours to finish and I didn't