469,167 Members | 1,207 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

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
Jul 20 '05 #1
4 1629
Olafur wrote:
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.


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)
Jul 20 '05 #2
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" <sp**********@yahoo.com> wrote in message
news:fJ*************@read3.inet.fi...
Olafur wrote:
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.


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)

Jul 20 '05 #3
Olafur wrote:
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'


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.
Jul 20 '05 #4
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" <sp**********@yahoo.com> wrote in message
news:O5************@read3.inet.fi...
Olafur wrote:
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'


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.

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Manlio Perillo | last post: by
5 posts views Thread by Robert Downes | last post: by
20 posts views Thread by Vijay Kumar R. Zanvar | last post: by
5 posts views Thread by maya | last post: by
22 posts views Thread by nospam_news | last post: by
2 posts views Thread by Piotr K | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.