MySQL中用sql语句插入时期
2010-04-24 17:16
274 查看
mysql> create table testdate(
-> id int not null auto_increment primary key,
-> time date);
Query OK, 0 rows affected (0.30 sec)
mysql> insert into testdate(time) values('2010-4-23');
Query OK, 1 row affected (0.06 sec)
mysql> select * from testdate;
+----+------------+
| id | time |
+----+------------+
| 1 | 2010-4-23|
+----+------------+
1 row in set (0.00 sec)
mysql> alter table testdate add column current time;
Query OK, 1 row affected (0.25 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> update testdate set current='21:18:00' where id=1;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from testdate;
+----+------------+----------+
| id | time | current |
+----+------------+----------+
| 1 | 2010-4-23 | 21:18:00 |
+----+------------+----------+
1 row in set (0.00 sec)
mysql> alter table testdate add column combine timestamp;
Query OK, 1 row affected (0.14 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> update testdate set combine='20050504212000' where id=1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> select * from testdate;
+----+------------+----------+---------------------+
| id | time | current | combine |
+----+------------+----------+---------------------+
| 1 | 2010-4-23 | 21:18:00 | 2010-4-23 21:20:00 |
+----+------------+----------+---------------------+
1 row in set (0.00 sec)
mysql> update testdate set combine=2010-4-23 21:22:0' where id=1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from testdate;
+----+------------+----------+---------------------+
| id | time | current | combine |
+----+------------+----------+---------------------+
| 1 | 2010-4-23 | 21:18:00 | 2010-4-23 21:22:00 |
+----+------------+----------+---------------------+
1 row in set (0.00 sec)
mysql> select * from testdate where month(time)=5;
+----+------------+----------+---------------------+
| id | time | current | combine |
+----+------------+----------+---------------------+
| 1 | 2010-4-23 | 21:18:00 | 2010-4-23 21:22:00 |
+----+------------+----------+---------------------+
1 row in set (0.00 sec)
-> id int not null auto_increment primary key,
-> time date);
Query OK, 0 rows affected (0.30 sec)
mysql> insert into testdate(time) values('2010-4-23');
Query OK, 1 row affected (0.06 sec)
mysql> select * from testdate;
+----+------------+
| id | time |
+----+------------+
| 1 | 2010-4-23|
+----+------------+
1 row in set (0.00 sec)
mysql> alter table testdate add column current time;
Query OK, 1 row affected (0.25 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> update testdate set current='21:18:00' where id=1;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from testdate;
+----+------------+----------+
| id | time | current |
+----+------------+----------+
| 1 | 2010-4-23 | 21:18:00 |
+----+------------+----------+
1 row in set (0.00 sec)
mysql> alter table testdate add column combine timestamp;
Query OK, 1 row affected (0.14 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> update testdate set combine='20050504212000' where id=1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> select * from testdate;
+----+------------+----------+---------------------+
| id | time | current | combine |
+----+------------+----------+---------------------+
| 1 | 2010-4-23 | 21:18:00 | 2010-4-23 21:20:00 |
+----+------------+----------+---------------------+
1 row in set (0.00 sec)
mysql> update testdate set combine=2010-4-23 21:22:0' where id=1;
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from testdate;
+----+------------+----------+---------------------+
| id | time | current | combine |
+----+------------+----------+---------------------+
| 1 | 2010-4-23 | 21:18:00 | 2010-4-23 21:22:00 |
+----+------------+----------+---------------------+
1 row in set (0.00 sec)
mysql> select * from testdate where month(time)=5;
+----+------------+----------+---------------------+
| id | time | current | combine |
+----+------------+----------+---------------------+
| 1 | 2010-4-23 | 21:18:00 | 2010-4-23 21:22:00 |
+----+------------+----------+---------------------+
1 row in set (0.00 sec)
相关文章推荐
- mysql增加插入执行sql语句文件的大小
- 允许mysql同时插入多条sql语句
- [lua, mysql] 将多条记录数据组合成一条sql插入语句(for mysql)
- MySQL基本SQL语句之数据插入、删除数据和更新数据
- mysql 有条件插入语句sql
- Mysql大量插入数据时SQL语句的优化
- Oracle和Mysql-可行的插入多条记录的SQL语句(总结)
- mysql导入CSV文件及JAVA读取CSV文件和MYSQL批量插入和更新及ibatis常用SQL语句
- Mysql--一条SQL语句多条插入、更新、删除
- Mysql大量插入数据时SQL语句的优化
- sql语句之随机查询记录和批量插入--基于mysql
- MySQL中使用sql语句插入日期时间类型的写法
- 插入mysql语句报错:1064 - 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
- MYSQL 数据表中行存在时更新,不存在时插入的SQL语句
- MySql避免重复插入sql语句
- mybatis--mysql 批量插入批量更新在一条sql语句中完成
- mysql sql 语句插入 blob字段的插入
- 在linux下写的mysql无法插入,sql语句在复制中变'脏'了.
- 【SQL】如何一次(一条SQL语句)向ORACLE中插入多组/多条数据,不同于mysql
- mysql中使用sql语句插入日期时间类型的写法