INSERT

Description

Writing data.

Syntax

1. > INSERT INTO [db.]table [(c1, c2, c3)] VALUES (v11, v12, v13), (v21, v22, v23), ...

Examples

1. drop table if exists t1;
2. create table t1(a int default (1+12), b int);
3. insert into t1(b) values(1), (1);

5. mysql> select * from t1;
6. +------+------+
7. | a    | b    |
8. +------+------+
9. |   13 |    1 |
10. |   13 |    1 |
11. +------+------+
12. 2 rows in set (0.01 sec)

14. drop table if exists t1;
15. create table t1 (a date);
16. insert into t1 values(DATE("2017-06-15 09:34:21")),(DATE("2019-06-25 10:12:21")),(DATE("2019-06-25 18:20:49"));

18. mysql> select * from t1;
19. +------------+
20. | a          |
21. +------------+
22. | 2017-06-15 |
23. | 2019-06-25 |
24. | 2019-06-25 |
25. +------------+
26. 3 rows in set (0.00 sec)

28. drop table if exists t;
29. CREATE TABLE t (i1 INT, d1 DOUBLE, e2 DECIMAL(5,2));
30. INSERT INTO t VALUES ( 6, 6.0, 10.0/3), ( null, 9.0, 10.0/3), ( 1, null, 10.0/3), ( 2, 2.0, null );

32. mysql> select * from t;
33. +------+------+------+
34. | i1   | d1   | e2   |
35. +------+------+------+
36. |    6 |    6 | 3.33 |
37. | NULL |    9 | 3.33 |
38. |    1 | NULL | 3.33 |
39. |    2 |    2 | NULL |
40. +------+------+------+
41. 4 rows in set (0.01 sec)