- 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
Can we use reserved word ‘index’ as MySQL column name?
Yes, but you need to add a backtick symbol to the reserved word (index) to avoid error while using it as a column name.
Let us first create a table −
mysql> create table DemoTable ( `index` int ); Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(1000); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(1020); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(967); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(567); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(1010); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | index | +-------+ | 1000 | | 1020 | | 967 | | 567 | | 1010 | +-------+ 5 rows in set (0.00 sec)
Now let us display some records with our column name `index`. Here, we are displaying 3 records −
mysql> select *from DemoTable order by `index` DESC LIMIT 3;
This will produce the following output −
+-------+ | index | +-------+ | 1020 | | 1010 | | 1000 | +-------+ 3 rows in set (0.00 sec)
Advertisements