sqlserver.sql 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. -- =================================== OBJECT NUMERIC_FAMILY============================
  2. -- TABLE : NUMERIC_FAMILY
  3. -- data with id > 6000 is not gaurenteed to be read-only.
  4. if exists (select name from sysobjects where
  5. name = 'numeric_family' and type = 'U')
  6. drop table numeric_family;
  7. go
  8. create table numeric_family (
  9. id int PRIMARY KEY NOT NULL,
  10. type_bit bit NULL,
  11. type_tinyint tinyint NULL,
  12. type_smallint smallint NULL,
  13. type_int int NULL,
  14. type_bigint bigint NULL,
  15. type_decimal1 decimal(38,0) NULL,
  16. type_decimal2 decimal(10,3) NULL,
  17. type_numeric1 numeric(38,0) NULL,
  18. type_numeric2 numeric(10,3) NULL,
  19. type_money money NULL,
  20. type_smallmoney smallmoney NULL,
  21. type_float real NULL,
  22. type_double float NULL,
  23. type_autoincrement int identity (2, 3));
  24. go
  25. 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)
  26. values (1, 1, 255, 32767, 2147483647, 9223372036854775807, 1000, 4456.432, 1000, 4456.432, 922337203685477.5807, 214748.3647, 3.40E+38, 1.79E+308);
  27. 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)
  28. values (2, 0, 0, -32768, -2147483648, -9223372036854775808, -1000, -4456.432, -1000, -4456.432, -922337203685477.5808, -214748.3648, -3.40E+38, -1.79E+308);
  29. 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)
  30. values (3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  31. 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)
  32. values (4, null, null, null, null, null, null, null, null, null, null, null, null, null);
  33. go
  34. -- =================================== END OBJECT NUMERIC_FAMILY ========================
  35. -- =================================== OBJECT BINARY_FAMILY =========================
  36. -- TABLE : BINARY_FAMILY
  37. -- data with id > 6000 is not gaurenteed to be read-only.
  38. if exists (select name from sysobjects where
  39. name = 'binary_family' and type = 'U')
  40. drop table binary_family;
  41. go
  42. create table binary_family (
  43. id int PRIMARY KEY NOT NULL,
  44. type_binary binary (8) NULL,
  45. type_varbinary varbinary (255) NULL,
  46. type_blob image NULL,
  47. type_tinyblob image NULL,
  48. type_mediumblob image NULL,
  49. type_longblob_image image NULL,
  50. type_timestamp timestamp NULL);
  51. go
  52. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  53. 1,
  54. convert (binary, '5'),
  55. convert (varbinary(255), 0x303132333435363738393031323334353637383930313233343536373839004453),
  56. convert (image, 0x3256004422),
  57. convert (image, 0x3A56004422),
  58. convert (image, 0x2B87002233),
  59. convert (image, 0x4D84002332)
  60. );
  61. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  62. 2,
  63. convert (binary, 0x0033340033303531),
  64. convert (varbinary, 0x003938373635003332313031323334),
  65. convert (image, 0x0066066697006606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066697066606669706660666970666066698),
  66. convert (image, 0x0056334422),
  67. convert (image, 0x0087342233),
  68. convert (image, 0x0084352332)
  69. );
  70. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  71. 3,
  72. convert (binary, ''),
  73. convert (varbinary, ''),
  74. convert (image, ''),
  75. convert (image, ''),
  76. convert (image, ''),
  77. convert (image, '')
  78. );
  79. insert into binary_family (id, type_binary, type_varbinary, type_blob, type_tinyblob, type_mediumblob, type_longblob_image) values (
  80. 4,null,null,null,null,null,null);
  81. go
  82. -- =================================== END OBJECT BINARY_FAMILY ========================
  83. -- =================================== OBJECT STRING_FAMILY============================
  84. -- TABLE : string_family
  85. -- data with id above 6000 is not gaurenteed to be read-only.
  86. if exists (select name from sysobjects where
  87. name = 'string_family' and type = 'U')
  88. drop table string_family;
  89. go
  90. create table string_family (
  91. id int PRIMARY KEY NOT NULL,
  92. type_guid uniqueidentifier NULL,
  93. type_char char(10) NULL,
  94. type_nchar nchar(10) NULL,
  95. type_varchar varchar(10) NULL,
  96. type_nvarchar nvarchar(10) NULL,
  97. type_text text NULL,
  98. type_ntext ntext NULL);
  99. go
  100. insert into string_family values (1, 'd222a130-6383-4d36-ac5e-4e6b2591aabf', 'char', N'nchभाr', 'varchar', N'nvभारतr', 'text', N'ntभाxt');
  101. insert into string_family values (2, '1c47dd1d-891b-47e8-aac8-f36608b31bc5', '0123456789', '0123456789', 'varchar ', N'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 ', N'ntभाxt ');
  102. insert into string_family values (3, '3c47dd1d-891b-47e8-aac8-f36608b31bc5', '', '', '', '', '', '');
  103. insert into string_family values (4, null, null, null, null, null, null, null);
  104. go
  105. -- =================================== END OBJECT STRING_FAMILY ========================
  106. -- =================================== OBJECT DATETIME_FAMILY============================
  107. -- TABLE : datetime_family
  108. -- data with id above 6000 is not gaurenteed to be read-only.
  109. if exists (select name from sysobjects where
  110. name = 'datetime_family' and type = 'U')
  111. drop table datetime_family;
  112. go
  113. create table datetime_family (
  114. id int PRIMARY KEY NOT NULL,
  115. type_smalldatetime smalldatetime NULL,
  116. type_datetime datetime NULL);
  117. go
  118. insert into datetime_family values (1,'2037-12-31 23:59:00','9999-12-31 23:59:59:997');
  119. insert into datetime_family values (4,null,null);
  120. go
  121. -- =================================== END OBJECT DATETIME_FAMILY========================
  122. -- =================================== OBJECT EMPLOYEE ============================
  123. -- TABLE : EMPLOYEE
  124. -- data with id above 6000 is not gaurenteed to be read-only.
  125. if exists (select name from sysobjects where
  126. name = 'employee' and type = 'U')
  127. drop table employee;
  128. go
  129. create table employee (
  130. id int PRIMARY KEY NOT NULL,
  131. fname varchar (50) NOT NULL,
  132. lname varchar (50) NULL,
  133. dob datetime NOT NULL,
  134. doj datetime NOT NULL,
  135. email varchar (50) NULL);
  136. go
  137. insert into employee values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', '[email protected]');
  138. insert into employee values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', '[email protected]');
  139. insert into employee values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', '[email protected]');
  140. insert into employee values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', '[email protected]');
  141. go
  142. -- STORED PROCEDURES
  143. -- SP : sp_clean_employee_table
  144. if exists (select name from sysobjects where
  145. name = 'sp_clean_employee_table' and type = 'P')
  146. drop procedure sp_clean_employee_table;
  147. go
  148. create procedure sp_clean_employee_table
  149. as
  150. begin
  151. delete from employee where id > 6000;
  152. end
  153. go
  154. -- SP : sp_get_age
  155. if exists (select name from sysobjects where
  156. name = 'sp_get_age' and type = 'P')
  157. drop procedure sp_get_age;
  158. go
  159. create procedure sp_get_age (
  160. @fname varchar (50),
  161. @age int output)
  162. as
  163. begin
  164. select @age = datediff (day, dob, getdate ()) from employee where fname like @fname;
  165. return @age;
  166. end
  167. go
  168. -- =================================== END OBJECT EMPLOYEE ============================
  169. -- SP : sp_326182a
  170. if exists (select name from sysobjects where
  171. name = 'sp_326182a' and type = 'P')
  172. drop procedure sp_326182a;
  173. go
  174. CREATE procedure sp_326182a (
  175. @param0 int out,
  176. @param1 int out,
  177. @param2 int out,
  178. @param3 int out)
  179. as
  180. begin
  181. set @param0 = 100
  182. set @param1 = 101
  183. set @param2 = 102
  184. set @param3 = 103
  185. return 2
  186. end
  187. go
  188. -- SP: sp_326182b
  189. if exists (select name from sysobjects where
  190. name = 'sp_326182b' and type = 'P')
  191. drop procedure sp_326182b;
  192. go
  193. CREATE procedure sp_326182b (
  194. @param0 int = 9,
  195. @param1 decimal (5, 2) out,
  196. @param2 varchar (12))
  197. as
  198. begin
  199. set @param1 = (@param0 + @param1 + 2)
  200. return 666
  201. end