PDA

View Full Version : AIUTO SQL in MYSQL


mercurio76
14-10-2003, 16:15
Ciao a tutti...sapete come si fa ad impostare i comandi ON UPDATE e ON DELETE per l'integrità referenziale quando però le tabelle sono già state create?
Sfogliando i manuali ho visto che sono due operazioni che si fanno in fase di creazione della tabella, si possono fare anche a tabella già fatta? Se si come?

Ciao e grazie

cionci
14-10-2003, 16:55
Prima di tutto...che tipo di tabelle sono ? InnoDB o MyISAM ?

cionci
14-10-2003, 17:30
Comunque puoi:

ALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...]

alter_specification:
ADD [COLUMN] create_definition [FIRST | AFTER column_name ]
or ADD [COLUMN] (create_definition, create_definition,...)
or ADD INDEX [index_name] (index_col_name,...)
or ADD PRIMARY KEY (index_col_name,...)
or ADD UNIQUE [index_name] (index_col_name,...)
or ADD FULLTEXT [index_name] (index_col_name,...)
or ADD [CONSTRAINT symbol] FOREIGN KEY index_name (index_col_name,...)
[reference_definition]
or ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}
or CHANGE [COLUMN] old_col_name create_definition
or MODIFY [COLUMN] create_definition
or DROP [COLUMN] col_name
or DROP PRIMARY KEY
or DROP INDEX index_name
or DISABLE KEYS
or ENABLE KEYS
or RENAME [TO] new_tbl_name
or ORDER BY col
or table_options


reference_definition:
REFERENCES tbl_name [(index_col_name,...)]
[MATCH FULL | MATCH PARTIAL]
[ON DELETE reference_option]
[ON UPDATE reference_option]

reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT

cionci
14-10-2003, 17:35
http://www.mysql.com/doc/en/InnoDB_foreign_key_constraints.html

mercurio76
14-10-2003, 17:39
Grazie mille..adesso provo. Le tabelle cmq sono MyISAM..

Grazie e a presto :D

cionci
14-10-2003, 19:35
Allora vanno convertite...funziona solo sulle tabelle InnoDB !!!

mercurio76
14-10-2003, 20:19
eh eh..me ne sono accorto...vabbè farò sta conversione.
Speriamo che non ci siano problemi..

Grazie ancora ciao

cionci
15-10-2003, 07:26
Altrimenti fai il backup della tabella prima ;)
Comunque non ci dovrebbero essere problemi...

mercurio76
15-10-2003, 16:17
Ho trovato un client visuale per MySql che è una figata...secondo me è fatto meglio del Control Center...si chiama SQLyog..ti pemette di fare tutto con pochi semplici click..

Cmq tutto ok..edesso ho tutte le relazioni belle salde con integrità referenziale..

grazie e ciao