home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / sharewar / mysql / data1.cab / Development / examples / tests / auto_increment.res next >
Encoding:
Text File  |  2001-11-02  |  2.3 KB  |  115 lines

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