Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004
    Posts
    110

    Unanswered: INSERT stattement syntax (autoincrementing field)

    Hello everybody

    I`ve created a table with just three fields. The first is an auto incrementing integer field and the second is a string. Finally, there exists a third Boolean field. The SQL statement used to create the relation (table) is shown below :

    CREATE TABLE TEXNIKOS(Kwd_Texnikou INTEGER UNSIGNED AUTO_INCREMENT,
    Onomatepwnymo VARCHAR(30) NOT NULL,
    Eswterikos BOOL,
    PRIMARY KEY(Kwd_Texnikou)) TYPE=INNODB;

    Since my first field is an auto integer, I was wondering what syntax I have to use in order to Insert a record in this table?

    thx, in advance

    George Papadopoulos

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you can either assign a NULL to it, assign a value to it, or leave it out of the statement altogether:
    Code:
    insert into TEXNIKOS
    values ( null, 'foo', true )  
    ;
    insert into TEXNIKOS
    values ( 3, 'bar', 0 )  
    ;
    insert into TEXNIKOS ( Onomatepwnymo , Eswterikos )
    values (  'qux', 0 )  
    ;
    insert into TEXNIKOS ( Onomatepwnymo  )
    values (  'fap'  )  
    ;
    select * from TEXNIKOS
    ;
    
    Kwd_Texnikou  Onomatepwnymo Eswterikos
      1             foo             1
      3             bar             0
      4             qux             0
      5             fap             NULL
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Apr 2004
    Posts
    110
    very nice. thank you!

Posting Permissions

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