Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2014
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. CREATE TABLE `test` (
  2. `cnt` int(11) NOT NULL AUTO_INCREMENT,
  3. `a` int(11) DEFAULT NULL,
  4. `b` int(11) DEFAULT NULL,
  5. PRIMARY KEY (`cnt`)
  6. )
  7.  
  8. CREATE TABLE `test_current` (
  9. `a` int(11) DEFAULT NULL,
  10. `b` int(11) DEFAULT NULL
  11. )
  12.  
  13. mysql> insert into test_current (a,b) values (1,1),(2,2);
  14. Query OK, 2 rows affected (0.00 sec)
  15. Records: 2 Duplicates: 0 Warnings: 0
  16.  
  17. mysql> INSERT INTO test (a,b) SELECT a,b FROM test_current;
  18. Query OK, 2 rows affected, 1 warning (0.00 sec)
  19. Records: 2 Duplicates: 0 Warnings: 1
  20.  
  21. mysql> select * from test;
  22. +-----+------+------+
  23. | cnt | a | b |
  24. +-----+------+------+
  25. | 1 | 1 | 1 |
  26. | 2 | 2 | 2 |
  27. +-----+------+------+
  28. 2 rows in set (0.00 sec)
  29.  
  30. mysql> INSERT INTO test (a,b) SELECT a,b FROM test_current;
  31. Query OK, 2 rows affected, 1 warning (0.00 sec)
  32. Records: 2 Duplicates: 0 Warnings: 1
  33.  
  34. mysql> select * from test;
  35. +-----+------+------+
  36. | cnt | a | b |
  37. +-----+------+------+
  38. | 1 | 1 | 1 |
  39. | 2 | 2 | 2 |
  40. | 4 | 1 | 1 |
  41. | 5 | 2 | 2 |
  42. +-----+------+------+
  43.  
  44. ALTER TABLE `test` AUTO_INCREMENT = 1;
  45. INSERT INTO test (a,b) SELECT a,b FROM test_current;
  46.  
  47. innodb_autoinc_lock_mode=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement