- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 “rank” as column name with MySQL8?
152 Lectures 16 hours
87 Lectures 5.5 hours
The rank is a MySQL reserved word defined in MySQL version 8.0.2. Therefore, you cannot use rank as a column name. You need to use backticks around the rank.
Let us first check the MySQL version we are working on. Here, I am using MySQL version 8.0.12 −
mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.12 | +-----------+ 1 row in set (0.00 sec)
The issues by using “rank” as column name are as follows −
mysql> create table DemoTable1596 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> rank int -> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'rank int )' at line 5
Above, an error is visible since we used reserved word as column name.
Let us first create a table and use backticks around “rank” to avoid error −
mysql> create table DemoTable1596 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> `rank` int -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1596(StudentName,`rank`) values('Bob',4567); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1596(StudentName,`rank`) values('David',1); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1596;
This will produce the following output −
+----+-------------+------+ | Id | StudentName | rank | +----+-------------+------+ | 1 | Bob | 4567 | | 2 | David | 1 | +----+-------------+------+ 2 rows in set (0.00 sec)
- Can we use MySQL keyword as alias name for a column?
- Can we use reserved word ‘index’ as MySQL column name?
- Can we use “When” as column name in CREATE TABLE statement?
- Can we use backticks with column value in MySQL?
- Why can't we use column name “desc” in MySQL?
- Can we define a method name same as class name in Java?
- Can we use semicolon as a MySQL DEMILITER?
- Can we use “year” as a column came in a MySQL Table?
- How can we use MySQL EXPORT_SET() function with column of a table?
- Can we use current_date() for table with column timestamp default in MySQL?
- Can we skip a column name while inserting values in MySQL?
- Can we insert values without mentioning the column name in MySQL?
- Can we use the “.” symbol in MongoDB collection name?
- Can we create a database with a numeric name with MySQL?