Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to represent a color in a SQL Database?

If I am using .Net and SQL Server 2008, what is the best way for me to store a color in the database, should I use ToString or convert it to an integer, or something else?

Edit:

All I want from the colour is to be able to retrieve it and draw something on the screen in the specified colour. I don't need to be able to query against it.

like image 297
Colin Desmond Avatar asked Sep 10 '09 16:09

Colin Desmond


People also ask

How do you give a color in SQL?

Specify custom colors for SSMS connection SSMS provides a solution for us to determine the environment as per the environment color coding. For example, we can set a red color for production, yellow for development, etc. Usually, we launch SSMS, specify the SQL instance, and connect to the respective SQL Server.

How do you store colors in SQL?

If you just need to store the color, then hex notation should be fine. If you need to perform queries against specific color channels, then you'd want smallint fields for each color channel (be it RGB, ARGB, CYMK, etc). So, for simple storage, keep it simple.

How do I change the color of my database?

In the Database Explorer (View | Tool Windows | Database Explorer), right-click any object (for example, a table or a data source) and select Color Settings. Select the color, and specify how this color should be used (see Database color settings dialog and Database color settings dialog).

What does blue text mean in SQL?

These are reserved keywords. Microsoft SQL Server uses these for defining, manipulating and accessing databases and all objects in it.


2 Answers

How are the colors stored natively?

If you're just using 0xRRGGBB format, you may as well store it as an integer in the database, and re-hexify it when you SELECT (for readability).

like image 77
Mark Rushakoff Avatar answered Oct 28 '22 23:10

Mark Rushakoff


How to store information in a database depends on how you intend to use and access it. There's no saying what the best way to store it is without knowing how you'll use it.

like image 31
Steve Kass Avatar answered Oct 29 '22 01:10

Steve Kass