简体   繁体   English

我如何最好地设计该数据库?

[英]How would I best design this database?

I am implementing my own license database, and was thinking of an idea to make it myself. 我正在实现自己的许可证数据库,并且正在考虑自己创建一个想法。 But as I am not really that good at designing databases, I was hoping to get some help (ideas) with the design. 但是由于我并不是很擅长设计数据库,因此我希望在设计方面获得一些帮助(想法)。

The way I am thinking. 我的想法。 I need a one-to-many relation database. 我需要一对多关系数据库。 The idea is the follolwing: 这个想法是跟随:

database.clients
id (int)20, auto_increment, not null;
Customer_Name (Varchar)255;
email (varchar)255;
serial (int)10;
PRIMARY KEY id;
UNIQUE serial;

database.serials
id (int)20, auto_increment, not null;
serial (varchar)40;
taken (int)2;
PRIMARY KEY id;
UNIQUE serial;

database.online
id (int)20, auto_increment, not null;
serial (int)10;
customer_name (varchar)255;
PRIMARY KEY id;
UNIQUE serial;

The serials table will be filled with several (a few hundreds to begin with) serials... My idea is that when a customer is purchasing one (or several) licenses, they will get registred in the clients table with name and email. 序列表中将填充几个(起初为几百个)序列...我的想法是,当客户购买一个(或多个)许可证时,它们将使用名称和电子邮件注册在客户表中。 A serial will be appointed to them, so the serial row in the clients table will be pointing to the id-row of their appointed serial. 将为他们指定一个序列号,因此clients表中的序列行将指向其指定序列号的id行。

The online table will be used when the customer are using the program. 当客户使用程序时,将使用在线表格。 When they go online, the online table will be filled will the id of the serial, and the customer name. 当他们上线时,将在在线表中填写序列号和客户名称。 WHen they go offline, they will be removed from the online table. 当他们离线时,它们将从在线表中删除。

The online table is also there to prevent a customer from using the same serial in several simultaneous instances. 在线表也在那里,以防止客户在多个同时实例中使用同一序列。 If they want to run more than one client simultaneously, they will have to purchase another serial. 如果他们想同时运行多个客户端,则必须购买另一系列。

And now to the question.... Am I thinking completely wrong? 现在到问题...。我在想完全错误吗? Or is this a good design? 还是这是一个好的设计? Would you do anything different? 您会做其他不同的事情吗? Anything you have to say in regards to how to design this database is valuable. 关于如何设计该数据库,您必须说的任何事情都是有价值的。

Thank you! 谢谢!

This is what I suggest: 这是我的建议:

database.clients
cl_id (int)20, auto_increment, not null;
cl_name (varchar)255, not null;
cl_email (varchar)255, not null;
PRIMARY KEY cl_id;
UNIQUE cl_email;

database.serials
ser_id (int)20, auto_increment, not null;
ser_serial (char)40, not null;
ser_taken (bit), not null;
PRIMARY KEY ser_id;
UNIQUE ser_serial;

database.client_serial
cs_id (int)20, auto_increment, not null;
cs_client (int)20, not null;
cs_serial (int)20, not null;
PRIMARY KEY cs_id;
UNIQUE cs_serial;

database.online_clients
oc_cs_id (int)20, not null;
PRIMARY KEY oc_cs_id;

Please make sure to make all fields that can't contain NULL values, not null. 请确保使所有字段不能包含NULL值,而不是null。 This increases the speed of queries. 这样可以提高查询速度。 Also I changed the type of the serial from varchar to char, since I suppose it is a fixed-size string. 另外,我将序列的类型从varchar更改为char,因为我认为它是固定大小的字符串。 If this is not the case you can change it back to varchar. 如果不是这种情况,则可以将其更改回varchar。

Ok, now let me suggest a design for your db: 好的,现在让我为您的数据库建议一个设计:

client 
(
clientid -  int not null unique,
name - varchar(any length you want)
email - varchar (any length you want)
)

serial
(
serialid - int not null unique
serialnumber - varchar any length you want - unique
)

You will only insert records in this table when a client purchases a license
client_serial_purchased
(
clientid - foreign key of the clients table
serialid - foreign key of the serials table
(clientid,serialid) - primary key of this table 
)

online
(
clientid 
serialid 
)

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

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