Should I name the username field in my MySQL table “name” or “user_name”?


Do not prefix table name with field name like user_name. Instead, use user or username.

If you prefix table name, then there may be a chance of ambiguity, so avoid prefixing table name.

Let us first create a table −

mysql> create table user
   -> (
   -> username varchar(20),
   -> password varchar(20)
   -> );
Query OK, 0 rows affected (0.66 sec)

Insert some records in the table using insert command −

mysql> insert into user values('John','J_635');
Query OK, 1 row affected (0.34 sec)
mysql> insert into user values('Carol','Carol2212');
Query OK, 1 row affected (0.16 sec)
mysql> insert into user values('David','@12345678');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select * from user;

This will produce the following output −

+----------+-----------+
| username | password  |
+----------+-----------+
| John     |     J_635 |
| Carol    | Carol2212 |
| David    | @12345678 |
+----------+-----------+
3 rows in set (0.00 sec)

Updated on: 12-Dec-2019

206 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements