Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2004
    Posts
    16

    Exclamation Unanswered: what is the autonumber datatype for DB2

    I am used to using SQL server and access, what is the command for an autonumber is it an identity type? how do you set things like where you want it to begin?

    Thanks for the help guys

  2. #2
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    Quote Originally Posted by jpalazzi
    I am used to using SQL server and access, what is the command for an autonumber is it an identity type? how do you set things like where you want it to begin?

    Thanks for the help guys
    Identity:
    CREATE TABLE A (
    ID INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY ( START WITH +1 , INCREMENT BY +1 , NO CACHE )
    );

    See the SQL Ref for more detail, but that's the bones of it.
    --
    Jonathan Petruk
    DB2 Database Consultant

  3. #3
    Join Date
    Nov 2004
    Posts
    16
    I got the create table to work.
    I tried an insert though and it keeps erroring out.

    I did: insert into test values(smith);

    i made 2 fields id which was the autonumber and then one that was lname and it was char.

    any ideas?

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Your insert should be:

    insert into test (lname) values('smith');


    Andy

  5. #5
    Join Date
    Nov 2004
    Posts
    16
    that seemed to work , but i thought you didnt have to put the fields you are inserting into as long as they were in the same order?

  6. #6
    Join Date
    Mar 2004
    Location
    Toronto, ON, Canada
    Posts
    513
    Quote Originally Posted by jpalazzi
    that seemed to work , but i thought you didnt have to put the fields you are inserting into as long as they were in the same order?
    If you have 2 columns and you're only supplying a value for 1, you need to supply the column list. The implicit column list only works if you're providing all values.
    --
    Jonathan Petruk
    DB2 Database Consultant

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •