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.
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.
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.
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).
These are reserved keywords. Microsoft SQL Server uses these for defining, manipulating and accessing databases and all objects in it.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With