Why the #1054 - Unknown column error occurs in MySQL and how to fix it?


Let’s see when the #1054 error occurs in MySQL. While inserting a varchar value, if you will forget to add single quotes, then this error will arise.

Following is the error −

mysql> insert into DemoTable798 values(100,Adam);
ERROR 1054 (42S22): Unknown column 'Adam' in 'field list'

You need to use single quotes around the string value to fix this error as shown below −

mysql> insert into DemoTable798 values(100,’Adam’);

Let us first create a table −

mysql> create table DemoTable798 (
   StudentId int,
   StudentName varchar(100)
);
Query OK, 0 rows affected (0.51 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable798 values(100,'Adam');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable798 values(101,'Chris');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable798 values(102,'Robert');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable798 values(103,'Carol');
Query OK, 1 row affected (0.16 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable798;

This will produce the following output -

+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
| 100       | Adam        |
| 101       | Chris       |
| 102       | Robert      |
| 103       | Carol       |
+-----------+-------------+
4 rows in set (0.00 sec)
raja
Published on 09-Sep-2019 12:31:35
Advertisements