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);
  4. mysql> select * from t1;
  5. +------+------+
  6. | a | b |
  7. +------+------+
  8. | 13 | 1 |
  9. | 13 | 1 |
  10. +------+------+
  11. 2 rows in set (0.01 sec)
  12. drop table if exists t1;
  13. create table t1 (a date);
  14. 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"));
  15. mysql> select * from t1;
  16. +------------+
  17. | a |
  18. +------------+
  19. | 2017-06-15 |
  20. | 2019-06-25 |
  21. | 2019-06-25 |
  22. +------------+
  23. 3 rows in set (0.00 sec)
  24. drop table if exists t;
  25. CREATE TABLE t (i1 INT, d1 DOUBLE, e2 DECIMAL(5,2));
  26. 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 );
  27. mysql> select * from t;
  28. +------+------+------+
  29. | i1 | d1 | e2 |
  30. +------+------+------+
  31. | 6 | 6 | 3.33 |
  32. | NULL | 9 | 3.33 |
  33. | 1 | NULL | 3.33 |
  34. | 2 | 2 | NULL |
  35. +------+------+------+
  36. 4 rows in set (0.01 sec)