繁体   English   中英

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

[英]How would I best design this database?

我正在实现自己的许可证数据库,并且正在考虑自己创建一个想法。 但是由于我并不是很擅长设计数据库,因此我希望在设计方面获得一些帮助(想法)。

我的想法。 我需要一对多关系数据库。 这个想法是跟随:

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;

序列表中将填充几个(起初为几百个)序列...我的想法是,当客户购买一个(或多个)许可证时,它们将使用名称和电子邮件注册在客户表中。 将为他们指定一个序列号,因此clients表中的序列行将指向其指定序列号的id行。

当客户使用程序时,将使用在线表格。 当他们上线时,将在在线表中填写序列号和客户名称。 当他们离线时,它们将从在线表中删除。

在线表也在那里,以防止客户在多个同时实例中使用同一序列。 如果他们想同时运行多个客户端,则必须购买另一系列。

现在到问题...。我在想完全错误吗? 还是这是一个好的设计? 您会做其他不同的事情吗? 关于如何设计该数据库,您必须说的任何事情都是有价值的。

谢谢!

这是我的建议:

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;

请确保使所有字段不能包含NULL值,而不是null。 这样可以提高查询速度。 另外,我将序列的类型从varchar更改为char,因为我认为它是固定大小的字符串。 如果不是这种情况,则可以将其更改回varchar。

好的,现在让我为您的数据库建议一个设计:

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