dzosef
dzosef

Reputation: 11

MySQL INSERT problem

Does anyone know what is problem with this query:

INSERT INTO match 
  (IDTeamHome, IDTeamGuest, Date) 
VALUES 
  ('15','16','20.03.2011 15:00')

IDTeamHome and IDTeamGuest are integer, and Date is varchar.

Upvotes: 0

Views: 127

Answers (4)

user7427557
user7427557

Reputation: 1

ID Of Team is Int so you can't use single quotations because that's quotations. For String value Like Alphabets, use this format:

insert into match(int,varchar(20),data)
Values(12,'teamname','2015-11-4');

Upvotes: 0

mechanical_meat
mechanical_meat

Reputation: 169514

Edit: there are several issues.

  1. "match" and "date" are keywords in MySQL. You need double-quotes or backticks around them so that MySQL knows that they are table or column names, e.g.
    INSERT INTO "match" (id1, id2, "date") VALUES ...

  2. Remove the single-quotes around the integer values you're inserting.
    Single-quotes are for strings. (not strictly necessary as pointed out by OMG Ponies in the comments)

  3. If you can avoid it, do not store timestamps as VARCHAR. This will make querying more difficult and confuse anyone else who's working with your table(s).

Upvotes: 4

Nicola Cossu
Nicola Cossu

Reputation: 56407

match is a reserved word.

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Rename your table or put it within backticks (alt + 96)

I've seen it just now. :)

Upvotes: 0

GG.
GG.

Reputation: 21904

Try with `Date` or rename this field, because Date is a word used by MySQL I think.

And remove the single quotes for the integers.

Upvotes: 0

Related Questions