You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.3 KiB

26 years ago
  1. --------------
  2. drop table if exists auto_incr_test,auto_incr_test2
  3. --------------
  4. Query OK, 0 rows affected
  5. --------------
  6. create table auto_incr_test (id int not null auto_increment, name char(40), timestamp timestamp, primary key (id))
  7. --------------
  8. Query OK, 0 rows affected
  9. --------------
  10. insert into auto_incr_test (name) values ("first record")
  11. --------------
  12. Query OK, 1 row affected
  13. --------------
  14. insert into auto_incr_test values (last_insert_id()+1,"second record",null)
  15. --------------
  16. Query OK, 1 row affected
  17. --------------
  18. insert into auto_incr_test (id,name) values (10,"tenth record")
  19. --------------
  20. Query OK, 1 row affected
  21. --------------
  22. insert into auto_incr_test values (0,"eleventh record",null)
  23. --------------
  24. Query OK, 1 row affected
  25. --------------
  26. insert into auto_incr_test values (last_insert_id()+1,"12","1997-01-01")
  27. --------------
  28. Query OK, 1 row affected
  29. --------------
  30. insert into auto_incr_test values (12,"this will not work",NULL)
  31. --------------
  32. ERROR 1062 at line 15: Duplicate entry '12' for key 1
  33. --------------
  34. replace into auto_incr_test values (12,"twelfth record",NULL)
  35. --------------
  36. Query OK, 2 rows affected
  37. --------------
  38. select * from auto_incr_test
  39. --------------
  40. id name timestamp
  41. 1 first record 19980817042654
  42. 2 second record 19980817042655
  43. 10 tenth record 19980817042655
  44. 11 eleventh record 19980817042655
  45. 12 twelfth record 19980817042655
  46. 5 rows in set
  47. --------------
  48. create table auto_incr_test2 (id int not null auto_increment, name char(40), primary key (id))
  49. --------------
  50. Query OK, 0 rows affected
  51. --------------
  52. insert into auto_incr_test2 select NULL,name from auto_incr_test
  53. --------------
  54. Query OK, 5 rows affected
  55. Records: 5 Duplicates: 0 Warnings: 0
  56. --------------
  57. insert into auto_incr_test2 select id,name from auto_incr_test
  58. --------------
  59. Query OK, 3 rows affected
  60. Records: 5 Duplicates: 2 Warnings: 0
  61. --------------
  62. replace into auto_incr_test2 select id,name from auto_incr_test
  63. --------------
  64. Query OK, 5 rows affected
  65. Records: 5 Duplicates: 5 Warnings: 0
  66. --------------
  67. select * from auto_incr_test2
  68. --------------
  69. id name
  70. 1 first record
  71. 2 second record
  72. 3 tenth record
  73. 4 eleventh record
  74. 5 twelfth record
  75. 10 tenth record
  76. 11 eleventh record
  77. 12 twelfth record
  78. 8 rows in set
  79. --------------
  80. drop table auto_incr_test,auto_incr_test2
  81. --------------
  82. Query OK, 0 rows affected
  83. Bye