sqlserver.sql 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. use monotest
  2. go
  3. -- =================================== OBJECT EMPLOYEE ============================
  4. -- TABLE : INT_FAMILY
  5. -- data with id > 6000 is not gaurenteed to be read-only.
  6. if exists (select name from sysobjects where
  7. name = 'numeric_family' and type = 'U')
  8. drop table numeric_family;
  9. go
  10. create table numeric_family (
  11. id int PRIMARY KEY NOT NULL,
  12. type_bit bit NULL,
  13. type_tinyint tinyint NULL,
  14. type_smallint smallint NULL,
  15. type_int int NULL,
  16. type_bigint bigint NULL,
  17. type_decimal decimal (38, 0) NULL,
  18. type_numeric numeric (38, 0) NULL,
  19. type_money money NULL,
  20. type_smallmoney smallmoney NULL);
  21. go
  22. insert into numeric_family values (1,1,255,32767,2147483647,9223372036854775807,1000,1000,922337203685477.5807,214748.3647);
  23. insert into numeric_family values (2,0,0,-32768,-2147483648,-9223372036854775808,-1000,-1000,-922337203685477.5808,-214748.3648);
  24. insert into numeric_family values (3,0,0,0,0,0,0,0,0,0);
  25. insert into numeric_family values (4,null,null,null,null,null,null,null,null,null);
  26. go
  27. -- =================================== END OBJECT EMPLOYEE ========================
  28. -- =================================== OBJECT BINARY_FAMILY =========================
  29. -- TABLE : INT_FAMILY
  30. -- data with id > 6000 is not gaurenteed to be read-only.
  31. if exists (select name from sysobjects where
  32. name = 'employee' and type = 'U')
  33. drop table binary_family;
  34. go
  35. create table binary_family (
  36. id int PRIMARY KEY NOT NULL,
  37. type_binary binary NULL,
  38. type_varbinary varbinary (255) NULL,
  39. type_blob image NULL,
  40. type_tinyblob image NULL,
  41. type_mediumblob image NULL,
  42. type_longblob_image image NULL);
  43. go
  44. insert into binary_family values (1, convert (image, '555555'), convert (image, '0123456789012345678901234567890123456789012345678901234567890123456789'),
  45. convert (image, '66666666'), convert (image, '777777'),
  46. convert (image, '888888'), convert (image, '999999'));
  47. --insert into binary_family values (2,
  48. --insert into binary_family values (3,
  49. insert into binary_family values (4,null,null,null,null,null,null);
  50. go
  51. -- =================================== END OBJECT BINARY_FAMILY ========================
  52. -- =================================== OBJECT EMPLOYEE ============================
  53. -- TABLE : EMPLOYEE
  54. -- data with id above 6000 is not gaurenteed to be read-only.
  55. if exists (select name from sysobjects where
  56. name = 'employee' and type = 'U')
  57. drop table employee;
  58. go
  59. create table employee (
  60. id int PRIMARY KEY NOT NULL,
  61. fname varchar (50) NOT NULL,
  62. lname varchar (50) NULL,
  63. dob datetime NOT NULL,
  64. doj datetime NOT NULL,
  65. email varchar (50) NULL);
  66. grant all privileges on employee to monotester;
  67. insert into employee values (1, 'suresh', 'kumar', '1978-08-22', '2001-03-12', '[email protected]');
  68. insert into employee values (2, 'ramesh', 'rajendran', '1977-02-15', '2005-02-11', '[email protected]');
  69. insert into employee values (3, 'venkat', 'ramakrishnan', '1977-06-12', '2003-12-11', '[email protected]');
  70. insert into employee values (4, 'ramu', 'dhasarath', '1977-02-15', '2005-02-11', '[email protected]');
  71. go
  72. -- STORED PROCEDURES
  73. -- SP : sp_clean_person_table
  74. if exists (select name from sysobjects where
  75. name = 'sp_clean_employee_table' and type = 'P')
  76. drop procedure sp_clean_employee_table;
  77. go
  78. create procedure sp_clean_employee_table
  79. as
  80. begin
  81. delete from employee where id > 6000;
  82. end
  83. go
  84. -- SP : sp_get_age
  85. if exists (select name from sysobjects where
  86. name = 'sp_get_age' and type = 'P')
  87. drop procedure sp_get_age;
  88. go
  89. create procedure sp_get_age (
  90. @fname varchar (50),
  91. @age int output)
  92. as
  93. begin
  94. select @age = datediff (day, dob, getdate ()) from employee where fname like @fname;
  95. return @age;
  96. end
  97. go
  98. -- =================================== END OBJECT EMPLOYEE ============================