sqlserver.sql 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. use monotest;
  2. -- =================================== OBJECT NUMERIC_FAMILY============================
  3. -- TABLE : NUMERIC_FAMILY
  4. -- data with id > 6000 is not gaurenteed to be read-only.
  5. if exists (select name from sysobjects where
  6. name = 'numeric_family' and type = 'U')
  7. drop table numeric_family;
  8. go
  9. create table numeric_family(
  10. id int PRIMARY KEY NOT NULL,
  11. type_bit bit NULL,
  12. type_tinyint tinyint NULL,
  13. type_smallint smallint NULL,
  14. type_int int NULL,
  15. type_bigint bigint NULL,
  16. type_decimal decimal(38,0) NULL,
  17. type_numeric numeric(38,0) NULL,
  18. type_money money NULL,
  19. type_smallmoney smallmoney NULL,
  20. type_float real NULL,
  21. type_double float NULL);
  22. go
  23. grant all privileges on numeric_family to monotester;
  24. go
  25. insert into numeric_family values (1,1,255,32767,2147483647,9223372036854775807,1000,1000,922337203685477.5807,214748.3647,3.40E+38,1.79E+308);
  26. insert into numeric_family values (2,0,0,-32768,-2147483648,-9223372036854775808,-1000,-1000,-922337203685477.5808,-214748.3648,-3.40E+38,-1.79E+308);
  27. insert into numeric_family values (3,0,0,0,0,0,0,0,0,0,0,0);
  28. insert into numeric_family values (4,null,null,null,null,null,null,null,null,null,null,null);
  29. go
  30. -- =================================== END OBJECT NUMERIC_FAMILY ========================
  31. -- =================================== OBJECT BINARY_FAMILY =========================
  32. -- TABLE : BINARY_FAMILY
  33. -- data with id > 6000 is not gaurenteed to be read-only.
  34. if exists (select name from sysobjects where
  35. name = 'binary_family' and type = 'U')
  36. drop table binary_family;
  37. go
  38. create table binary_family (
  39. id int PRIMARY KEY NOT NULL,
  40. type_binary binary NULL,
  41. type_varbinary varbinary (255) NULL,
  42. type_blob image NULL,
  43. type_tinyblob image NULL,
  44. type_mediumblob image NULL,
  45. type_longblob_image image NULL);
  46. go
  47. grant all privileges on binary_family to monotester;
  48. go
  49. insert into binary_family values (1, convert (binary, '5'), convert (varbinary, '0123456789012345678901234567890123456789012345678901234567890123456789'),
  50. convert (image, '66666666'), convert (image, '777777'),
  51. convert (image, '888888'), convert (image, '999999'));
  52. --insert into binary_family values (2,
  53. --insert into binary_family values (3,
  54. insert into binary_family values (4,null,null,null,null,null,null);
  55. go
  56. -- =================================== END OBJECT BINARY_FAMILY ========================
  57. -- =================================== OBJECT STRING_FAMILY============================
  58. -- TABLE : string_family
  59. -- data with id above 6000 is not gaurenteed to be read-only.
  60. if exists (select name from sysobjects where
  61. name = 'string_family' and type = 'U')
  62. drop table string_family;
  63. go
  64. create table string_family(
  65. id int PRIMARY KEY NOT NULL,
  66. type_guid uniqueidentifier NULL,
  67. type_char char(10) NULL,
  68. type_varchar varchar(10) NULL,
  69. type_text text NULL,
  70. type_ntext ntext NULL);
  71. go
  72. grant all privileges on string_family to monotester;
  73. go
  74. insert into string_family values (1,newid(),'char','varchar','text','ntext');
  75. insert into string_family values (4,null,null,null,null,null);
  76. go
  77. -- =================================== END OBJECT STRING_FAMILY ========================
  78. -- =================================== OBJECT DATETIME_FAMILY============================
  79. -- TABLE : datetime_family
  80. -- data with id above 6000 is not gaurenteed to be read-only.
  81. if exists (select name from sysobjects where
  82. name = 'datetime_family' and type = 'U')
  83. drop table datetime_family;
  84. go
  85. create table datetime_family (
  86. id int PRIMARY KEY NOT NULL,
  87. type_smalldatetime smalldatetime NULL,
  88. type_datetime datetime NULL);
  89. grant all privileges on datetime_family to monotester;
  90. go
  91. insert into datetime_family values (1,'2079-06-06 23:59:00','9999-12-31 23:59:59:00');
  92. insert into datetime_family values (4,null,null);
  93. go
  94. -- =================================== END OBJECT DATETIME_FAMILY========================
  95. -- =================================== OBJECT EMPLOYEE ============================
  96. -- TABLE : EMPLOYEE
  97. -- data with id above 6000 is not gaurenteed to be read-only.
  98. if exists (select name from sysobjects where
  99. name = 'employee' and type = 'U')
  100. drop table employee;
  101. go
  102. create table employee (
  103. id int PRIMARY KEY NOT NULL,
  104. fname varchar (50) NOT NULL,
  105. lname varchar (50) NULL,
  106. dob datetime NOT NULL,
  107. doj datetime NOT NULL,
  108. email varchar (50) NULL);
  109. go
  110. grant all privileges on employee to monotester;
  111. go
  112. insert into employee values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', '[email protected]');
  113. insert into employee values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', '[email protected]');
  114. insert into employee values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', '[email protected]');
  115. insert into employee values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', '[email protected]');
  116. go
  117. -- STORED PROCEDURES
  118. -- SP : sp_clean_person_table
  119. if exists (select name from sysobjects where
  120. name = 'sp_clean_employee_table' and type = 'P')
  121. drop procedure sp_clean_employee_table;
  122. go
  123. create procedure sp_clean_employee_table
  124. as
  125. begin
  126. delete from employee where id > 6000;
  127. end
  128. go
  129. -- SP : sp_get_age
  130. if exists (select name from sysobjects where
  131. name = 'sp_get_age' and type = 'P')
  132. drop procedure sp_get_age;
  133. go
  134. create procedure sp_get_age (
  135. @fname varchar (50),
  136. @age int output)
  137. as
  138. begin
  139. select @age = datediff (day, dob, getdate ()) from employee where fname like @fname;
  140. return @age;
  141. end
  142. go
  143. -- =================================== END OBJECT EMPLOYEE ============================