Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it L'avatar di Donovant
    Registrato dal
    Sep 2005
    residenza
    London
    Messaggi
    1,329

    Come si usa CONSTRAINT campo CHECK???

    Salve ragazzi, vorrei capire come utilizzare CONSTRAINT campo CHECK....
    nn ho capito bene.
    Ad esempio se io volessi aggiungere un attributo Stipendio ad una tabella Persone con il vincolo che questo debba essere compreso tra un valore1 ed un valore2.
    Grazie.
    Beati gli smemorati, perchè avranno la meglio anche sui loro errori...

    My gallery: http://donovant.deviantart.com/gallery/

  2. #2
    Utente di HTML.it L'avatar di Donovant
    Registrato dal
    Sep 2005
    residenza
    London
    Messaggi
    1,329
    Allora ho fatto in this way:

    la colonna Stipendio ha solo un valore impostato = 999 gli altri sono a NULL

    ALTER TABLE persone ADD CONSTRAINT ck_stip CHECK (Stipendio BETWEEN 1000 AND 2000);

    a questo punto do l'ok e va tutto alla perfezione, n mi da errori, quando vado a vedere la tabella Persone nn è successo niente. Qualcuno mi sa dire come mai, o come devo utlizzare sto CHECK CONSTRAINT ???
    Grazie.
    Beati gli smemorati, perchè avranno la meglio anche sui loro errori...

    My gallery: http://donovant.deviantart.com/gallery/

  3. #3
    in nessun modo.... e' fasullo (per finta) con mysql. Esiste solo per compatibilita' SQL della query.

    Chissa' poi con la 5.1 (boh!!!)

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  4. #4
    Utente di HTML.it L'avatar di Donovant
    Registrato dal
    Sep 2005
    residenza
    London
    Messaggi
    1,329
    Possibile...? quindi non serve a niente?
    E come si fa a mettere un vincolo ai dati inseriti dall'utente??? si può fare un controllo solo attraverso PHP? Io pensavo si potesse anche via MySql.
    Beati gli smemorati, perchè avranno la meglio anche sui loro errori...

    My gallery: http://donovant.deviantart.com/gallery/

  5. #5
    Originariamente inviato da Donovant
    Possibile...? quindi non serve a niente?
    E come si fa a mettere un vincolo ai dati inseriti dall'utente??? si può fare un controllo solo attraverso PHP? Io pensavo si potesse anche via MySql.
    #

    InnoDB tables support checking of foreign key constraints. See Section 13.2, “The InnoDB Storage Engine”. Note that the FOREIGN KEY syntax in InnoDB is more restrictive than the syntax presented for the CREATE TABLE statement at the beginning of this section: The columns of the referenced table must always be explicitly named. InnoDB supports both ON DELETE and ON UPDATE actions on foreign keys. For the precise syntax, see Section 13.2.6.4, “FOREIGN KEY Constraints”.

    For other storage engines, MySQL Server parses and ignores the FOREIGN KEY and REFERENCES syntax in CREATE TABLE statements. The CHECK clause is parsed but ignored by all storage engines. See Section 1.9.5.4, “Foreign Keys”.

    Important

    The inline REFERENCES specifications where the references are defined as part of the column spoecification are silently ignored by InnoDB. InnoDB only accepts REFERENCES clauses when specified as part of a separate FOREIGN KEY specification.
    http://dev.mysql.com/doc/refman/5.0/...ate-table.html

    controlla i dati con il php....

    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.