
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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).
- Related Articles
- How can we allow MySQL to store invalid dates?
- How can we enter BOOLEAN values in MySQL statement?
- How can we update values in a MySQL table?
- How can we update any value in MySQL view as we can update the values in MySQL table?
- BOOLEAN or TINYINT to store values in MySQL?
- How can we display MySQL bit values in printable form?
- How can we specify default values in MySQL INSERT statement?
- Can we store objects in an array in Java?
- Can we fetch multiple values with MySQL WHERE Clause?
- Can we insert values without mentioning the column name in MySQL?
- Can we skip a column name while inserting values in MySQL?
- Can we insert records in a MySQL table without auto_increment values?
- Can MySQL automatically store timestamp in a row?
- How can we update the values in one MySQL table by using the values of another MySQL table?
- How can we calculate the difference between two time values in MySQL?

Advertisements