简体   繁体   English

用于存储int的数据库架构

[英]Database schema for storing ints

I'm really new to databases so please bear with me. 我真的是数据库新手,请耐心等待。

I have a website where people can go to request tickets to an upcoming concert. 我有一个网站,人们可以在那里索取即将举行的音乐会的门票。 Users can request tickets for either New York or Dallas. 用户可以要求购买纽约或达拉斯的门票。 Similarly, for each of those locales, they can request either a VIP ticket or a regular ticket. 同样,对于这些语言环境中的每个语言环境,他们都可以请求VIP票证或普通票。

I need a database to keep track of how many people have requested each type of ticket ( VIP and NY or VIP and Dallas or Regular and NY or Regular and Dallas ). 我需要一个数据库来跟踪有多少人要求每种票证( VIP and NYVIP and DallasRegular and NYRegular and Dallas )。 This way, I won't run out of tickets. 这样,我不会用完票。

What schema should I use for this database? 我应该为该数据库使用哪种模式? Should I have one row and then 4 columns (VIP&NY, VIP&Dallas, Regular&NY and Regular&Dallas)? 我应该一行然后四列(VIP&NY,VIP&Dallas,Regular&NY和Regular&Dallas)吗? The problem with this is it doesn't seem very flexible, thus I'm not sure if it's good design. 问题在于它似乎不太灵活,因此我不确定它是否是好的设计。

您应该有一列包含数量,一列指定类型(VIP),另一列指定城市。

To make it flexible you would do: 为了使其更加灵活,您可以执行以下操作:

Table: 
    location
Columns:
    location_id  integer
    description  varchar

Table
    type
Columns:
    type_id      integer
    description  varchar

table 
    purchases
columns:
    purchase_id integer
    type_id     integer
    location_id integer

This way you can add more cities, more types and you allways insert them in purchases. 这样,您可以添加更多城市,更多类型,并且始终将它们插入购买中。

When you want to know how many you sold you count them 当您想知道您卖出了多少时,就算上它们

What you want to do is have one table with cities and one table with ticket types. 您想要做的就是一张包含城市的表,一张包含票证类型的表。 Then you create a weak association with [city, ticket type, number of tickets]. 然后,您将与[城市,票证类型,票证数量]建立一个弱关联。

That table will have 2 foreign keys, therefore "weak". 该表将具有2个外键,因此为“弱”。

But this enables you to add or remove cities etc. And you can add a table for concerts as well and your weak table you will have another foreign key "concert". 但是,这使您可以添加或删除城市等。还可以为音乐会添加表,而弱表中将有另一个外键“音乐会”。

I think this is the most correct way to do it. 我认为这是最正确的方法。

CREATE TABLE `tickets` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `locale` varchar(45) NOT NULL,
   `ticket_type` varchar(45) NOT NULL
}

This is a simple representation of your table. 这是表的简单表示。 Ideally you would have separate tables for locale and type. 理想情况下,您将具有用于语言环境和类型的单独表。 And your table would look like this: 您的表如下所示:

CREATE TABLE `tickets` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `locale_id` int(11) NOT NULL,
   `ticket_type_id` int(11) NOT NULL
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于存储指标的数据库架构/设计 - Database schema/design for storing metrics 用于存储问卷和多项选择答案的数据库模式 - database schema for storing questionnaires and multiple choice answers 哪个数据库表模式用于存储调查数据? - Which database table schema for storing survey data? 创建可伸缩的数据库架构以存储高尔夫分数 - Create a scalable database schema for storing golf scores 存储嵌套的Json对象的数据库架构是什么? - what is the database schema for storing nested Json Objects? 尝试考虑最佳的数据库模式来存储需要连接的日期范围 - Trying to think of the best database schema for storing dates ranges that will require joins 有关存储超过255个字符的文本列的数据库模式的建议 - Recommendation on database schema for a text column storing more than 255 characters 如何创建用于存储产品搜索过滤器的数据库模式 - how to create a database schema for storing product search filters 使用Perl验证XML,解析XML并将数据存储回MySQL数据库的最佳方法是什么? - What is the best way to validate XML against XML Schema, parsing it and storing data back to MySQL Database using Perl? 数据库架构 - Database Schema
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM