Can we use the word user for a MySQL table?

MySQLMySQLi Database

You cannot use “user” for a MySQL table because it is a reserved word in MySQL. You can change the name from user to users or something else or you can use backticks around the user word.

The word user can be used to create a user or can select a user list from the MySQL database.

Let us first create a table. Here, we have used the table name users −

mysql> create table users
   -> (
   -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> UserName varchar(20),
   -> UserAge int
   -> );
Query OK, 0 rows affected (0.51 sec)

Insert some records in the table using insert command −

mysql> insert into users(UserName,UserAge) values('Chris Brown',28);
Query OK, 1 row affected (0.17 sec)
mysql> insert into users(UserName,UserAge) values('John Doe',31);
Query OK, 1 row affected (0.18 sec)
mysql> insert into users(UserName,UserAge) values('John Smith',26);
Query OK, 1 row affected (0.17 sec)
mysql> insert into users(UserName,UserAge) values('David Miller',27);
Query OK, 1 row affected (0.13 sec)

Display all records from the table using select statement −

mysql> select *from users;

This will produce the following output −

+--------+--------------+---------+
| UserId | UserName     | UserAge |
+--------+--------------+---------+
|      1 | Chris Brown  |      28 |
|      2 | John Doe     |      31 |
|      3 | John Smith   |      26 |
|      4 | David Miller |      27 |
+--------+--------------+---------+
4 rows in set (0.00 sec)
raja
Published on 12-Dec-2019 11:47:03
Advertisements