0

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.

1
  • 4
    Why would you store date & time in a VARCHAR column!? There's no obvious error with what you posted, you'll have to provide the error you experience to get an answer. Commented Mar 20, 2011 at 21:21

4 Answers 4

4

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).

Sign up to request clarification or add additional context in comments.

7 Comments

MySQL (and most other databases for that matter) performs implicit conversion in situations like these, based on the column data type. But it is good habit not to rely on it, for sake of attempting to provide data that can not be implicitly converted.
Why single quotes don't work in his case? Is related to some sql mode?
Actually, I missed that the date column is VARCHAR
so, what is the answer? If the date column is VARCHAR? Thanks
@dzosef: if the column is varchar your code should be working as written. Please post the exact error you're getting.
|
0

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.

3 Comments

Now it is this code INSERT INTO match (IDTeamHome,IDTeamGuest,Datum) VALUES (11,12,'20.03.2011 15:00')
@dzosef: don't store dates in a varchar column.
I want to store in varchar column, because it's not gonna be date every time. So I don't catch what's the problem with my code if it is regular varchar INSERT INTO match (IDTeamHome,IDTeamGuest,SomeField) VALUES (7,8,'blah blah').
0

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. :)

Comments

0

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.