Tutorialspoint

Do MySQL Can Enum type values contain spaces in it?


1 Answer
Smita Kapse

Yes, you can include a string value with spaces in ENUM type. Let us first create a table −

mysql> create table DemoTable
   (
   Size ENUM('SMALL SIZE','LARGE SIZE','XL SIZE')
   );
Query OK, 0 rows affected (0.65 sec)

Let us check the description of table using DESC command −

mysql> desc DemoTable;

This will produce the following output −

+-------+-------------------------------------------+------+-----+---------+-------+
| Field | Type                                      | Null | Key | Default | Extra |
+-------+-------------------------------------------+------+-----+---------+-------+
| Size  | enum('SMALL SIZE','LARGE SIZE','XL SIZE') | YES  |     | NULL    |       |
+-------+-------------------------------------------+------+-----+---------+-------+
1 row in set (0.01 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('XL SIZE');
Query OK, 1 row affected (0.14 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output. Here, we have displayed an ENUM type value with a space −

+---------+
| Size    |
+---------+
| XL SIZE |
+---------+
1 row in set (0.00 sec)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.