Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Didattica > Corsi A - F > Basi di dati ~ informatica triennale > Un po' di comandi SQL
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
CaboM.BNA
.grande:maestro.

User info:
Registered: Jan 2006
Posts: 503 (0.07 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 23:32:44 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Un po' di comandi SQL

Hola gente...
Cercasi qualche "virtuoso" di SQL...

Mettiamo questo esempio:
- ho definito uno schema che si chiama universitario
- all'interno di questo schema ho 2 tabelle: studente e docente
- docente ha 3 attributi/colonne: nome , cognome , corso tenuto
- ho definito l'attributo nome come PRIMARY KEY

Ipotesi: mi accorgo che non va bene come chiave primaria. Con che sitassi devo usare il comando ALTER per ri-definire come chiave primaria (ad es.) nome e cognome?

P.S. (per i più pedanti&pignoli) SO che la Castano ha detto che "una base cosi progettata non va bene, perché la chiave primaria è stata scelta male. Invece del comando ALTER si sarebbe dovuta progettare meglio la tabella..."; la mia è semplice curiosità...

19-10-2007 19:05
Click Here to See the Profile for CaboM.BNA Click here to Send CaboM.BNA a Private Message Find more posts by CaboM.BNA Add CaboM.BNA to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
n3o
tanto c'è SPASS...

User info:
Registered: Oct 2005
Posts: 134 (0.02 al dì)
Location: Brescia
Corso: Informatica Magistrale
Anno:
Time Online: 1 Day, 19:26:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Se hai usato una sintassi del genere:

code:
CREATE TABLE docenti ( nome VARCHAR(50) PRIMARY KEY, cognome VARCHAR(50) NOT NULL, corso INTEGER REFERENCES qualcosa );
il terminale psql dovrebbe restituirti questo messaggio:
code:
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "nome_pkey" for table "docenti" CREATE TABLE
Postgres non offre il comodissimo comando DROP PRIMARY KEY quindi bisogna arrangiarsi così:
code:
ALTER TABLE docenti DROP CONSTRAINT nome_pkey; ALTER TABLE docenti ADD CONSTRAINT pr_key PRIMARY KEY (nome, cognome);
Fammi sapere se funziona o trovi una soluzione meno macchinosa!

__________________
The answer is blowing in the wind...

20-10-2007 11:23
Click Here to See the Profile for n3o Click here to Send n3o a Private Message Find more posts by n3o Add n3o to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
CaboM.BNA
.grande:maestro.

User info:
Registered: Jan 2006
Posts: 503 (0.07 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 23:32:44 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

perfetto...
appena testato, funziona benissimo... :clap:
grazie mille

20-10-2007 15:33
Click Here to See the Profile for CaboM.BNA Click here to Send CaboM.BNA a Private Message Find more posts by CaboM.BNA Add CaboM.BNA to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
johnnyd
.grande:maestro.

User info:
Registered: Sep 2005
Posts: 840 (0.12 al dì)
Location: Milano (Fragagnano)
Corso: Informatica
Anno: IV
Time Online: 13 Days, 22:13:29 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Quando ho una tabella con relazione n a n... è corretto (come scritto in seguito) usare una sintassi del genere per definire le due chiavi esterne che sono anche chiavi primarie..

CREATE TABLE esamiSvolti (
Matricola char[10],
codEsame int[10]
PRIMARY KEY(Matricola, codEsame)
FOREIGN KEY (codEsame, Matricola)
REFERENCES esami(codEsame), matricole(Matricola)
ON DELETE SET NULL
ON UPDATE CASCADE
)

__________________
My Blog - My Photo Album

21-10-2007 12:21
Click Here to See the Profile for johnnyd Click Here to See the Blog of johnnyd Click here to Send johnnyd a Private Message Find more posts by johnnyd Add johnnyd to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
n3o
tanto c'è SPASS...

User info:
Registered: Oct 2005
Posts: 134 (0.02 al dì)
Location: Brescia
Corso: Informatica Magistrale
Anno:
Time Online: 1 Day, 19:26:05: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Prova con:

code:
CREATE TABLE esamiSvolti ( Matricola INTEGER REFERENCES matricole (Matricola) ON DELETE SET NULL ON UPDATE CASCADE, codEsame INTEGER REFERENCES esami (codEsame) ON DELETE SET NULL ON UPDATE CASCADE, PRIMARY KEY (Matricola, codEsame) );

__________________
The answer is blowing in the wind...

21-10-2007 20:39
Click Here to See the Profile for n3o Click here to Send n3o a Private Message Find more posts by n3o Add n3o to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
johnnyd
.grande:maestro.

User info:
Registered: Sep 2005
Posts: 840 (0.12 al dì)
Location: Milano (Fragagnano)
Corso: Informatica
Anno: IV
Time Online: 13 Days, 22:13:29 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

in che formato salvereste delle percentuali in un db?

qualcosa del tipo 1.1 per il 10% o direttamente un int/doube contenente il 10?

__________________
My Blog - My Photo Album

25-10-2007 09:28
Click Here to See the Profile for johnnyd Click Here to See the Blog of johnnyd Click here to Send johnnyd a Private Message Find more posts by johnnyd Add johnnyd to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
xSharKMaNx
un gioco della follia

User info:
Registered: Sep 2007
Posts: 1477 (0.23 al dì)
Location:
Corso: F49
Anno: Laureato
Time Online: 10 Days, 17:15:29 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by johnnyd
in che formato salvereste delle percentuali in un db?

qualcosa del tipo 1.1 per il 10% o direttamente un int/doube contenente il 10?


Memorizza un double con il valore effettivo della percentuale quindi nel tuo caso 10 in modo tale da poter reperire il dato e a sua volta effettuare i vari calcoli su di essa

25-10-2007 10:53
Click Here to See the Profile for xSharKMaNx Click here to Send xSharKMaNx a Private Message Find more posts by xSharKMaNx Add xSharKMaNx to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
GiKappa
Dubbioso a Progetto

User info:
Registered: Oct 2004
Posts: 1800 (0.24 al dì)
Location: Brescia
Corso: Informatica
Anno: Laureato Triennale
Time Online: 9 Days, 22:39:19 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

scusate,

il prof ferrara all'ultima lezione ha spiegato a grandi linee l'installazione di psql.

io ce l'ho già installato e funzionante, ma vedevo che lui creava un cluster e utilizzava il comando "postmaster" che nella versione per windows non ho trovato.

sapete qual è il suo corrispettivo?

grazie

26-10-2007 18:54
Click Here to See the Profile for GiKappa Click here to Send GiKappa a Private Message Find more posts by GiKappa Add GiKappa to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
CaboM.BNA
.grande:maestro.

User info:
Registered: Jan 2006
Posts: 503 (0.07 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 23:32:44 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

quasi mi vergogno a chiederlo...
pero non sono proprio riuscito a trovare il carattere di escape..

mi spiego meglio.
in una colonna definita come varchar(20) voglio inserire L'armata brancaleone . Siccome bisogna digitare

code:
INSERT INTO nome_tabella VALUES ('L'armata bracaleone')

non so cosa digitare per evitare che il mio (innocente) apostrofo venga interpretato come carattere di terminazione della stringa...

22-11-2007 17:11
Click Here to See the Profile for CaboM.BNA Click here to Send CaboM.BNA a Private Message Find more posts by CaboM.BNA Add CaboM.BNA to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkSchneider
Why so serious?

User info:
Registered: Feb 2004
Posts: 1250 (0.16 al dì)
Location: Brescia
Corso: Informatica
Anno: out of bounds :/
Time Online: 26 Days, 1:01:59 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by CaboM.BNA
quasi mi vergogno a chiederlo...
pero non sono proprio riuscito a trovare il carattere di escape..

mi spiego meglio.
in una colonna definita come varchar(20) voglio inserire L'armata brancaleone . Siccome bisogna digitare
code:
INSERT INTO nome_tabella VALUES ('L'armata bracaleone')

non so cosa digitare per evitare che il mio (innocente) apostrofo venga interpretato come carattere di terminazione della stringa...


dovrebbe bastare questo:

INSERT INTO nome_tabella VALUES (' L''armata brancaleone') :
con due apici, il secondo annulla il primo

per lo meno funziona così con il PL/SQL di oracle, anche se non so se sia quello utilizzato durante il corso di basi dati :D:D

22-11-2007 20:27
Click Here to See the Profile for DarkSchneider Click here to Send DarkSchneider a Private Message Find more posts by DarkSchneider Add DarkSchneider to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
CaboM.BNA
.grande:maestro.

User info:
Registered: Jan 2006
Posts: 503 (0.07 al dì)
Location:
Corso:
Anno:
Time Online: 1 Day, 23:32:44 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

:approved:
ti ringrazio...
ho appena testato, è proprio come dicevi tu..
certo che io sono babbo però... :sbonk:
non avevo provato la COSA PIU' OVVIA...
avevo immediatamente pensato solo caratteri come \ o " ..

22-11-2007 20:47
Click Here to See the Profile for CaboM.BNA Click here to Send CaboM.BNA a Private Message Find more posts by CaboM.BNA Add CaboM.BNA to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkSchneider
Why so serious?

User info:
Registered: Feb 2004
Posts: 1250 (0.16 al dì)
Location: Brescia
Corso: Informatica
Anno: out of bounds :/
Time Online: 26 Days, 1:01:59 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by CaboM.BNA
quasi mi vergogno a chiederlo...
pero non sono proprio riuscito a trovare il carattere di escape..

mi spiego meglio.
in una colonna definita come varchar(20) voglio inserire L'armata brancaleone . Siccome bisogna digitare
code:
INSERT INTO nome_tabella VALUES ('L'armata bracaleone')

non so cosa digitare per evitare che il mio (innocente) apostrofo venga interpretato come carattere di terminazione della stringa...


dovrebbe bastare questo:

INSERT INTO nome_tabella VALUES (' L''armata brancaleone) :
con due apici, il secondo annulla il primo

per lo meno funziona così con il PL/SQL di oracle, anche se non so se sia quello utilizzato durante il corso di basi dati :D:D

22-11-2007 21:06
Click Here to See the Profile for DarkSchneider Click here to Send DarkSchneider a Private Message Find more posts by DarkSchneider Add DarkSchneider to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DarkSchneider
Why so serious?

User info:
Registered: Feb 2004
Posts: 1250 (0.16 al dì)
Location: Brescia
Corso: Informatica
Anno: out of bounds :/
Time Online: 26 Days, 1:01:59 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by CaboM.BNA
:approved:
ti ringrazio...
ho appena testato, è proprio come dicevi tu..
certo che io sono babbo però... :sbonk:
non avevo provato la COSA PIU' OVVIA...
avevo immediatamente pensato solo caratteri come \ o " ..


di niente .. figurati :D

23-11-2007 20:51
Click Here to See the Profile for DarkSchneider Click here to Send DarkSchneider a Private Message Find more posts by DarkSchneider Add DarkSchneider to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 23:12.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.048 seconds (77.63% PHP - 22.37% MySQL) con 23 query.