In my application whenever a user upload a wallpaper,i need to crop that wallpaper into 3 different sizes and store all those paths(3 paths for cropped images and 1 for original upload wallpaper) into my database.
I also need to store the tinyurl of the original wallpaper(one which is uploaded by user).

在我的应用程序中,每当用户上传壁纸时,我需要将该壁纸裁剪成3种不同的尺寸,并将所有这些路径(裁剪图像的3条路径和原始上传壁纸的1条路径)存储到我的数据库中。我还需要存储原始壁纸(由用户上传的一个)的tinyurl。

While solving the above described problem i come up with following table structure.

在解决上述问题的同时,我提出了以下表格结构。

CREATE TABLE `wallpapermaster` (
  `wallpaperid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `userid` bigint(20) NOT NULL,
  `wallpaperloc` varchar(100) NOT NULL,
  `wallpapertitle` varchar(50) NOT NULL,
  `wallpaperstatus` tinyint(4) DEFAULT '0' COMMENT '0-Waiting,1-approved,2-disapproved',
  `tinyurl` varchar(40) NOT NULL
) ENGINE=MyISAM

wallpaperloc is a comma separated field consisting of original wallpaper location plus locations of all cropped instances.

wallpaperloc是一个逗号分隔的字段,由原始壁纸位置和所有裁剪实例的位置组成。

I know using comma separated field considered to be a bad design in the world of relational database,So Would you like to suggest some other neat and efficient ways?

我知道在关系数据库的世界中使用逗号分隔的字段被认为是一个糟糕的设计,所以你想建议一些其他整洁有效的方法吗?

5 个解决方案

#1


4

Use a 1:n relationship between the wallpapermaster and a location table.

在wallpapermaster和位置表之间使用1:n关系。

Something like this:

像这样的东西:

CREATE TABLE wallpapermaster (
  wallpaperid     int unsigned NOT NULL AUTO_INCREMENT,
  userid          bigint NOT NULL,
  wallpaperloc    varchar(100) NOT NULL,
  wallpapertitle  varchar(50) NOT NULL,
  wallpaperstatus tinyint DEFAULT '0' COMMENT '0-Waiting,1-approved,2-disapproved',
  primary key (wallpaperid)
) ENGINE=InnoDB;


CREATE TABLE wallpaperlocation (
  wallpaperid  int unsigned NOT NULL,
  location     varchar(100) NOT NULL,
  tinyurl      varchar(40),
  constraint fk_loc_wp 
      foreign key (wallpaperid) 
      references wallpapermaster (wallpaperid),
   primary key (wallpaperid, location)
) ENGINE=InnoDB;

The primary key in wallpaperlocation ensures that the same location cannot be inserted twice.

wallpaperlocation中的主键确保无法插入相同的位置两次。

Note that int(10) does not define any datatype constraints. It is merely a hint for client application to indicate how many digits the number has.

请注意,int(10)不定义任何数据类型约束。它仅仅是客户端应用程序的提示,指示该数字具有多少位数。

更多相关文章

  1. centos7 移动mysql5.7.19 数据存储位置
  2. js金额数字格式化实现代码(三位加逗号处理保留两位置小数)
  3. js“DOM事件”之鼠标事件、js的测试方法、js代码的放置位置
  4. 使用谷歌地图computeDistanceBetween获取最近的位置返回NaN
  5. Google Maps API v3:如何设置缩放级别和地图中心到用户提交的位置
  6. 拒绝获取不安全标题“位置”
  7. 将div停靠在窗口左侧并再次单击原始位置
  8. 如何在涉及css缩放时获取页面上的点击位置
  9. swiper 定位到指定页面或位置

随机推荐

  1. ANDROID:控件属性(很全)
  2. [置顶] NoHttp详解之Android使用Https
  3. Android异步处理三:Handler+Looper+Messag
  4. 《android 1: 创建一个安卓项目》
  5. Android(安卓)创建及调用自己的 ContentP
  6. Android播放视频的三种方式示例
  7. android中怎么让 button组件居中显示
  8. Android app设置全屏模式
  9. Android 网络开发详解
  10. android中的color使用总结