Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. drop trigger info_cache_trg;
  2. drop table info_cache;
  3. drop sequence info_cache_seq;
  4.  
  5. drop trigger info_table_columns_trg;
  6. drop sequence into_table_columns_seq;
  7. drop table info_table_columns;
  8.  
  9. drop trigger info_objects_trg;
  10. drop sequence info_objects_seq;
  11. drop table info_objects;
  12.  
  13. drop trigger info_tables_trg;
  14. drop sequence info_tables_seq;
  15. drop table info_tables;
  16.  
  17. drop trigger info_schemes_trg;
  18. drop sequence info_schemes_seq;
  19. drop table info_schemes;
  20.  
  21. drop trigger info_session_trg;
  22. drop table info_session;
  23. drop sequence info_session_seq;
  24.  
  25. create table info_schemes(
  26. scheme_id int not null primary key,
  27. scheme_name varchar(100)
  28. );
  29. create sequence info_schemes_seq start with 1 increment by 1;
  30.  
  31. create trigger info_schemes_trg
  32. before insert on info_schemes
  33. for each row
  34. begin
  35. if :new.scheme_id is null then
  36. select info_schemes_seq.nextval into :new.scheme_id from dual;
  37. end if;
  38. end;
  39.  
  40. commit;
  41. create table info_tables(
  42. table_id int not null primary key,
  43. table_name varchar(100),
  44. scheme_id int not null,
  45. primary_column_name varchar(100),
  46. foreign key(scheme_id) references info_schemes(scheme_id)
  47. );
  48.  
  49. create sequence info_tables_seq start with 1 increment by 1;
  50.  
  51. create trigger info_tables_trg
  52. before insert on info_tables
  53. for each row
  54. begin
  55. if :new.table_id is null then
  56. select info_tables_seq.nextval into :new.table_id from dual;
  57. end if;
  58. end;
  59. commit;
  60.  
  61. create table info_objects(
  62. object_id int not null primary key,
  63. table_id int not null,
  64. table_object_id int not null,
  65. foreign key(table_id) references info_tables(table_id)
  66. );
  67.  
  68. create sequence info_objects_seq start with 1 increment by 1;
  69.  
  70. create trigger info_objects_trg
  71. before insert on info_objects
  72. for each row
  73. begin
  74. if :new.object_id is null then
  75. select info_objects_seq.nextval into :new.object_id from dual;
  76. end if;
  77. end;
  78. commit;
  79.  
  80. create table info_table_columns(
  81. column_id int not null primary key,
  82. column_name varchar(100),
  83. table_id int not null,
  84. data_type varchar(20),
  85. foreign key(table_id) references info_tables(table_id)
  86. );
  87.  
  88. create sequence info_table_columns_seq start with 1 increment by 1;
  89.  
  90. create trigger info_table_columns_trg
  91. before insert on info_table_columns
  92. for each row
  93. begin
  94. if :new.column_id is null then
  95. select info_table_columns_seq.nextval into :new.column_id from dual;
  96. end if;
  97. end;
  98. commit;
  99.  
  100. create sequence info_session_seq start with 1 increment by 1 cache 2;
  101.  
  102. create table info_session(
  103. session_id int not null primary key,
  104. creation_date date not null);
  105.  
  106. create trigger info_session_trg
  107. before insert on info_session
  108. for each row
  109. begin
  110. if :new.session_id is null then
  111. select info_session_seq.nextval into :new.session_id from dual;
  112. end if;
  113. end;
  114.  
  115. create sequence info_cache_seq start with 1 increment by 1 cache 2;
  116.  
  117. create table info_cache(
  118. cache_id int not null primary key,
  119. session_id int not null,
  120. column_id int not null,
  121. object_id int not null,
  122. str_val varchar2(2000),
  123. int_val int,
  124. float_val float,
  125. date_val date,
  126. foreign key(session_id) references info_session(session_id),
  127. foreign key(column_id) references info_table_columns(column_id),
  128. foreign key(object_id) references info_objects(object_id));
  129.  
  130. create trigger info_cache_trg
  131. before insert on info_cache
  132. for each row
  133. begin
  134. if :new.cache_id is null then
  135. select info_cache_seq.nextval into :new.cache_id from dual;
  136. end if;
  137. end;
  138.  
  139. insert into info_schemes(scheme_name)
  140. values('domodedovo_uag');
  141. commit;
  142.  
  143. insert into info_tables(table_name, scheme_id, primary_column_name)
  144. values('buildings', 1, 'building_id');
  145. commit;
  146.  
  147. insert into info_objects(table_id, table_object_id)
  148. values(1, 17501);
  149. insert into info_objects(table_id, table_object_id)
  150. values(1, 17567);
  151. commit;
  152.  
  153. insert into info_table_columns(column_name, table_id)
  154. values('floors', 1);
  155. insert into info_table_columns(column_name, table_id)
  156. values('total_area', 1);
  157. insert into info_Table_columns(column_name, table_id)
  158. values('build_name', 1);
  159. commit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement