| STUDIAMO UNA BASE DI DATI|pt.3 eng-ita

in Olio di Balenalast year

image.png

INTRODUZIONE E TRACCIA

Bentornati a tutti, e soprattutto buona feste a tutti, dopo un po' di giorni di festa ho deciso di tornare a mettere un bel post e ho pensato qual è il modo migliore? oggi procederemo con lo studio di una base di dati...vedremo prima il modello logico, concettuale dopo di che vedremo anche l'sql.

Si vogliono organizzare le informazioni relative ai clienti, ai loro rappresentanti e alle fatture emesse.

Ogni rappresentante ha tanti clienti mentre a un cliente corrisponde un solo rappresentante. Per semplicità si supponga di registrare con la data e l'importo totale di ogni fattura senza specificare le righe di dettaglio sugli articoli venduti...definire il modello del database e rappresentare le varie entità

MODELLO CONCETTUALE

Come primo passo procediamo con la realizzazione del modello concettuale, per fare ciò bisogna individuare le nostre entità quindi rileggiamo il testo più volte fino a capire quali sono gli oggetti fondamentali per la creazione della nostra base di dati

per non confonderci andiamo a sottolineare all'interno della nostra traccia in rosso le entità e in giallo i vari attributi, nel nostro caso abbiamo tre entità: cliente, fattura e rappresentante.

image.png

una volta individuate le entità andiamo a individuare i vari attributi delle nostre entità:

Cliente avrà come chiave primaria codice cliente o codice fiscale non cambia nulla, tra gli attributi avrà un nome, un cognome, l'email e il telefono.

Rappresentante invece avrà come chiave primaria codice rappresentante mentre come attributi nome, cognome, telefono e e-mail.

per concludere fattura avrà come chiave primaria codice fattura e come attributi importo, nome e data come richiesto dalla traccia

Se vedete che la traccia non vi mette a disposizione tutti gli attributi necessari ricordatevi che toccherà a noi inserirli...ricordatevi che devono essere più reali possibili al nostro caso :)
image.png

ASSOCIAZIONI

Una volta fatto ciò procediamo con collegare le nostre entità, colleghiamo cliente a rappresentante con un 1 a N poiché un cliente può avere più rappresentanti mentre un rappresentante può avere un solo cliente ed infine colleghiamo sempre cliente a fattura poiché un cliente può avere più fatture mentre una fattura stessa non può avere più clienti, quindi riassumendo avremo 3 entità e 2 associazioni...come vedremo qui sotto nella foto che vi avrò caricato:

image.png

MODELLO LOGICO

Una volta completato il modello concettuale procediamo con il modello logico… il modello logico consiste in un elenco dei vari attributi delle nostre entità attraverso una specie di elenco.

Come prima cosa inseriamo per primo l'entità con meno chiavi esterne fino ad arrivare alle entità con più chiavi esterne.
Quindi come prima entità descriveremo cliente inserendo tra le parentesi la chiave primaria, gli attributi ed eventuali chiavi esterne(COSA MOLTO IMPORTANTE DA FARE E' CHE LA CHIAVE PRIMARIA VA SEMPRE SOTTOLINATA...MENTRE TUTTO IL RESTO NO) dopo verrà fatture ed infine rappresentanti

image.png




image.png

INTRODUCTION AND TRACKING

Welcome back everyone, and especially happy holidays to everyone, after a few days of celebration I decided to come back and put a nice post and I thought what is the best way? today we will proceed with the study of a database...we will first see the logical, conceptual model after that we will also see the sql.

You want to organize information about customers, their representatives and invoices issued.

Each representative has many customers while one customer corresponds to one representative. For simplicity suppose we record with the date and total amount of each invoice without specifying the detail rows on the sold items...define the database model and represent the various entities

CONCEPTUAL MODEL

As a first step let's proceed with the creation of the conceptual model, to do this we need to identify our entities so let's reread the text several times until we understand what are the fundamental objects for the creation of our database

in order not to confuse ourselves let's underline within our trace in red the entities and in yellow the various attributes, in our case we have three entities: customer, invoice and representative.

image.png

once we have identified the entities let's go to identify the various attributes of our entities:

Customer will have as primary key customer code or tax code nothing changes, among the attributes it will have a first name, last name, email and phone.

Representative on the other hand will have as primary key representative code while as attributes first name, last name, phone and email.

finally invoice will have as primary key invoice code and as attributes amount, name and date as required by the trace

If you see that the trace does not provide you with all the necessary attributes remember that it will be up to us to insert them...remember that they must be as real as possible to our case :)
image.png

ASSOCIATIONS

Once that is done we proceed with linking our entities, we link customer to representative with a 1 to N since a customer can have multiple representatives while a representative can only have one customer and finally we always link customer to invoice since a customer can have multiple invoices while an invoice itself cannot have multiple customers, so in summary we will have 3 entities and 2 associations...as we will see below in the picture I will have uploaded for you:

image.png

LOGICAL MODEL
.
Once we have completed the conceptual model we proceed with the logical model...the logical model consists of listing the various attributes of our entities through some sort of list.

As first we enter the entity with the least foreign keys until we get to the entities with the most foreign keys.
Then as the first entity we will describe customer by inserting in parentheses the primary key, attributes and any foreign keys(VERY IMPORTANT THING TO DO IS THAT THE PRIMARY KEY ALWAYS SHOULD BE UNDERLINED...WHILE EVERYTHING ELSE IS NOT) after it will come invoices and finally representatives

image.png

Sort:  

@tipu curate

grazie mille!!! e buon natale

!discovery 30


This post was shared and voted inside the discord by the curators team of discovery-it
Join our community! hive-193212
Discovery-it is also a Witness, vote for us here
Delegate to us for passive income. Check our 80% fee-back Program

Congratulations @fraaaaa! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You distributed more than 200 upvotes.
Your next target is to reach 300 upvotes.
You received more than 1250 upvotes.
Your next target is to reach 1500 upvotes.
You made more than 200 comments.
Your next target is to reach 300 comments.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Check out our last posts:

Christmas Challenge - Offer a gift to your friends
HiveBuzz World Cup Contest - Sponsor Feedback and Feedback Request
HiveBuzz World Cup Contest - Prizes from our sponsors
The Hive Gamification Proposal Renewal
Support the HiveBuzz project. Vote for our proposal!

Sei un ottima fonte per informarsi. Complimenti per i tuoi post che sono di una qualità elevatissima.