Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Can we store CSS color values in MySQL?
Yes, we can. In order to store CSS color value, you can use CHAR(6) without # symbol for hexadecimal. Let us see an example and create a table
mysql> create table storeCSSColorDemo -> ( -> CSSValue char(6) -> ); Query OK, 0 rows affected (0.53 sec)
Insert some records in the table using insert command. The records here are individual color values in hexadecimal, for which we have used char(6)
mysql> insert into storeCSSColorDemo values('FF0000');
Query OK, 1 row affected (0.13 sec)
mysql> insert into storeCSSColorDemo values('FFA500');
Query OK, 1 row affected (0.86 sec)
mysql> insert into storeCSSColorDemo values('FFFF00');
Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from storeCSSColorDemo;
The following output displays the color value successfully stored in MySQL table
+----------+ | CSSValue | +----------+ | FF0000 | | FFA500 | | FFFF00 | +----------+ 3 rows in set (0.00 sec)
In the above sample output, the three colors are RED, ORANGE and YELLOW.
NOTE If your column is nullable then you can use VARCHAR(6).
Advertisements
