开发者

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.

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. 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. If this is not the case you can change it back to 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 
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜