0
  • i am new to sql and was following a tutorial from netwrokchunk on youtube.
  • if creating a table with first field order, error pops up
  • if creating same table with first field orders, doesn't show any error.
mysql> show tables
    -> ;
+---------------------+
| Tables_in_nc_coffee |
+---------------------+
| coffee_table        |
| orders_table        |
+---------------------+
2 rows in set (0.00 sec)

mysql> drop table orders_table;
Query OK, 0 rows affected (0.03 sec)

mysql> show tables
    -> ;
+---------------------+
| Tables_in_nc_coffee |
+---------------------+
| coffee_table        |
+---------------------+
1 row in set (0.00 sec)

mysql> create table orders_table (
    -> order int,
    -> coffee int,
    -> customer 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 'order int,
coffee int,
customer int
)' at line 2
mysql> create table orders_table ( order int, coffee int, customer 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 'order int, coffee int, customer int )' at line 1
mysql> create table orders_table ( orders int, coffee int, customer int );
Query OK, 0 rows affected (0.03 sec)

mysql> 

what is going on here ?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794

1 Answers1

2

ORDER is a reserved word (part of the SQL ORDER BY clause).

It's usually a bad idea to use reserved words for column or table names, but if you really want to MySQL will let you do this by enclosing it in backticks:

create table orders_table ( `order` int, coffee int, customer int );
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • thank you. where can i learn sql, do you know any resources online that are affordable if not free. from ground zero – Sahil Gautam Jan 26 '23 at 18:39