下面的过程,不知道是不是你想要的?
mysql> create table cc(id int not null auto_increment primary key,
-> name varchar(20) not null,date timestamp default now());
Query OK, 0 rows affected (0.08 sec)mysql> desc cc;
+-------+-------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | | |
| date | timestamp | YES | | CURRENT_TIMESTAMP | |
+-------+-------------+------+-----+-------------------+----------------+
3 rows in set (0.03 sec)mysql> insert into cc(id,name) values(1,'tom');
Query OK, 1 row affected (0.00 sec)mysql> select * from cc;
+----+------+---------------------+
| id | name | date |
+----+------+---------------------+
| 1 | tom | 2006-09-28 14:00:25 |
+----+------+---------------------+
1 row in set (0.00 sec)mysql> update cc set name='jim';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from cc;
+----+------+---------------------+
| id | name | date |
+----+------+---------------------+
| 1 | jim | 2006-09-28 14:00:25 |
+----+------+---------------------+
1 row in set (0.00 sec)
mysql> create table cc(id int not null auto_increment primary key,
-> name varchar(20) not null,date timestamp default now());
Query OK, 0 rows affected (0.08 sec)mysql> desc cc;
+-------+-------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | | |
| date | timestamp | YES | | CURRENT_TIMESTAMP | |
+-------+-------------+------+-----+-------------------+----------------+
3 rows in set (0.03 sec)mysql> insert into cc(id,name) values(1,'tom');
Query OK, 1 row affected (0.00 sec)mysql> select * from cc;
+----+------+---------------------+
| id | name | date |
+----+------+---------------------+
| 1 | tom | 2006-09-28 14:00:25 |
+----+------+---------------------+
1 row in set (0.00 sec)mysql> update cc set name='jim';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from cc;
+----+------+---------------------+
| id | name | date |
+----+------+---------------------+
| 1 | jim | 2006-09-28 14:00:25 |
+----+------+---------------------+
1 row in set (0.00 sec)
解决方案 »
- 弱弱的问一下 SQL是什么,MySQL又是什么
- 麻烦各位大虾帮我看看这个异常是为什么
- 关于乱码...虚拟主机mysql数据库导出
- 一个单表查询问题
- myslq的 expt 是否可以做
- 竟然有这么诡异的问题,研究了半个月头都大了,100分,帮我解释下啊大家
- vc连接mysql数据库的问题
- MySql 截取年月做日期比较
- server configuration denies access data source?
- 用jsp 使用sqlserver还是mysql与ODBC/JDBC连接哪个更方便?
- 怎么设置让Mysql 支持FULLTEXT 最小英文单词字母为3
- select语句怎样查找一个table中的最后一个表项?
hy2003fly()的方法在低版本上不对,default now()语法错误
如果想以后不被修改,可以在update的时候指定这一列继续使用当前值
以下是我模拟hy2003fly()的方法的结果
mysql> create table cc(id int not null auto_increment primary key,
-> name varchar(20) not null,date timestamp);
Query OK, 0 rows affected (0.11 sec)mysql> desc cc
-> ;
+-------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| name | varchar(20) | | | | |
| date | timestamp(14) | YES | | NULL | |
+-------+---------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)mysql> insert into cc(id,name) values(1,'tom');
Query OK, 1 row affected (0.04 sec)mysql> select * from cc;
+----+------+----------------+
| id | name | date |
+----+------+----------------+
| 1 | tom | 20060929094134 |
+----+------+----------------+
1 row in set (0.00 sec)mysql> update cc set name='jim',date=date;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0mysql> select * from cc;
+----+------+----------------+
| id | name | date |
+----+------+----------------+
| 1 | jim | 20060929094134 |
+----+------+----------------+
1 row in set (0.01 sec)