auto-increments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Olafur

    #1

    auto-increments

    Hello all,

    I am a beginner with mysql, however installation was fine no problems and I
    have been trying the Consol Center trying to create new tables. I get two
    errors I can't get rid of.

    1. I create a table with primary key etc and several columns. When
    entering data I always get in the primary key column three letters PRI and
    an error message
    [root@localhost: 3306] ERROR 1054: Unknown column 'PRI' in 'field list'


    2. I have made the primary key column auto-incremental. If I overwrite this
    PRI and put e.g. 1 in the first row the next should automatically provide 2
    etc. However this does not happen, I get again PRI in that column.

    Could anyone please be so kind to give me a hint what I am doing wrong.

    Best regards,

    Olaf


  • Aggro

    #2
    Re: auto-increments

    Olafur wrote:
    [color=blue]
    > 2. I have made the primary key column auto-incremental. If I overwrite this
    > PRI and put e.g. 1 in the first row the next should automatically provide 2
    > etc. However this does not happen, I get again PRI in that column.
    >
    > Could anyone please be so kind to give me a hint what I am doing wrong.[/color]

    That would be a lot easier if I would know what you are doing.

    Can you provide example (copy-paste) like the one I'm giving now, so
    that I could see what you are trying to do.


    mysql> create table mytest(
    -> id int unsigned auto_increment primary key default 5,
    -> name varchar(255)
    -> );
    Query OK, 0 rows affected (0.00 sec)

    mysql> insert into mytest(name) values('Jack');
    Query OK, 1 row affected (0.00 sec)

    mysql> insert into mytest(name) values('Lisa');
    Query OK, 1 row affected (0.00 sec)

    mysql> select * from mytest;
    +----+------+
    | id | name |
    +----+------+
    | 1 | Jack |
    | 2 | Lisa |
    +----+------+
    2 rows in set (0.00 sec)

    Comment

    • Olafur

      #3
      Re: auto-increments

      Thanks Aggro,
      I was not using the command line, but the MySQL Command Center 0.9.4 beta.
      However, using the command line as you suggest and and giving the
      instruction to create the table as you indicate I get the following error:

      ERROR 1067: Invalid default value for 'id'

      Regards,

      Olafur


      "Aggro" <spammerdream@y ahoo.com> wrote in message
      news:fJ%Ac.204$ Qr.55@read3.ine t.fi...[color=blue]
      > Olafur wrote:
      >[color=green]
      > > 2. I have made the primary key column auto-incremental. If I overwrite[/color][/color]
      this[color=blue][color=green]
      > > PRI and put e.g. 1 in the first row the next should automatically[/color][/color]
      provide 2[color=blue][color=green]
      > > etc. However this does not happen, I get again PRI in that column.
      > >
      > > Could anyone please be so kind to give me a hint what I am doing wrong.[/color]
      >
      > That would be a lot easier if I would know what you are doing.
      >
      > Can you provide example (copy-paste) like the one I'm giving now, so
      > that I could see what you are trying to do.
      >
      >
      > mysql> create table mytest(
      > -> id int unsigned auto_increment primary key default 5,
      > -> name varchar(255)
      > -> );
      > Query OK, 0 rows affected (0.00 sec)
      >
      > mysql> insert into mytest(name) values('Jack');
      > Query OK, 1 row affected (0.00 sec)
      >
      > mysql> insert into mytest(name) values('Lisa');
      > Query OK, 1 row affected (0.00 sec)
      >
      > mysql> select * from mytest;
      > +----+------+
      > | id | name |
      > +----+------+
      > | 1 | Jack |
      > | 2 | Lisa |
      > +----+------+
      > 2 rows in set (0.00 sec)[/color]


      Comment

      • Aggro

        #4
        Re: auto-increments

        Olafur wrote:
        [color=blue]
        > Thanks Aggro,
        > I was not using the command line, but the MySQL Command Center 0.9.4 beta.
        > However, using the command line as you suggest and and giving the
        > instruction to create the table as you indicate I get the following error:
        >
        > ERROR 1067: Invalid default value for 'id'[/color]

        My mistake (I propably got older version, which didn't complain about
        the error I made). That should be:

        create table mytest(
        id int unsigned auto_increment primary key,
        name varchar(255) );

        I was just trying does it work if I add default 5 at the end, but that
        didn't make it to start counting from 5. I remember that there was some
        way to start counting from another number than 1, but don't remember how
        it was.

        But if you are happy with the counting starting from 1, that should be
        enough for you.

        Comment

        • Olafur

          #5
          Re: auto-increments

          Thanks Aggro,
          This goes fine I get the results from the two rows fine just as you
          indcated.
          My problem must have something to do with the MySQL Command Center and not
          with the database as such.

          Regards,

          Olafur


          "Aggro" <spammerdream@y ahoo.com> wrote in message
          news:O5bCc.74$f l5.0@read3.inet .fi...[color=blue]
          > Olafur wrote:
          >[color=green]
          > > Thanks Aggro,
          > > I was not using the command line, but the MySQL Command Center 0.9.4[/color][/color]
          beta.[color=blue][color=green]
          > > However, using the command line as you suggest and and giving the
          > > instruction to create the table as you indicate I get the following[/color][/color]
          error:[color=blue][color=green]
          > >
          > > ERROR 1067: Invalid default value for 'id'[/color]
          >
          > My mistake (I propably got older version, which didn't complain about
          > the error I made). That should be:
          >
          > create table mytest(
          > id int unsigned auto_increment primary key,
          > name varchar(255) );
          >
          > I was just trying does it work if I add default 5 at the end, but that
          > didn't make it to start counting from 5. I remember that there was some
          > way to start counting from another number than 1, but don't remember how
          > it was.
          >
          > But if you are happy with the counting starting from 1, that should be
          > enough for you.[/color]


          Comment

          Working...