-2

I was coding using mySQL 5.x and now i switched to 8.x version and i am confused. What is wrong with this short code ?

[screenshot of my code ]

1

Error message

"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 VARCHAR(50) NOT NULL, discipline VARCHAR(1), yr_start INT(11), ' at line 3"

eshirvana
  • 23,227
  • 3
  • 22
  • 38
KrepaFR
  • 31
  • 3

2 Answers2

3

rank is now a MySQL reserved word. It is used for the rank() window function

Use a variant, such as ranking instead.

These functions were introduced in MySQL 8.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
1

In case changing your schema is not practical for some reason, you can also use quoted identifier. By default in MySQL use the backquote character, for example:

create table foo (
   `rank` varchar(50)
) 

should work if you want to port your pre-existing schema from older mysql version without modifying your application logic.

user700390
  • 2,287
  • 1
  • 19
  • 26
  • Oh thanks it's working too ! It's just quite unusual for me to type the ` character with my keyboard. – KrepaFR Jul 01 '21 at 11:19