shashank shashank - 2 months ago 6
MySQL Question

Entering string says unknown column

I am practising mysql in command line. I have a database named ticket_system which in turn has a table named train

create table ticket_system.Train
(
Train_no int(10) PRIMARY KEY,
Name varchar(10),
source varchar(10),
destination varchar(10),
start_time TIME,
reach_time TIME,
traveltime int(10),
distance int(10),
class int(10),
days int(10),
type varchar(10)
);


This was what I used to make a table and its columns which worked fine. But now when I am inserting data in the table columns.

INSERT INTO ticket_system.Train (Train_no, Name, source, destination, start_time, reach_time, traveltime, distance, class, days, type) values(1, ‘raja’, ‘delhi’ , ‘patna’ , ’120000’ , ’130000’ , 1 , 100 , 1 , 1, ‘2nd’ );


I am getting error

ERROR 1054 (42S22): Unknown column 'raja' in 'field list'

I dont understand why is this error . The field Name datatype is set to varchar(10) and "raja" should fit into that . Can someone point me where I am doing wrong?

Answer

You need to wrap your columns that are of string (text, varchar, char) data type with single quotes '.

INSERT INTO ticket_system.Train 
  (Train_no, Name, source, destination, start_time, reach_time, traveltime, distance, class, days, type) 
values
  (1, 'raja', 'delhi' , 'patna' , '120000' , '130000' , 1 , 100 , 1 , 1, '2nd' );
Comments