MySQL_5.sql 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. =========================================================================================
  3. MySQL_5.sql
  4. Author: Amit Biswas ([email protected])
  5. This sql script performs the same operations as "mysql.sql" but some sql commands
  6. have been changed either to fix bugs or to comply with MySQL Server 5.0
  7. 15-Dec-2007
  8. Changes:
  9. --------
  10. In numeric_family, the column type_tinyint cannot store the value 255, hence changed it to 127
  11. Reason: tinyint takes 1 byte and stores from -128 to 127 (http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html)
  12. (ERROR: Out of range value adjusted for column 'type_tinyint')
  13. In numeric_family, the column type_double was declared as float NULL which cannot store the value 1.79E+308, hence it changed it to float (53)
  14. Reason: MySQL supports the optional precision specification but the precision value is used only
  15. to determine storage size. A precision from 0 to 23 results in a four-byte single-precision FLOAT column.
  16. A precision from 24 to 53 results in an eight-byte double-precision DOUBLE column.
  17. (http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html)
  18. In binary_family, the column type_binary was declared as binary NULL which cannot store the value 555555, hence changed it to binary (8)
  19. Reason: In case of binary (and varbinary) fields the length indicates bytes, not characters. (http://dev.mysql.com/doc/refman/5.0/en/binary-varbinary.html)
  20. (ERROR: Data too long for column 'type_binary')
  21. In datetime_family, the column type_smalldatetime was declared as timestamp NULL which cannot store the year 2079, hence changed it to 2037-12-31 23:59:00
  22. Reason: The range of timestamp is '1970-01-01 00:00:01' to 2037, (http://dev.mysql.com/doc/refman/5.0/en/date-and-time-type-overview.html)
  23. (ERROR: Incorrect datetime value: '2079-06-06 23:59:00' for column 'type_smalldatetime')
  24. Stored Procedures:
  25. ------------------
  26. Modified the "Create Procedure" statement
  27. Reason: the existing statement doesnt work in MySQL Administrator, MySQL 5.0.27
  28. Removed the "Return" statement in the stored procedure sp_get_age
  29. Reason: "Return" is only allowed in a function not in a procedure, u can use "INTO" instead
  30. ===========================================================================================
  31. */
  32. use monotest;
  33. /*
  34. =================================== OBJECT NUMERIC_FAMILY =========================
  35. -- TABLE : NUMERIC_FAMILY
  36. -- data with id > 6000 is not gaurenteed to be read-only.
  37. */
  38. drop table if exists numeric_family;
  39. create table `numeric_family` (
  40. `id` int PRIMARY KEY NOT NULL,
  41. `type_bit` bit NULL,
  42. `type_tinyint` tinyint NULL,
  43. `type_smallint` smallint NULL,
  44. `type_int` int NULL,
  45. `type_bigint` bigint NULL,
  46. `type_decimal` decimal (38, 0) NULL,
  47. `type_numeric` numeric (38, 0) NULL,
  48. `type_money` numeric (38,0) NULL,
  49. `type_smallmoney` numeric (12,0) NULL,
  50. `type_float` real NULL,
  51. `type_double` float (53));
  52. insert into `numeric_family` values (1,1,127,32767,2147483647,9223372036854775807,1000,1000,922337203685477.5807,214748.3647,3.40E+38,1.79E+308);
  53. insert into `numeric_family` values (2,0,0,-32768,-2147483648,-9223372036854775808,-1000,-1000,-922337203685477.5808,-214748.3648,-3.40E+38,-1.79E+308);
  54. insert into `numeric_family` values (3,0,0,0,0,0,0,0,0,0,0,0);
  55. insert into `numeric_family` values (4,null,null,null,null,null,null,null,null,null,null,null);
  56. /*
  57. -- =================================== END OBJECT NUMERIC_FAMILY ========================
  58. -- =================================== OBJECT BINARY_FAMILY =========================
  59. -- TABLE : BINARY_FAMILY
  60. -- data with id > 6000 is not gaurenteed to be read-only.
  61. */
  62. drop table if exists binary_family;
  63. create table `binary_family` (
  64. `id` int PRIMARY KEY NOT NULL,
  65. `type_binary` binary (8),
  66. `type_varbinary` varbinary (255) NULL,
  67. `type_blob` blob NULL,
  68. `type_tinyblob` tinyblob NULL,
  69. `type_mediumblob` mediumblob NULL,
  70. `type_longblob_image` longblob NULL);
  71. insert into `binary_family` values (1, '555555', '0123456789012345678901234567890123456789012345678901234567890123456789', '66666666', '777777', '888888', '999999');
  72. /* --insert into binary_family values (2,
  73. --insert into binary_family values (3,
  74. */
  75. insert into `binary_family` values (4,null,null,null,null,null,null);
  76. /*
  77. -- =================================== END OBJECT BINARY_FAMILY ========================
  78. -- =================================== OBJECT STRING_FAMILY============================
  79. -- TABLE : string_family
  80. -- data with id above 6000 is not gaurenteed to be read-only.
  81. */
  82. drop table if exists string_family;
  83. create table `string_family` (
  84. `id` int PRIMARY KEY NOT NULL,
  85. `type_char` char(10) NULL,
  86. `type_varchar` varchar(10) NULL,
  87. `type_text` text NULL,
  88. `type_ntext` longtext NULL);
  89. grant all privileges on string_family to monotester;
  90. insert into `string_family` values (1,"char","varchar","text","ntext");
  91. insert into `string_family` values (2, '0123456789','varchar' ,'longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext longtext ','ntext');
  92. insert into `string_family` values (4,null,null,null,null);
  93. /*
  94. -- =================================== END OBJECT STRING_FAMILY ========================
  95. -- =================================== OBJECT DATETIME_FAMILY============================
  96. -- TABLE : datetime_family
  97. -- data with id above 6000 is not gaurenteed to be read-only.
  98. */
  99. drop table if exists datetime_family;
  100. create table `datetime_family` (
  101. `id` int PRIMARY KEY NOT NULL,
  102. `type_smalldatetime` timestamp NULL,
  103. `type_datetime` datetime NULL);
  104. grant all privileges on datetime_family to monotester;
  105. insert into `datetime_family` values (1,'2037-12-31 23:59:00','9999-12-31 23:59:59.997');
  106. insert into `datetime_family` values (4,null,null);
  107. /*
  108. -- =================================== END OBJECT DATETIME_FAMILY========================
  109. -- =================================== OBJECT EMPLOYEE ============================
  110. -- TABLE : EMPLOYEE
  111. -- data with id above 6000 is not gaurenteed to be read-only.
  112. */
  113. drop table if exists employee;
  114. create table `employee` (
  115. `id` int PRIMARY KEY NOT NULL,
  116. `fname` varchar (50) NOT NULL,
  117. `lname` varchar (50),
  118. `dob` datetime NOT NULL,
  119. `doj` datetime NOT NULL,
  120. `email` varchar (50));
  121. grant all privileges on employee to monotester;
  122. insert into `employee` values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', '[email protected]');
  123. insert into `employee` values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', '[email protected]');
  124. insert into `employee` values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', '[email protected]');
  125. insert into `employee` values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', '[email protected]');
  126. /*
  127. -- STORED PROCEDURES
  128. -- SP : sp_clean_person_table
  129. */
  130. delimiter //
  131. drop procedure if exists sp_clean_employee_table
  132. //
  133. CREATE DEFINER=`monotester`@`localhost` PROCEDURE `sp_clean_employee_table`()
  134. begin
  135. delete from employee where `id` > 6000;
  136. end
  137. //
  138. /*
  139. -- SP : sp_get_age
  140. */
  141. drop procedure if exists sp_get_age
  142. //
  143. create procedure sp_get_age (fname varchar (50), OUT age int)
  144. begin
  145. select age = datediff (day, dob, getdate ()) from employee where fname like fname;
  146. /* you can also use SELECT ..... INTO age */
  147. end
  148. //
  149. /*
  150. -- =================================== END OBJECT EMPLOYEE ============================
  151. */