Sei sulla pagina 1di 3

create database Stage

create table Aziende(


PIVA char(16) primary key not null,
Nome char(100) not null,
Indirizzo char(100) not null,
Cap char(5) not null,
Citta char(20) not null,
Provincia char(2) not null,
Telefono char(10) not null,
Email char(100) not null,
SedeCentrale char(100) not null,
Fatturato float(10) not null
);

create table Tutor(


CodiceFiscale char(16) primary key not null,
NomeTutor char(20) primary key not null,
CognomeTutor char(20) not null,
Materia char(20),
Cellulare char(10),
Eta int,
Maschio boolean not null
);

create table Studenti(


Matricola char(16) primary key not null,
Nome char(20) not null,
Cognome char(20) not null,
Classe char(10) not null,
DataNascita date not null,
KAzienda char(16),
KTutor char(16),
index(KAzienda),
index(KTutor),
foreign key (KAzienda) references Aziende(PIVA),
foreign key (KTutor) references Tutor(CodiceFiscale)
);

insert into Aziende (PIVA, Nome, Indirizzo, Cap, Citta, Provincia, Telefono, Email,
SedeCentrale, Fatturato) values ('123456789abcdefg', 'Agusta', 'Via fasulla',
'21017', 'Samarate', 'VA', '0331224466', 'agusta@gmail.com', 'Cascina Costa',
100000000000);
insert into Aziende (PIVA, Nome, Indirizzo, Cap, Citta, Provincia, Telefono, Email,
SedeCentrale, Fatturato) values ('abcdefghilmnopqr', 'Chiaravalli', 'Via fasulla2',
'21019', 'Casorate', 'VA', '0331223344', 'chiaravalli@gmail.com', 'Cavaria',
10000000);
insert into Aziende (PIVA, Nome, Indirizzo, Cap, Citta, Provincia, Telefono, Email,
SedeCentrale, Fatturato) values ('abcdefghilmn1234', 'Bticino', 'Via fasulla3',
'21059', 'Vicenza', 'VI', '0331225344', 'bticino@gmail.com', 'Milano', 1000020000);

insert into Tutor (CodiceFiscale, NomeTutor, CognomeTutor, Materia, Cellulare, Eta,


Maschio) values ('FCCMARC9685M496P', 'Marco', 'Facco', 'Matematica', '3409588223',
18, true);
insert into Tutor (CodiceFiscale, NomeTutor, CognomeTutor, Materia, Cellulare, Eta,
Maschio) values ('SLVGGMRK96PM4522', 'Mirka', 'Salvalaggio', 'Fisica',
'3552211444', 18, false);
insert into Tutor (CodiceFiscale, NomeTutor, CognomeTutor, Materia, Cellulare, Eta,
Maschio) values ('LRNRCC56K844P914', 'Riccardo', 'Lorenzato', 'Elettronica',
'3558895441', 18, true);
insert into Tutor (CodiceFiscale, NomeTutor, CognomeTutor, Materia, Cellulare, Eta,
Maschio) values ('MCHLPSNT4558H564', 'Michela', 'Pesante', 'Informatica',
'3534211874', 18, false);

insert into Studenti (Matricola, Nome, Cognome, Classe, DataNascita, KAzienda,


KTutor) values ('cavolochebello17', 'Edoardo', 'Busatta', '4INF', '1995/10/12',
'123456789abcdefg', 'FCCMARC9685M496P');
insert into Studenti (Matricola, Nome, Cognome, Classe, DataNascita, KAzienda,
KTutor) values ('cavolochebello18', 'Matteo', 'Strangio', '5INF', '1996/12/14',
'abcdefghilmnopqr', 'SLVGGMRK96PM4522');
insert into Studenti (Matricola, Nome, Cognome, Classe, DataNascita, KAzienda,
KTutor) values ('cavolochebello19', 'Giacomo', 'Pignoni', '5INF', '1996/08/15',
'abcdefghilmnopqr', 'LRNRCC56K844P914');
insert into Studenti (Matricola, Nome, Cognome, Classe, DataNascita, KAzienda,
KTutor) values ('cavolochebello20', 'Carlo', 'Lamanna', '1INF', '1996/10/14',
'123456789abcdefg', 'MCHLPSNT4558H564');

QUERY MODIFICA
UPDATE Studenti
Set DataNascita='1993/10/14'
Where Nome="Carlo";
-------------------------------
Update Studenti
Set DataNascita='1994/10/12'
Where Nome="Edoardo"

QUERY 1
Select Studenti.Nome, Studenti.Cognome, Studenti.DataNascita, Tutor.NomeTutor,
Tutor.CognomeTutor
From Studenti, Tutor
Where CodiceFiscale=KTutor and (Tutor.Materia='informatica' or
Tutor.Materia='elettronica')

QUERY 2
Select Studenti.Nome, Studenti.Cognome, Studenti.Classe, Aziende.Nome,
Aziende.Indirizzo, Aziende.Cap, Aziende.Citta, Aziende.Provincia
From Studenti, Aziende
Where (Studenti.DataNascita>='1993/09/01' and Studenti.DataNascita<='1995/06/30')
and KAzienda=PIVA

QUERY 3
Select Studenti.Nome, Studenti.Cognome, Tutor.NomeTutor, Tutor.CognomeTutor,
Tutor.Materia
From Studenti, Tutor
Where KTutor=CodiceFiscale and Studenti.DataNascita>='1994/01/01' and
Studenti.Classe like '4%'

QUERY 4
Select Aziende.PIVA, Aziende.Nome, Aziende.Indirizzo, Aziende.Cap,
Aziende.Provincia, Aziende.Telefono, Aziende.SedeCentrale, Aziende.Fatturato
From Aziende
Where Citta not like 'Gallarate'

QUERY 5
select Aziende.PIVA, Aziende.Nome, Aziende.Indirizzo, Aziende.Cap,
Aziende.Provincia, Aziende.Telefono, Aziende.SedeCentrale, Aziende.Fatturato
from Aziende
where Citta in ('Vicenza','Venezia','Varese') and SedeCentrale not in
('Vicenza','Venezia','Varese')

QUERY 6
SELECT Tutor.NomeTutor, Tutor.CognomeTutor, Tutor.Materia
FROM Tutor
WHERE NomeTutor between 'A%' and 'M%'

QUERY 8
select Studenti.Matricola, Studenti.Nome, Studenti.Cognome
From Studenti
where [Nome Tutor]=Tutor.NomeTutor and [Cognome Tutor]=Tutor.TutorCognome and
CodiceFiscale=KTutor

Potrebbero piacerti anche