truncate.test
Upload User: romrleung
Upload Date: 2022-05-23
Package Size: 18897k
Code Size: 1k
Category:

MySQL

Development Platform:

Visual C++

  1. #
  2. # Test of truncate
  3. #
  4. --disable_warnings
  5. drop table if exists t1;
  6. --enable_warnings
  7. create table t1 (a integer, b integer,c1 CHAR(10));
  8. insert into t1 (a) values (1),(2);
  9. truncate table t1;
  10. select count(*) from t1;
  11. insert into t1 values(1,2,"test");
  12. select count(*) from t1;
  13. delete from t1;
  14. select * from t1;
  15. drop table t1;
  16. # The following should fail
  17. --error 1146
  18. select count(*) from t1;
  19. create temporary table t1 (n int);
  20. insert into t1 values (1),(2),(3);
  21. truncate table t1;
  22. select * from t1;
  23. drop table t1;
  24. --error 1146
  25. truncate non_existing_table;
  26. #
  27. # test autoincrement with TRUNCATE; verifying difference with DELETE
  28. #
  29. create table t1 (a integer auto_increment primary key);
  30. insert into t1 (a) values (NULL),(NULL);
  31. truncate table t1;
  32. insert into t1 (a) values (NULL),(NULL);
  33. SELECT * from t1;
  34. delete from t1;
  35. insert into t1 (a) values (NULL),(NULL);
  36. SELECT * from t1;
  37. drop table t1;
  38. # Verifying that temp tables are handled the same way
  39. create temporary table t1 (a integer auto_increment primary key);
  40. insert into t1 (a) values (NULL),(NULL);
  41. truncate table t1;
  42. insert into t1 (a) values (NULL),(NULL);
  43. SELECT * from t1;
  44. delete from t1;
  45. insert into t1 (a) values (NULL),(NULL);
  46. SELECT * from t1;
  47. drop table t1;
  48. # End of 4.1 tests