I am trying to do this, but it seems that MySQL is not allowing me to solve this issue Or do I always expect to include the function in my INSERT questions?
create table fu (created INT NOT NULL DEFAULT UNIX_TIMESTAMP ()) I know about TIMESTAMP type which is a CURRENT_TIMESTAMP accepted default Does, but my customer insists on using era in the database.
The manner in which MySQL implements the TIMESTAMP data type is actually Store the time of the era in the database, you can simply use the TIMESTAMP column with the default of CURRENT_TIMESTAMP and apply it to UNIX_TIMESTAMP () If you want to display it as a Int: Make Table Fu (created TIMESTAMP tap default CURRENT_TIMESTAMP); Put in Foo values (current_Date ()), (now ()); Select unix_timestamp (created) from Foo; + ------------------------- + | Unix_timestamp (created) | + ------------------------- + | 1300248000 | | 1300306959 | + ------------------------- + 2 lines set (0.00 seconds) However, if you actually You want to have the datatype of the column in the INT You can use Bemaros's suggestion and set it through a trigger: Make Table Fu (Created INT NULL); Delimiter $$ Create tr_b_ins_foo trigger before inserting on foo for each line if new (set) is new.created then set new .created = unix_timestamp (); end if; End $$ delimiter; Insert Foo values (Unix_timestamp (current) () ()), (faucet); Select made from Foo; + ------------ + | Made + ------------ + | 1300248000 | | 13003069 9 5 + ------------ + 2 rows set (0.00 seconds)
Comments
Post a Comment