DB Adapter - PostgreSQL - Primary key - auto increment handling

Hi,
I have to connect to a PostgreSQL DB. I have a table in which has a primary key called seq_id. This seq_id is being incremented using a sequence.
I have to configure the DB adapter for this table. The problem is that while creating the adapter it does not allow me to deselect the primary key (seq_id). Because of this I have to supply a value for the seq_id while inseting the data using the adapter. But this defeats the purpose of sequence (auto increment).
Is there a way to get around this and to avoid specifying the value for seq_id while using the DB Adapter and let it get inserted using the sequence of the DB?
Thanks,
Sanjay

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

Similar Messages

  • 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

  • Insert into table returning primary key (auto number) in resultset

    Hi,
    I'm connecting to Oracle 10g via JDBC (ojdbc14.jar).
    My SQL statement is as follows:
    INSERT into Student (studentName, phone, email, address) values ('Jason', '12345678', 'test', 'test');
    SELECT Student_studentId_SEQ.NEXTVAL FROM DUAL;
    Fyi -The Student table has a trigger to support the generation of a primary key (integer) based on a sequence when a new record is inserted.
    What the above will do (from the Java app point of view) is to create a Student record and automatically select the student ID so that the student ID can be accessed via the resultset in Java.
    I'm getting error "ORA-00911: invalid character". Can you please help?
    Regards,
    Jason
    Edited by: user10394130 on Oct 13, 2008 2:40 AM

    Yes, I'm referring to the studentId, which is generated via the Student table trigger on insert of a new record.
    I've now verified that the following SQL works and it is "printing" the correct studentId.
    DECLARE seqNbr_studentId NUMBER(12) := 0;
    BEGIN
    INSERT into Student (studentName, phone, email, address) values ('Jason', '12345678', 'test', 'test')
    RETURNING studentId INTO seqNbr_studentId;
    dbms_output.put_line(seqNbr_studentId);
    END;
    --> This prints the correct value of seqNbr_studentId that has been generated by the trigger. This is good.
    However, I would like the studentId to be in a resultset (so that I can access this via Java Resultset.getInt(1) ), for example:
    DECLARE seqNbr_studentId NUMBER(12) := 0;
    BEGIN
    INSERT into Student (studentName, phone, email, address) values ('Jason', '12345678', 'test', 'test')
    RETURNING studentId INTO seqNbr_studentId;
    SELECT seqNbr_studentId FROM DUMMYTABLE;
    END;
    Is this possible?
    What I'm trying to do is to achieve the effect in SQL Server where I can simply do an SQL command "SELECT @@IDENTITY" where it returns the auto number from the newly inserted record.
    Regards,
    Jason
    Edited by: user10394130 on Oct 13, 2008 2:08 AM
    Edited by: user10394130 on Oct 13, 2008 2:56 AM

  • Auto incremented field mobile device

    hello,
    my colleague requires to make a mechanism in the mobile device (oracle lite client) where the primary field of a table is automatically incremented.
    according to the documentation in order to make that happen in a consistent manner so that all clients can sync correctly without ambiguities , we created a sequence
    through the MDW and attached it to the publication. then with the sync , this sequence has been downloaded to all clients and each one has a specified window.
    now we suppose that we must create the trigger that uses this sequence in order to provide the correct primary key field.
    lets say that the sequence is names SYSTEM.AUTOINCSEQUENCEA
    the table is named SYSTEM.TABLEA
    and the primary key that we want to auto incr is named ID.
    the trigger we suppose that should look like:
    CREATE TRIGGER SYSTEM.TRIGGERTABLEA
    BEFORE INSERT
    ON SYSTEM.TABLEA REFERENCING NEW AS New OLD AS Old
    FOR EACH ROW
    BEGIN
    select AUTOINCSEQUENCEA.nextval into :new.ID from dual;
    END ;
    1)But if i execute this from the msql on the client device (mobile windows device) it returns a "syntax error". how can i create the trigger that i need which will use my sequence in order
    to appoint the new values on the primary key (auto incremented field??) .
    2)if i cant do it through a normal sql statement then how can i do it?
    thank you

    You need Java Store Procedure as the trigger. PL/SQL is not support on the Oracle Lite client.
    Let me know if you need an example on how to do this.

  • How to re-order automatically the number of primary key column in MySql that has been set as auto_increment if one of the row deleted?

    Hello,
    Can anyone show me the way how to re-oder automatically the number of primary key that has been set as auto_increment in mysql database when the row deleted?
    example:
    No (primary key=auto increment)|
    Name |
    AGE |
    1
        | JO
    | 21
    |
    2
        | Kyle
    | 25
    |
    3
        | Macy
    | 30
    |
    When delete 1 row:
    No (primary key=auto increment)|
    Name |
    AGE |
    1
        | JO
    | 21
    |
    2
        | Macy
    | 30
    |

    Hello,
    This is not a VB.NET question, best to ask this question in
    MySQL forum.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

  • Auto Increment Primary Keys

    I am trying to migrate from SQL Server. I want to setup tables which generate sequencial Primary keys on adding records to the table. I have a VB application which is using ADO with an ODBC connection. How does one use the Oracle Enterprise Console Manager to set a Primary Key to increment on the adding of new records automatically. In SQL Server one just needs to set an Identity, Identity Seed and Identitiy Increment. In Access there is a datatype called AutoNumber. Help would be greatly appreciated. I am using 9i with a standalone Enterprise Console Manager. Thanks in Advance.

    You first have to create a sequence and then the trigger below:
    Instead of data in single quotes(') you must specify the appropriate for your db names
    CREATE OR REPLACE TRIGGER 'Schema'.'trigger_name' BEFORE
    INSERT ON 'table_name'
    FOR EACH ROW
    BEGIN
    SELECT 'sequence_name'.nextval into :new.'column_name' from dual;
    END
    ;

  • How to "auto" generate "Primary Key" in custom table?

    Hi Folks,
    Requirement:
    I need a function module or program that can create automatically a primary key.
    Scenario:
    I have a program that creates an entries and save it to a custom table at the same time, but a primary key should always be generated respective to the entries saved.
    Example:
    Material(MATNR) 4001001, Plant(WERKS) XX01, ID[Primary Key-auto generated]
    (I'm thinking of a similar concept/logic on how a unique IDOC number is being generated or how SAP standard creates a unique entry)
    I try to look for any SAP FM that can generate a PK, but there's no luck.
    Thanks.
    Regards,
    Jun

    Hi Keshu and All,
    The links are helpful, however:
    #1. I don't have authorization to create a new object in transaction SNRO, but the way I see the objects in SNRO is just for defining the length(number of characters) for the ranges that will be use if I'm not mistaken.
    #2. FM NUMBER_GET_NEXT - yes it can populate incremental unique entries but it's only occurring at runtime ?? So when the program get terminated it's not being saved nowhere.
    So after if I use FM NUMBER_GET_NEXT, I always have to look for all the last primary key in my custom table, then target it as my starting point for creating a new PK.  I think this will give a performance issue, any comments?
    For better visualization, I have scenario:
    1.  (ZQ_CREATE_PK) Create unique incremental PK for material, batch, so on..
    2.  Append line/entries to ZQ_TABLE
    3.  Repeat #1 and #2
    4.  User exits the program
    5.  Back to 1 --> At this point, I need to get the "LATEST" PK then start this as a starting point again to generate PK and append it to ZQ_TABLE
    I'm assuming that SAP has other SAP FMs related in creating this scenario.   Similar to IDOC # creation..
    Thanks.

  • Primary Key in tabular form is not a number

    I created a table called tblRegions.
    The primary key is RegionCode(VarChar2) - example - USA.
    I then tried to create an updateable Tabular Form using tblRegions, but it won't let me choose the primary key as an updateable field.

    O.K.
    1. create a trigger which will populate a real primary key out of a sequence - search internet
    on triggers and sequences in oracle
    2. use this primary key for tabular form processing
    3. if you need a manually entered pseudo (fake) primary key, you can handle this column
    as any other - tabular form will not complain about it
    4. you may create a constraint on your table, which will take care this column is allways
    populated and unique - this is not the nicest way since it involves processing and the errors
    you gat may not look user friendly. However, this is the most secure and easiest way -
    you don't need to write any code on the application side to handle eventual errors.
    Search internet on constraints.
    5. you may decide to create a manual validation process to fetch the eventual errors
    before you commit the changes to the database. This forum is full of the threads on
    the topic "tabular form" and "manual creation of tabular forms". If you are new to apex,
    you should stay away from that for the first (this is only my opinion).
    Denes Kubicek

  • Primary key violation exception in auto increment column

    Hi All,
    I am facing one issue in Multi threaded environment.
    I am getting Primary key violation exception in auto increment column. I have a table and the primary key is the auto increment column, and I have a trigger which is populating this column.
    5 threads are running and inserting the data in the table and throwing Primary key violation exception randomly.
    create table example (
    id number not null,
    name varchar2(30)
    alter table example
    add constraint PK1example primary key (id);
    create sequence example_id_seq start with 1 increment by 1;
    create or replace trigger example_insert
    before insert on example
    for each row
    begin
    select example_id_seq.nextval into :new.id from dual;
    end;
    Any idea how to handle auto increment column(trigger) in Multi threaded environment??
    Thanks,

    user13566109 wrote:
    Thanks All,
    Problem was in approach; removed the trigger and placed a seq.nextval in insert query. It has resolved the issue.I very much suspect that that was not the issue.
    The trigger would execute for each insertion and the nextval would have been unique for each insertion (that's how sequences work in oracle), so that wouldn't have been causing duplicates.
    I suspect, more likely, that you had some other code somewhere that was using another sequence or some other method of generating the keys that was also inserting into the same table, so there was a conflict in the sources of the sequences being generated.
    The way you showed you had coded above, was a perfectly normal way to assign primary keys from a sequence, and is not a problem in a multi user/threaded environment.

  • How to get the auto increment integer primary key value of a new record

    I have a DB table that has a auto increment integer primary key, if I insert a new record into it by SQL statement "INSERT INTO...", how can I get the integer primary key value of that newly created record?

    Well maybe someone knows a better method, but one workaround would be to add a dummy field to your table. When a new record is inserted this dummy field will be null. Then you can select your record with SELECT keyField FROM yourTable WHERE dummyField IS NULL. Once you've got the key number, you then update the record with a non-null value in the dummyField. Bit of a bodge, but it should work...
    Another alternative is, instead of using an Autonumbered key field, you could assign your own number by getting the MAX value of the existing keys (with SELECT MAX(keyField) FROM yourTable) and using that number + 1 for your new key. Might be a problem if you have lots of records and frequent deletions though.

  • CMP with auto-increment primary key.Please help

    Hi all,
    I new with EJB technology so please bear with me.
    Env: 2k Server, SQL 2k Server
    Sun One(Forte EE) to develop and deploy CMP
    I got the servlet to load the data from CMP's business mehods
    is fine. Calling the findPrimaryKey is OK too. Even when I try to insert the row into DB is OK. At this time I make key PK is int AND NOT
    AUTO INCREMENT everything is OK. In the ejbCreate method
    I called setPK, setName ...It's fine.
    The problem comes when I try to make the PK(still int) to be auto-increment field.In ejbCreate not call setPK because of in SunOne IDE, under the J2EE RI tab of EJB Module property, the Auto generate SQL I set to false so that I can
    modify the SQL statement under SQL Deployment.createRow not taking the PK. I thought that will do it but it doesnot like it at all (I got Exception with transaction rollback)I just want to insert a single row with ID and name that's all.
    Then I changed the SQL statment take PK and changed the Auto Generate SQL to True and in ejbCreate the PK as one of the args and called setPK this time with null object. It doesn't like neither.(Exception Cannot set the primary key with null. That is reasonable.)
    I thought using EJB fast and clean technique would help developer to develop application with easiness.
    So I realy stuck with this, I wonder ejb 2.0 support for auto increment at all because I would like to take advantage of the auto increment feature of the DB without writing the PrimaryKeySequence generator at all.
    Am I missing something with this? May be just config thing to tell
    that my PK is auto-increment field so that when the ejbCreate called it knows not taking the PK or even not asking to call setPK in ejbCreate.
    Any help would appreciated.

    Check out this thread, there's a bunch of good info:
    http://www.theserverside.com/patterns/thread.jsp?thread_id=4976

  • 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

  • Utilizing auto-increment/identity fields for primary key with "application" identity

    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?

    To the best of my knowledge, you cannot use auto-increment. Due to the
    differences in the way that identities are generated at the datastore
    (upon insert) vs. JDO (upon makePersistent), this feature of SQLServer is
    not supported yet.
    However, we do provide a variety of other ways of generating identity
    which may provide a closer fit to what you want, and
    our users may have some experience in solving your problem.
    On Tue, 28 Jan 2003 09:56:08 +0000, Sean Ryan wrote:
    Is it possible to utilise an auto-increment (identity in MS SQL Server)
    field for the primary key field when using "application" identity?--
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • Auto Increment of primary key value in jdeveloper.

    hi all,
    i have one table with one primary key.
    i want to increment that primary key when ever i go for CreateInsert or create operation in JSF page.
    i have tried with db sequence value type, but i was not able to achieve my condition. in DB Sequence i got error like cannot convert java.class.string to java.class.dbsequence.
    can any one suggest me in this to achieve my condition.
    regards,
    M vijayalakshmi.

    hi all,
    from this i found the simple method to achive the auto increment of primary key.
    http://www.techartifact.com/blogs/2012/10/adding-number-for-primary-key-in-oracle-adf-using-groovy-by-sequence.html#ixzz2EeU9CWo6
    in this am facing an one small issue.
    intial value of the primary key is 1.
    for this value i have entered the row of data.
    again i have clicked on the create button.
    then the value of the primary key has increased to 2.
    for this value i didnt entered the row of data to databse.
    just i closed the browser.
    if i run the run page again, the value of primary key is 3.
    my requirment is i shd get the value of primary key is "2".
    the increment shd happen the maxi value present in the primary key of the table.
    can any one help me in this how to achive this.
    thanks in advance.
    regards,
    M vijayalakshmi.

  • 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

Maybe you are looking for

  • How do I find out my server password?

    I just bought my third Mac, this one is a new Macbook Pro. I already have a white 2007 Macbook, and a 2009 iMac. With buying this one, I figured I'd start using file sharing, which I haven't done before. But, with that, I ran into a few problems: my

  • JS [CS3]. Specify a Default Folder in openDialog()

    Is there a way to specify that folder just like we can in selectDialog(prompt, default folder object)??? Otherwise the openDialog shows the last folder accessed by the user. Or can we modify the Window's Environment variable? Thanks, Alex

  • Embedding a pdf file in 10g reports

    Hello Dears, I need to embed some pdf file into my .rdf report in 10g. I have already done this in forms 10g through bean pdfviewer but i dont know how to do that in reports. Please help Qazi

  • Please would you stop bundling Anti-Virus software with Adobe Reader?

    I would be really grateful if Adobe would stop bundling Anti-Virus software with the Adobe Reader updates. Pre-selecting  the (download - Anti virus software) check-box in the dialogue box smacks of sharp practice. I have nothing against Anti-Virus s

  • Maximum number of messages sent to a Queue?I hav

    I am currently using Glassfish v2.1 and I have set up a queue to send and receive messages from with Sesion beans and MDBs respectively. However, I have noticed that I can send only a maximum of 1000 messages to the queue. Is there any reason why I c