Possiamo selezionare il nome del campo in MySQL che contiene un asterisco?
No, non possiamo. Per risolverlo ancora, usa gli apici inversi attorno al nome del campo. Creiamo innanzitutto una tabella con il nome della colonna con l'asterisco, `Name*` :
mysql> create table DemoTable
-> (
-> `Name*` varchar(20)
-> );
Query OK, 0 rows affected (2.03 sec)
Inserisci alcuni record nella tabella utilizzando il comando di inserimento:
mysql> insert into DemoTable(`Name*`) values('Chris Brown');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable(`Name*`) values('David Miller');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable(`Name*`) values('John Doe');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable(`Name*`) values('John Smith');
Query OK, 1 row affected (0.23 sec)
Visualizza tutti i record dalla tabella utilizzando l'istruzione select :
mysql> select *from DemoTable;
Ciò produrrà il seguente output:
+--------------+
| Name* |
+--------------+
| Chris Brown |
| David Miller |
| John Doe |
| John Smith |
+--------------+
4 rows in set (0.00 sec)
Di seguito è riportata la query per selezionare il nome del campo che contiene un asterisco:
mysql> select `Name*` from DemoTable;
Ciò produrrà il seguente output:
+--------------+
| Name* |
+--------------+
| Chris Brown |
| David Miller |
| John Doe |
| John Smith |
+--------------+
4 rows in set (0.00 sec)