Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [MySql] inizializzazione campo data

    Ciao
    allora, io ho una tabella che vorrei creare cn questi comandi.

    codice:
    MA_BanForum	DATETIME DEFAULT DATE_SUB(NOW(), INTERVAL 1 DAYS),
    MA_Soft		DATETIME DEFAULT DATE_ADD(NOW(), INTERVAL 7 DAYS),
    MA_SemiSoft	DATETIME DEFAULT DATE_ADD(NOW(), INTERVAL 14 DAYS),
    MA_Supporter	DATETIME DEFAULT DATE_ADD(NOW(), INTERVAL 30 DAYS),
    Questo perchè volevo che quando inserisco un nuovo record abbia di default le date che ho scelto (ovvero MA_BanForum il giorno prima, MA_Soft tra una settimana, ecc...)
    Però quando do il comando mi da questo errore

    codice:
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use near 'DATE_
    SUB(NOW(), INTERVAL 1 DAYS),
    MA_Soft         DATETIME DEFAULT DATE_ADD(NOW(), INTE' at line 24
    Come mai? Non posso mettere le funzioni nel default? Oppure sbaglio?
    Grazie!

  2. #2
    Purtroppo non puoi....
    The DEFAULT clause specifies a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column.

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

  3. #3
    Ah, peccato...
    Va bhe, vorrà dire che lo metto nel codice, grazie

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.