设置我的画廊表格

发布于 2024-10-06 22:51:13 字数 655 浏览 0 评论 0原文

我将为图片库创建一个网络应用程序。

这就是我创建数据库表的方式。 (我已经排除了其余不必要的表。)

Gallery
Gid    -> Primary key.  
Rid    -> Foreign key from register table.  
Name   -> Name of the image.  
Url    -> Location of image.   
Status -> Enabled or disabled.

Album
Aid    -> Primary key.   
Name   -> Name of the album.

Imagelist  
Iid    -> Primary key.
Aid    -> Foreign key from Album table.  
Gid    -> Foreign key from Gallery table.

但由于某种原因,我觉得这些表的结构是错误的。我的要求是用户应该能够从图库表创建不同的相册。

例如,如果有名为 A、B、C、D 的图片,那么用户应该能够创建名为 a1 的相册,其中包含图片 A、B、C;相册a2包含图片A、B、D。

我创建了这三个表,但我感觉表结构有问题。有人能指出我正确的方向吗?

I am going to create a web application for picture gallery.

So this is how I have created my database tables. (I have excluded the rest of unnecessary tables.)

Gallery
Gid    -> Primary key.  
Rid    -> Foreign key from register table.  
Name   -> Name of the image.  
Url    -> Location of image.   
Status -> Enabled or disabled.

Album
Aid    -> Primary key.   
Name   -> Name of the album.

Imagelist  
Iid    -> Primary key.
Aid    -> Foreign key from Album table.  
Gid    -> Foreign key from Gallery table.

But for some reason I feel the structure of these tables are wrong. My requirement is user should be able to create different albums from the gallery table.

For example if there are pictures named A, B, C, D. then user should be able to create album named a1 which contains pictures A,B,C; album a2 which contains pictures A, B, D.

I have created this three tables, but I feel that there is something wrong in the table structure. Can someone point me in a right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手长情犹 2024-10-13 22:51:13

我不会将带有图像的表格称为画廊,因为它可能意味着相册。从我的角度来看,数据库模式是正确的,我唯一要更改的是 ImageList 表,因为那里不需要 Iid,Aid 和 Gid 应该是唯一索引,我还会添加字段来存储相册中的图像顺序,并设置所有表到InnoDB模式。

这是数据库架构的示例:

-- ----------------------------
-- Table structure for `gallery_album`
-- ----------------------------
DROP TABLE IF EXISTS `gallery_album`;
CREATE TABLE `gallery_album` (
  `album_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL COMMENT 'name of the album',
  `description` text COMMENT 'description of the album',
  `visible` enum('0','1') NOT NULL DEFAULT '1' COMMENT 'is album visible',
  `position` int(11) unsigned NOT NULL,
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`album_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for `gallery_image`
-- ----------------------------
DROP TABLE IF EXISTS `gallery_image`;
CREATE TABLE `gallery_image` (
  `image_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(30) DEFAULT NULL COMMENT 'name of the image used as image ALT attribute',
  `description` varchar(100) DEFAULT NULL COMMENT 'description of the image used as image TITLE attribute',
  `visible` enum('0','1') NOT NULL DEFAULT '1',
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`image_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for `gallery_relation`
-- ----------------------------
DROP TABLE IF EXISTS `gallery_relation`;
CREATE TABLE `gallery_relation` (
  `album_id` int(11) unsigned NOT NULL,
  `image_id` int(11) unsigned NOT NULL,
  `position` int(11) unsigned NOT NULL,
  PRIMARY KEY (`album_id`,`image_id`),
  KEY `image_id` (`image_id`),
  CONSTRAINT `gallery_relation_ibfk_1` FOREIGN KEY (`album_id`) REFERENCES `gallery_album` (`album_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `gallery_relation_ibfk_2` FOREIGN KEY (`image_id`) REFERENCES `gallery_image` (`image_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

I would not call table with images a gallery as it can mean album to. From my point of view database schema is correct only thing I would change is ImageList table as Iid is not required there, Aid and Gid suppose to be unique index, I would also add field to store image order in album, and also set all tables to InnoDB mode.

Here is example of database schema:

-- ----------------------------
-- Table structure for `gallery_album`
-- ----------------------------
DROP TABLE IF EXISTS `gallery_album`;
CREATE TABLE `gallery_album` (
  `album_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL COMMENT 'name of the album',
  `description` text COMMENT 'description of the album',
  `visible` enum('0','1') NOT NULL DEFAULT '1' COMMENT 'is album visible',
  `position` int(11) unsigned NOT NULL,
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`album_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for `gallery_image`
-- ----------------------------
DROP TABLE IF EXISTS `gallery_image`;
CREATE TABLE `gallery_image` (
  `image_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(30) DEFAULT NULL COMMENT 'name of the image used as image ALT attribute',
  `description` varchar(100) DEFAULT NULL COMMENT 'description of the image used as image TITLE attribute',
  `visible` enum('0','1') NOT NULL DEFAULT '1',
  `date_created` datetime NOT NULL,
  `date_updated` datetime NOT NULL,
  PRIMARY KEY (`image_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for `gallery_relation`
-- ----------------------------
DROP TABLE IF EXISTS `gallery_relation`;
CREATE TABLE `gallery_relation` (
  `album_id` int(11) unsigned NOT NULL,
  `image_id` int(11) unsigned NOT NULL,
  `position` int(11) unsigned NOT NULL,
  PRIMARY KEY (`album_id`,`image_id`),
  KEY `image_id` (`image_id`),
  CONSTRAINT `gallery_relation_ibfk_1` FOREIGN KEY (`album_id`) REFERENCES `gallery_album` (`album_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `gallery_relation_ibfk_2` FOREIGN KEY (`image_id`) REFERENCES `gallery_image` (`image_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文