MySQL_5.sql 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. /*
  32. =================================== OBJECT NUMERIC_FAMILY =========================
  33. -- TABLE : NUMERIC_FAMILY
  34. -- data with id > 6000 is not gaurenteed to be read-only.
  35. */
  36. drop table if exists numeric_family;
  37. create table `numeric_family` (
  38. `id` int NOT NULL,
  39. `type_bit` bit NULL,
  40. `type_tinyint` tinyint unsigned NULL,
  41. `type_smallint` smallint NULL,
  42. `type_int` int NULL,
  43. `type_bigint` bigint NULL,
  44. `type_decimal1` decimal (38, 0) NULL,
  45. `type_decimal2` decimal (10, 3) NULL,
  46. `type_numeric1` numeric (38, 0) NULL,
  47. `type_numeric2` numeric (10, 3) NULL,
  48. `type_money` numeric (38,0) NULL,
  49. `type_smallmoney` numeric (12,0) NULL,
  50. `type_float` float(24) NULL,
  51. `type_double` float (53) NULL,
  52. `type_autoincrement` int PRIMARY KEY AUTO_INCREMENT NOT NULL);
  53. 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)
  54. values (1, 1, 255, 32767, 2147483647, 9223372036854775807, 1000, 4456.432, 1000, 4456.432, 922337203685477.5807, 214748.3647, 3.40E+38, 1.79E+308);
  55. 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)
  56. values (2, 0, 0, -32768, -2147483648, -9223372036854775808, -1000, -4456.432, -1000, -4456.432, -922337203685477.5808, -214748.3648, -3.40E+38, -1.79E+308);
  57. 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)
  58. values (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  59. 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)
  60. values (4, null, null, null, null, null, null, null, null, null, null, null, null, null);
  61. /*
  62. -- =================================== END OBJECT NUMERIC_FAMILY ========================
  63. -- =================================== OBJECT BINARY_FAMILY =========================
  64. -- TABLE : BINARY_FAMILY
  65. -- data with id > 6000 is not gaurenteed to be read-only.
  66. */
  67. drop table if exists binary_family;
  68. create table `binary_family` (
  69. `id` int PRIMARY KEY NOT NULL,
  70. `type_binary` binary (8),
  71. `type_varbinary` varbinary (255) NULL,
  72. `type_blob` blob NULL,
  73. `type_tinyblob` tinyblob NULL,
  74. `type_mediumblob` mediumblob NULL,
  75. `type_longblob_image` longblob NULL);
  76. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  77. 1,
  78. '5',
  79. 0x303132333435363738393031323334353637383930313233343536373839004453,
  80. 0x3256004422,
  81. 0x3A56004422,
  82. 0x2B87002233,
  83. 0x4D84002332
  84. );
  85. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  86. 2,
  87. 0x0033340033303531,
  88. 0x003938373635003332313031323334,
  89. 0x0066066697006606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066698,
  90. 0x0056334422,
  91. 0x0087342233,
  92. 0x0084352332
  93. );
  94. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  95. 3,
  96. '',
  97. '',
  98. '',
  99. '',
  100. '',
  101. ''
  102. );
  103. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  104. 4,null,null,null,null,null,null);
  105. /*
  106. -- =================================== END OBJECT BINARY_FAMILY ========================
  107. -- =================================== OBJECT STRING_FAMILY============================
  108. -- TABLE : string_family
  109. -- data with id above 6000 is not gaurenteed to be read-only.
  110. */
  111. drop table if exists string_family;
  112. create table `string_family` (
  113. `id` int PRIMARY KEY NOT NULL,
  114. `type_char` char(10) NULL,
  115. `type_nchar` char(10) CHARACTER SET ucs2 COLLATE ucs2_general_ci NULL,
  116. `type_varchar` varchar(10) NULL,
  117. `type_nvarchar` varchar(10) CHARACTER SET ucs2 COLLATE ucs2_general_ci NULL,
  118. `type_text` text NULL,
  119. `type_ntext` longtext CHARACTER SET ucs2 COLLATE ucs2_general_ci NULL);
  120. insert into string_family values (1, 'char', 'nchभाr', 'varchar', 'nvभारतr', 'text', 'ntभाxt');
  121. 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 ');
  122. insert into string_family values (3, '', '', '', '', '', '');
  123. insert into string_family values (4, null, null, null, null, null, null);
  124. /*
  125. -- =================================== END OBJECT STRING_FAMILY ========================
  126. -- =================================== OBJECT DATETIME_FAMILY============================
  127. -- TABLE : datetime_family
  128. -- data with id above 6000 is not gaurenteed to be read-only.
  129. */
  130. drop table if exists datetime_family;
  131. create table `datetime_family` (
  132. `id` int PRIMARY KEY NOT NULL,
  133. `type_smalldatetime` timestamp NULL,
  134. `type_datetime` datetime NULL,
  135. `type_time` time NULL,
  136. `type_date` date NULL);
  137. insert into `datetime_family` values (1,'2037-12-31 23:59:00','9999-12-31 23:59:59','23:58:59','9999-12-31');
  138. insert into `datetime_family` values (4,null,null,null,null);
  139. /*
  140. -- =================================== END OBJECT DATETIME_FAMILY========================
  141. -- =================================== OBJECT EMPLOYEE ============================
  142. -- TABLE : EMPLOYEE
  143. -- data with id above 6000 is not gaurenteed to be read-only.
  144. */
  145. drop table if exists employee;
  146. create table `employee` (
  147. `id` int PRIMARY KEY NOT NULL,
  148. `fname` varchar (50) NOT NULL,
  149. `lname` varchar (50),
  150. `dob` datetime NOT NULL,
  151. `doj` datetime NOT NULL,
  152. `email` varchar (50));
  153. insert into `employee` values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', '[email protected]');
  154. insert into `employee` values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', '[email protected]');
  155. insert into `employee` values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', '[email protected]');
  156. insert into `employee` values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', '[email protected]');
  157. /*
  158. -- STORED PROCEDURES
  159. -- SP : sp_clean_person_table
  160. */
  161. delimiter //
  162. drop procedure if exists sp_clean_employee_table
  163. //
  164. CREATE PROCEDURE `sp_clean_employee_table`()
  165. begin
  166. delete from employee where `id` > 6000;
  167. end
  168. //
  169. /*
  170. -- SP : sp_get_age
  171. */
  172. drop procedure if exists sp_get_age
  173. //
  174. create procedure sp_get_age (fname varchar (50), OUT age int)
  175. begin
  176. select age=datediff (`dob`, now()) from `employee` where `fname` like fname;
  177. end
  178. //
  179. /*
  180. -- =================================== END OBJECT EMPLOYEE ============================
  181. */