MySQL_5.sql 7.3 KB

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