预订网站的数据库表
我们正在建立一个预订系统。共有三个模块
- 客户
- 客房
- 预订
客户可以预订一间或多间房间并预订不同的日期。预订房间时,我想搜索在日期 A 和日期 B 之间可以预订哪些房间。
表格(可能的解决方案) 客户(ID、姓名、......) 房间(id,房间号,房间类型,......) bookings(id, room_id, fromDate, toDate)
目前我有这样的表
CREATE TABLE IF NOT EXISTS `bookings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`checkin` datetime NOT NULL,
`checkout` datetime NOT NULL,
`advance` int(11) NOT NULL,
`amount` int(11) NOT NULL,
`booking_details_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `bookings_rooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`booking_id` int(11) NOT NULL,
`room_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `customers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`age` int(11) NOT NULL,
`address` varchar(255) NOT NULL,
`nationality_id` int(11) NOT NULL,
`mobile` int(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `rooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`number` int(4) NOT NULL,
`category_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
需要帮助设计数据库,这是一个更好的方法。
We are building an Reservation booking system. There are three modules
- Customers
- Rooms
- Bookings
A customer can book one or many rooms and for varying dates. While booking a room(s) i want to search for which rooms are available to be booked between date A and date B.
Tables ( likely solution)
customers(id, name, .....)
rooms(id, roomNo, roomType, ....)
bookings(id, room_id, fromDate, toDate)
Presently i have the tables like this
CREATE TABLE IF NOT EXISTS `bookings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`checkin` datetime NOT NULL,
`checkout` datetime NOT NULL,
`advance` int(11) NOT NULL,
`amount` int(11) NOT NULL,
`booking_details_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `bookings_rooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`booking_id` int(11) NOT NULL,
`room_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `customers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`age` int(11) NOT NULL,
`address` varchar(255) NOT NULL,
`nationality_id` int(11) NOT NULL,
`mobile` int(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `rooms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`number` int(4) NOT NULL,
`category_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
Need help to design the database and which is a better approach.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些模式结构已经允许您找到两个日期之间的空闲房间。
以下查询将检查在开始时间之前预订的房间是否会在开始时间之前空闲,或者对于那些在开始时间之后预订的房间,它会检查他们是否也在结束日期之后办理入住。
These schema structures already allow you to find the free rooms between two dates.
The following query will check if rooms booked before start-time will be free before start-time or, for those ones booked after, it checks if they're checkin is following end-date too.
外键名称存在混淆 - booking_id 逻辑上应该是 bookings_id
每个表都有重复的键 -您可以删除所有 booking_details_id 等,因为它们扮演 id 的角色
customers 不以任何方式引用
您实现房间的方式 - 很好,但一切都取决于您对它们的处理方式。也许你可以用稍微不同的方式设计它,以便你可以轻松地获取空房间列表(你可以从这个结构中获取空闲房间列表,但性能并不壮观)
there is a confusion in the name of foreign keys - booking_id should be logically bookings_id
you have for each table duplicate keys - you can remove all booking_details_id etc as they play the role of id
customers are not referenced in any way
the way you implement rooms - it's fine but all depends on what you do with them. Possibly you could design it in a bit different way so that you can get easily the list of empty rooms (you can get the list of free rooms from this structure, but the performance is not spectacular)