I'm working on designing my very first actual database from the following UML class diagram (in French unfortunately):
I'm at the point of creating the relational sketch of it which I created this way:
Yet, it creates some issues when trying to ask to the database which are the clients that never ordered product number one?
Indeed, I don't know how to do it in SQL as far as it seems that there is no relations between Client, Commande and Produit. It gived the following sql code:
CREATE TABLE Client ( IDClient INT NOT NULL, AdresseClient VARCHAR(255)NOT NULL , NomContact VARCHAR(255)NOT NULL, NumeroSIRET VARCHAR(14) NOT NULL, CONSTRAINT cclient PRIMARY KEY (IDClient) ); CREATE TABLE Produit ( IDProduit INT NOT NULL , PrixVente INT NOT NULL , QuantiteEnStock INT NOT NULL , CONSTRAiNT cproduit PRIMARY KEY (IDProduit) ) ; CREATE TABLE Commande ( IDNumeroCde INT NOT NULL , Date DATE NOT NULL , CONSTRAINT ccommande PRIMARY KEY (IDNumeroCde) );
In relational algebra and calculus it gives:
The fact that I can't explain it in relational calculus let me think that I've done a mistake.
I read all the links you provided and therfore add some comments and changes on my tables, can you tell me if I'm right on my assumptions?
But the last ones have the same primary key then. is it a problem?
UML class diagrams do not include relations in a class' attributes list, so when creating database tables representing those classes, the database designer must identify and specify them, much like the software developer must create the pointers and lists to support the related objects.
In your diagram,
Commande relates to
Client but does not explicitly specify a
IDClient attribute. When creating the
Commande table, you must include this attribute along with a foreign key to
You can find further information about this in Database Design - UML/SQL:
The UML representation of the Order class contains only its own descriptive attributes. The UML association tells which customer placed an order. In the database, we will need a different way to identify the customer; that will be part of the relation scheme (below).
In addition to Ziggy answer, if you want to make this diagram work, you need to edit it, for example you should create a third table called
cleint_order and this table has primary key from
Client table and
product table since one client may have one or more product and one product can be ordered from many customers.