- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why can't we use column name “desc” in MySQL?
The desc is a MySQL reserved word, therefore you cannot use it. But, if you still want to set the column name as ‘desc’, you need to use backticks. The backtick notation is (` `).
To understand the above concept, let us create a table.
The query to create a table is as follows −
mysql> create table useOfDescColumnNameDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> `desc` varchar(200) default 'GOOD' -> ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command.
The query is as follows −
mysql> insert into useOfDescColumnNameDemo(Name) values('John'); Query OK, 1 row affected (0.17 sec) mysql> insert into useOfDescColumnNameDemo(Name) values('Bob'); Query OK, 1 row affected (0.16 sec) mysql> insert into useOfDescColumnNameDemo(Name) values('Carol'); Query OK, 1 row affected (0.13 sec) mysql> insert into useOfDescColumnNameDemo(Name) values('Sam'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using a select statement.
The query is as follows −
mysql> select *from useOfDescColumnNameDemo;
Here is the output −
+----+-------+------+ | Id | Name | desc | +----+-------+------+ | 1 | John | GOOD | | 2 | Bob | GOOD | | 3 | Carol | GOOD | | 4 | Sam | GOOD | +----+-------+------+ 4 rows in set (0.00 sec)
Here is the query to use backticks with a select statement −
mysql> select `desc` from useOfDescColumnNameDemo;
The following is The output −
+------+ | desc | +------+ | GOOD | | GOOD | | GOOD | | GOOD | +------+ 4 rows in set (0.00 sec)
Advertisements