🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.bd.misc
Article #255

Re: [MySQL] Fecha y hora actuales como valor por defecto al insertar registro

#255
From: stripTM
Date: Wed, 25 Aug 2004 23:17
47 lines
3353 bytes
Kepler escribi�:
>     En una tabla, tengo entre otros estos dos campos: "fecha" y "hora", y
> quisiera que por defecto, al insertar un nuevo registro, se les asignara la
> fecha y hora actuales del servidor.
> 

Creo que lo que buscas est� aqu�
http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html#IDX1640

# NULL values are handled differently for TIMESTAMP columns than for 
other column types. You cannot store a literal NULL in a TIMESTAMP 
column; setting the column to NULL sets it to the current date and time. 
Because TIMESTAMP columns behave this way, the NULL and NOT NULL 
attributes do not apply in the normal way and are ignored if you specify 
them. On the other hand, to make it easier for MySQL clients to use 
TIMESTAMP columns, the server reports that such columns can be assigned 
NULL values (which is true), even though TIMESTAMP never actually will 
contain a NULL value. You can see this when you use DESCRIBE tbl_name to 
get a description of your table. Note that setting a TIMESTAMP column to 
0 is not the same as setting it to NULL, because 0 is a valid TIMESTAMP 
value.
# With one exception, a 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 as of MySQL 
4.1.2. See section 12.3.1.2 TIMESTAMP Properties as of MySQL 4.1. If no 
DEFAULT value is specified for a column, MySQL automatically assigns 
one, as follows. If the column can take NULL as a value, the default 
value is NULL. If the column is declared as NOT NULL, the default value 
depends on the column type:

     * For numeric types other than those declared with the 
AUTO_INCREMENT attribute, the default is 0. For an AUTO_INCREMENT 
column, the default value is the next value in the sequence.
     * For date and time types other than TIMESTAMP, the default is the 
appropriate ``zero'' value for the type. For the first TIMESTAMP column 
in a table, the default value is the current date and time. See section 
12.3 Date and Time Types.
     * For string types other than ENUM, the default value is the empty 
string. For ENUM, the default is the first enumeration value.

BLOB and TEXT columns cannot be assigned a default value.


-- 
Saludos -=stripTM=-
Technical Details
Message-ID: <2p4kuuFfgut8U1@uni-berlin.de>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail
References: <2p38j4Fg977rU1@uni-berlin.de>

Show Full Headers
Complete Article Headers
X-Google-Thread: 106e2f,2a91492b6b6db535
X-Google-Attributes: gid106e2f,public
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail
From: stripTM <striptmNOVALE@yahoo.com>
Newsgroups: es.comp.bd.misc
Subject: Re: [MySQL] Fecha y hora actuales como valor por defecto al insertar
 registro
Date: Thu, 26 Aug 2004 01:17:00 +0200
Lines: 47
Message-ID: <2p4kuuFfgut8U1@uni-berlin.de>
References: <2p38j4Fg977rU1@uni-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de DXU/8GgsRxf5D8zrTAZt0gsQqizHaomfp07HZqwOEgKqvekIeY
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; es-ES; rv:1.7.2) Gecko/20040803 MultiZilla/1.6.4.0b
X-Accept-Language: es-es, es, en-us, en
In-Reply-To: <2p38j4Fg977rU1@uni-berlin.de>