简体   繁体   中英

what is the best way color store in sql

i am not sure which is the best for color store in sql

i can be perform 3 way Color Name ,Hex color code , RGB Color Code. what is the datatype for the color .

please suggest me i am working a eCommerce side with Asp.net MVC and sql 2012. i need to store product color . 在此处输入图片说明

You will probably need a color table with, say, 20 colors, the clients can use to filter the products.

Here is one rather simple database design where a product has various colors:

table color - these are the generic colors used for filtering

  • color_id
  • color_name - eg 'red', a text you can use to show in the filter options
  • color_code - eg #FF0000, a color you can use to show in the filter options

table product - the product (irrespective of its colors)

  • product_id
  • product_description

table product_color - the product's colors; these are the items that are actually ordered

  • product_id
  • color_id
  • color_name, product-specific eg 'dark red'
  • price

(That may get more complicated when the product has various sizes, too.)

For storing color in database use input type color if you want to store colorcode in html.

And in sql save the color with a char(6) without the # if the column is not null... if the column is nullable use a varchar(6) to saving size

如果仅使用0xRRGGBB格式,而不是在数据库中以整数形式存储,并且在要选择时以十六进制形式存储,或者如何将值存储在数据库中取决于它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM