MySQL_5.sql 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 unsigned attribute was added to column type_tinyint to allow it to store the value 255,
  11. Reason: tinyint is normally signed and stores from -128 to 127 (http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html)
  12. 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)
  13. Reason: MySQL supports the optional precision specification but the precision value is used only
  14. to determine storage size. A precision from 0 to 23 results in a four-byte single-precision FLOAT column.
  15. A precision from 24 to 53 results in an eight-byte double-precision DOUBLE column.
  16. (http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html)
  17. In binary_family, the column type_binary was declared as binary NULL which cannot store the value 555555, hence changed it to binary (8)
  18. 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)
  19. (ERROR: Data too long for column 'type_binary')
  20. 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
  21. 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)
  22. (ERROR: Incorrect datetime value: '2079-06-06 23:59:00' for column 'type_smalldatetime')
  23. Stored Procedures:
  24. ------------------
  25. Modified the "Create Procedure" statement
  26. Reason: the existing statement doesnt work in MySQL Administrator, MySQL 5.0.27
  27. Removed the "Return" statement in the stored procedure sp_get_age
  28. Reason: "Return" is only allowed in a function not in a procedure, u can use "INTO" instead
  29. ===========================================================================================
  30. */
  31. use monotest;
  32. /*
  33. =================================== OBJECT NUMERIC_FAMILY =========================
  34. -- TABLE : NUMERIC_FAMILY
  35. -- data with id > 6000 is not gaurenteed to be read-only.
  36. */
  37. drop table if exists numeric_family;
  38. create table `numeric_family` (
  39. `id` int NOT NULL,
  40. `type_bit` bit NULL,
  41. `type_tinyint` tinyint unsigned NULL,
  42. `type_smallint` smallint NULL,
  43. `type_int` int NULL,
  44. `type_bigint` bigint NULL,
  45. `type_decimal1` decimal (38, 0) NULL,
  46. `type_decimal2` decimal (10, 3) NULL,
  47. `type_numeric1` numeric (38, 0) NULL,
  48. `type_numeric2` numeric (10, 3) NULL,
  49. `type_money` numeric (38,0) NULL,
  50. `type_smallmoney` numeric (12,0) NULL,
  51. `type_float` float(24) NULL,
  52. `type_double` float (53) NULL,
  53. `type_autoincrement` int PRIMARY KEY AUTO_INCREMENT NOT NULL);
  54. insert into numeric_family (id, type_bit, type_tinyint, type_smallint, type_int, type_bigint, type_decimal1, type_decimal2, type_numeric1, type_numeric2, type_money, type_smallmoney, type_float, type_double)
  55. values (1, 1, 255, 32767, 2147483647, 9223372036854775807, 1000, 4456.432, 1000, 4456.432, 922337203685477.5807, 214748.3647, 3.40E+38, 1.79E+308);
  56. insert into numeric_family (id, type_bit, type_tinyint, type_smallint, type_int, type_bigint, type_decimal1, type_decimal2, type_numeric1, type_numeric2, type_money, type_smallmoney, type_float, type_double)
  57. values (2, 0, 0, -32768, -2147483648, -9223372036854775808, -1000, -4456.432, -1000, -4456.432, -922337203685477.5808, -214748.3648, -3.40E+38, -1.79E+308);
  58. insert into numeric_family (id, type_bit, type_tinyint, type_smallint, type_int, type_bigint, type_decimal1, type_decimal2, type_numeric1, type_numeric2, type_money, type_smallmoney, type_float, type_double)
  59. values (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  60. insert into numeric_family (id, type_bit, type_tinyint, type_smallint, type_int, type_bigint, type_decimal1, type_decimal2, type_numeric1, type_numeric2, type_money, type_smallmoney, type_float, type_double)
  61. values (4, null, null, null, null, null, null, null, null, null, null, null, null, null);
  62. /*
  63. -- =================================== END OBJECT NUMERIC_FAMILY ========================
  64. -- =================================== OBJECT BINARY_FAMILY =========================
  65. -- TABLE : BINARY_FAMILY
  66. -- data with id > 6000 is not gaurenteed to be read-only.
  67. */
  68. drop table if exists binary_family;
  69. create table `binary_family` (
  70. `id` int PRIMARY KEY NOT NULL,
  71. `type_binary` binary (8),
  72. `type_varbinary` varbinary (255) NULL,
  73. `type_blob` blob NULL,
  74. `type_tinyblob` tinyblob NULL,
  75. `type_mediumblob` mediumblob NULL,
  76. `type_longblob_image` longblob NULL);
  77. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  78. 1,
  79. '5',
  80. 0x303132333435363738393031323334353637383930313233343536373839004453,
  81. 0x3256004422,
  82. 0x3A56004422,
  83. 0x2B87002233,
  84. 0x4D84002332
  85. );
  86. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  87. 2,
  88. 0x0033340033303531,
  89. 0x003938373635003332313031323334,
  90. 0x0066066697006606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066698,
  91. 0x0056334422,
  92. 0x0087342233,
  93. 0x0084352332
  94. );
  95. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  96. 3,
  97. '',
  98. '',
  99. '',
  100. '',
  101. '',
  102. ''
  103. );
  104. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  105. 4,null,null,null,null,null,null);
  106. /*
  107. -- =================================== END OBJECT BINARY_FAMILY ========================
  108. -- =================================== OBJECT STRING_FAMILY============================
  109. -- TABLE : string_family
  110. -- data with id above 6000 is not gaurenteed to be read-only.
  111. */
  112. drop table if exists string_family;
  113. create table `string_family` (
  114. `id` int PRIMARY KEY NOT NULL,
  115. `type_char` char(10) NULL,
  116. `type_nchar` char(10) CHARACTER SET ucs2 COLLATE ucs2_general_ci NULL,
  117. `type_varchar` varchar(10) NULL,
  118. `type_nvarchar` varchar(10) CHARACTER SET ucs2 COLLATE ucs2_general_ci NULL,
  119. `type_text` text NULL,
  120. `type_ntext` longtext CHARACTER SET ucs2 COLLATE ucs2_general_ci NULL);
  121. grant all privileges on string_family to monotester;
  122. insert into string_family values (1, 'char', 'nchभाr', 'varchar', 'nvभारतr', 'text', 'ntभाxt');
  123. insert into string_family values (2, '0123456789', '0123456789', 'varchar ', 'nvभारतr ', '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 ', 'ntभाxt ');
  124. insert into string_family values (3, '', '', '', '', '', '');
  125. insert into string_family values (4, null, null, null, null, null, null);
  126. /*
  127. -- =================================== END OBJECT STRING_FAMILY ========================
  128. -- =================================== OBJECT DATETIME_FAMILY============================
  129. -- TABLE : datetime_family
  130. -- data with id above 6000 is not gaurenteed to be read-only.
  131. */
  132. drop table if exists datetime_family;
  133. create table `datetime_family` (
  134. `id` int PRIMARY KEY NOT NULL,
  135. `type_smalldatetime` timestamp NULL,
  136. `type_datetime` datetime NULL,
  137. `type_time` time NULL,
  138. `type_date` date NULL);
  139. grant all privileges on datetime_family to monotester;
  140. insert into `datetime_family` values (1,'2037-12-31 23:59:00','9999-12-31 23:59:59.997','23:58:59.953','9999-12-31');
  141. insert into `datetime_family` values (4,null,null,null,null);
  142. /*
  143. -- =================================== END OBJECT DATETIME_FAMILY========================
  144. -- =================================== OBJECT EMPLOYEE ============================
  145. -- TABLE : EMPLOYEE
  146. -- data with id above 6000 is not gaurenteed to be read-only.
  147. */
  148. drop table if exists employee;
  149. create table `employee` (
  150. `id` int PRIMARY KEY NOT NULL,
  151. `fname` varchar (50) NOT NULL,
  152. `lname` varchar (50),
  153. `dob` datetime NOT NULL,
  154. `doj` datetime NOT NULL,
  155. `email` varchar (50));
  156. grant all privileges on employee to monotester;
  157. insert into `employee` values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', '[email protected]');
  158. insert into `employee` values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', '[email protected]');
  159. insert into `employee` values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', '[email protected]');
  160. insert into `employee` values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', '[email protected]');
  161. /*
  162. -- STORED PROCEDURES
  163. -- SP : sp_clean_person_table
  164. */
  165. delimiter //
  166. drop procedure if exists sp_clean_employee_table
  167. //
  168. CREATE DEFINER=`monotester`@`localhost` PROCEDURE `sp_clean_employee_table`()
  169. begin
  170. delete from employee where `id` > 6000;
  171. end
  172. //
  173. /*
  174. -- SP : sp_get_age
  175. */
  176. drop procedure if exists sp_get_age
  177. //
  178. create procedure sp_get_age (fname varchar (50), OUT age int)
  179. begin
  180. select age=datediff (`dob`, now()) from `employee` where `fname` like fname;
  181. end
  182. //
  183. /*
  184. -- =================================== END OBJECT EMPLOYEE ============================
  185. */