• Non ci sono risultati.

VISTE LOGICHE E PERSONALIZZAZIONE DELLE MASCHERE 55 Trovare la media dei voti più alta tra le medie degli studenti maschi.

Nel documento ESERCITAZIONI SVOLTE ACCESS (pagine 63-66)

56. Costruire una maschera per l’immissione dell’elenco degli studenti. Successivamente personalizzarla

con una casella di riepilogo per l’inserimento del campo Genere.

57. Aggiungere alla maschera dell’esercizio precedente una sottomaschera collegata per l’inserimento

dei voti degli studenti.

58. Creare un database per rappresentare gli esami sostenuti dagli studenti di una università.

Il database è formato da quattro tabelle con i dati degli studenti iscritti, dei corsi offerti, con l’indica- zione della facoltà che li ha attivati, delle facoltà presenti nell’università e degli esami sostenuti dagli studenti:

Facoltà (CodFacoltà, NomeFacoltà, Indirizzo)

Studenti (Matricola, Cognome, Nome, Indirizzo, Telefono, CodFacoltà) Corsi (CodCorso, NomeCorso, Crediti, CodFacoltà)

La tabella Studenti, con chiave Matricola, raccoglie i dati anagrafici degli studenti dell’università, tramite la chiave esterna CodFacoltà, permette di sapere a quale facoltà lo studente è iscritto. La tabella Corsi, con chiave CodCorso, raccoglie le informazioni sui corsi offerti. Ogni corso è caratte- rizzato da un certo numero di crediti ed è attivato da una facoltà, identificata mediante la chiave esterna CodFacoltà. Uno studente per laurearsi deve conseguire un certo numero di crediti: 180 per la laurea di primo livello, conseguita la quale si può iscrivere alle lauree specialistiche. I corsi delle lauree specialistiche richiedono altri 120 crediti. Il valore del numero di crediti dipende dal corso. La tabella Facoltà con chiave CodFacoltà contiene la descrizione e l’indirizzo della facoltà.

La tabella Esami, con chiave ID, serve a registrare i voti degli studenti. ID è un progressivo assegnato automaticamente per ogni esame registrato. Nella tabella Esami sono registrati: lo studente che ha sostenuto l’esame, identificato con la chiave esterna Matricola, il corso oggetto della prova, ricono- sciuto dalla chiave esterna CodCorso, oltre alla data dell’esame e al voto conseguito. Il voto può assumere qualsiasi valore tra 1 e 30. Un esame si intende superato se il voto è maggiore o uguale a 18. Creare il database e le tabelle e inserire alcuni dati di prova. Sviluppare in Access le operazioni per: • aggiornare le quattro tabelle mediante maschere;

• costruire le interrogazioni (specificando la sequenza di operazioni relazionali utilizzate), in grado di fornire le seguenti informazioni:

- Elenco degli studenti che hanno superato un certo esame. - Elenco degli studenti che hanno sostenuto un certo esame.

- Elenco degli studenti iscritti a facoltà collocate in città diverse da quella di residenza, precisando città di residenza, facoltà e città sede della facoltà.

- Elenco degli esami superati in un certo periodo, suddivisi per corso. L’elenco deve contenere matricola, nome e cognome dello studente, descrizione del corso, data e voto.

- Media dei voti degli esami superati da un dato studente.

- Cognome e nome degli studenti con media superiore a un voto prefissato. - Descrizione dei corsi per i quali la media degli esami superati è maggiore di 24.

- Elenco degli studenti (con matricola, cognome e nome) che hanno superato almeno 10 esami. - Elenco degli studenti che non hanno sostenuto esami in un certo periodo.

59. Si vuole organizzare un database per la registrazione e il controllo delle assenze degli alunni di una

scuola. Descrivere l’analisi del problema individuando entità, attributi e associazioni; disegnare il modello E/R e derivare le tabelle.

Sviluppare in Access le operazioni per: • aggiornare l’archivio degli alunni;

• permettere l’inserimento e la modifica delle assenze di ogni alunno con l’indicazione della durata e del motivo dell’assenza;

• ottenere, a fine periodo, il conteggio dei giorni di assenza per alunno, ordinato per alunno; • individuare gli alunni con maggior numero di assenze;

• ottenere la lista degli alunni sempre presenti;

• inviare una breve comunicazione alla famiglia per gli alunni che hanno fatto più di un numero prefissato di assenze;

• ottenere il conteggio dei giorni di assenza per motivazione; • ottenere la media generale dei giorni di assenza nella scuola;

• calcolare la media dei giorni di assenza suddivisa per maschi e per femmine; • calcolare la media dei giorni di assenza suddivisa per classe.

ACCESS

Access is a designed relational DBMS for the Microsoft Windows environment. Access provides the user with a graphical interface to create tables, queries and it also allows the creation of forms and reports. For this reason we can define Access as an applications generator. The typical Access data engine for PC application is the Jet engine that stores all necessary data: tables, indexes, queries and so on in a single (.accdb) file. Indexes are based on the ISAM (Index Sequential Access

Method) organization. (See Chapter 1, Par. 4: Organizzazione a Indici”). The Access product can

also be installed with a more powerful data engine which is compatible with the Microsoft SQL Server product. In this way it is possible to develop applications running on a PC Windows platform or on a clusters of multiprocessor servers operating under control of an operating system of the Microsoft Windows Server family.

Customized database applications can be developed with Access by means of Access macro language or the Visual Basic programming language. Access has also many programs, called Wizard, that help in the development of applications and in writing queries interacting with the user by sessions of dialog boxes. Access greatly simplifies the implementation of a relational database due to the graphical approach in the definition of the database tables and adopting the QBE methodology in writing queries to extract data from the database.

Access QBE

Query By Example is a visual method for accessing data in a database through the use of graphical query templates. To show how to create a QBE query with Access let us consider the

Customers and Purchases tables with the following schema:

Customers ( CustomerID, Cname, Surname, SSN, Address, Town, ZIP ) Purchases ( ID, PurchaseDate, Article, UnitPrice, Qty, CustomerID )

The table Customers stores the information of the customers who made the purchases recorded in the table Purchases. Customers and Purchases are associated in a 1:N relationship that has been modelled with the foreign key Purchases.CustomerID associated with the primary key of the table

Customers.

We want to query the database to extract the purchases made by customers who live in London and, for every purchase, we want to know the name of the article, the date of the purchase and the total amount of the purchase, i.e. the product of UnitPrice and Qty.

To extract the requested data with an Access QBE we choose the Create tab in the ribbon and then, in the query group, we click the button Query Design. In the Show Table dialog box, in the Tables tab, we double click Customers and Purchases and then we close the Show Table dialog box. The Customers and Purchases tables appear in the graphical window of the query. Note the line connecting the CustomerID field in the Customers table with the CustomerID field in the Purchases table showing the relationship between the two tables and the execution of a join operation between them.

The Access QBE is a graphical tool and with the mouse we select and drag objects in the QBE

grid to define an example of the data we want to include in the record. We fill the grid as shown

in the figure. The Town field has been included in the grid to select the customers who live in London but it is not to be displayed and, in the line Show of the Town field, the  mark has been deselected. Note in the fourth column of the QBE grid the way to display the total amount of the purchase: Total: [UnitPrice]*[Qty]. The requested data will be displayed in a table with three columns labeled as: Article, PurchaseDate and Total.

GLOSSARY

Nel documento ESERCITAZIONI SVOLTE ACCESS (pagine 63-66)