469,890 Members | 2,321 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

auto_increment in mysql

i have created the following table:

create table test (field1 varchar(100), id integer unsigned not null
auto_increment, unique (field1), primary key (id));

When i try to insert some values by using the following statement

insert into test values ("this is a test");

I was told "column count does not match value count at row 1".

I could not figure out what's wrong with the syntax. Could someone help me
out. Thanks.
Jul 19 '05 #1
4 4489
BDR
You can't use that type of syntax when inserting into one field only.

Using a blatant insert into, your input value count MUST match the
number of columns in the table, like this:

insert into test values "this is a test", '0'

This type of insert is not recommended because if your database ever
changes, then all of your programmed query statements will have to
change too.

Better:
insert into test (field1), ("this is a test")

or
insert into test (field1), ("this is test1", "this is test2", "this is
test3")

or

insert into test set field1="this is a test"

jjliu wrote:
i have created the following table:

create table test (field1 varchar(100), id integer unsigned not null
auto_increment, unique (field1), primary key (id));

When i try to insert some values by using the following statement

insert into test values ("this is a test");

I was told "column count does not match value count at row 1".

I could not figure out what's wrong with the syntax. Could someone help me
out. Thanks.


Jul 19 '05 #2
BDR
You can't use that type of syntax when inserting into one field only.

Using a blatant insert into, your input value count MUST match the
number of columns in the table, like this:

insert into test values "this is a test", '0'

This type of insert is not recommended because if your database ever
changes, then all of your programmed query statements will have to
change too.

Better:
insert into test (field1), ("this is a test")

or
insert into test (field1), ("this is test1", "this is test2", "this is
test3")

or

insert into test set field1="this is a test"

jjliu wrote:
i have created the following table:

create table test (field1 varchar(100), id integer unsigned not null
auto_increment, unique (field1), primary key (id));

When i try to insert some values by using the following statement

insert into test values ("this is a test");

I was told "column count does not match value count at row 1".

I could not figure out what's wrong with the syntax. Could someone help me
out. Thanks.


Jul 19 '05 #3
KS
On Mon, 13 Oct 2003 19:54:53 +0000, jjliu wrote:
insert into test values ("this is a test");


If I remember correct you must list the fields in insert clause. So the
correct sql would be
insert into test(field1) values ("this is a test");

-Kari

Jul 19 '05 #4
KS
On Mon, 13 Oct 2003 19:54:53 +0000, jjliu wrote:
insert into test values ("this is a test");


If I remember correct you must list the fields in insert clause. So the
correct sql would be
insert into test(field1) values ("this is a test");

-Kari

Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Paul Lamonby | last post: by
4 posts views Thread by Pjotr Wedersteers | last post: by
reply views Thread by Miguel Perez | last post: by
reply views Thread by Write a Friend | last post: by
2 posts views Thread by Nico v. Rossum | last post: by
9 posts views Thread by Bart Van der Donck | last post: by
reply views Thread by Shailesh | last post: by
1 post views Thread by Phil Latio | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.