Advertisement
saleks28

subd1

Aug 18th, 2020
1,319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 3.61 KB | None | 0 0
  1. /* Далее идут блоки удаления таблиц если они существуют*/
  2. BEGIN
  3.     EXECUTE IMMEDIATE 'drop table Applications cascade constraints';
  4. EXCEPTION
  5.     WHEN OTHERS THEN NULL;
  6. END;
  7. /
  8. BEGIN
  9.     EXECUTE IMMEDIATE 'drop table Software cascade constraints';
  10. EXCEPTION
  11.     WHEN OTHERS THEN NULL;
  12. END;
  13. /
  14. BEGIN
  15.     EXECUTE IMMEDIATE 'drop table SystemSoft cascade constraints';
  16. EXCEPTION
  17.     WHEN OTHERS THEN NULL;
  18. END;
  19. /
  20. BEGIN
  21.     EXECUTE IMMEDIATE 'drop table Computer_System cascade constraints';
  22. EXCEPTION
  23.     WHEN OTHERS THEN NULL;
  24. END;
  25. /
  26. BEGIN
  27.     EXECUTE IMMEDIATE 'drop table CS_Component cascade constraints';
  28. EXCEPTION
  29.     WHEN OTHERS THEN NULL;
  30. END;
  31. /
  32. BEGIN
  33.     EXECUTE IMMEDIATE 'drop table Applications_SystemSoft cascade constraints';
  34. EXCEPTION
  35.     WHEN OTHERS THEN NULL;
  36. END;
  37. /
  38. BEGIN
  39.     EXECUTE IMMEDIATE 'drop table Software_Computer_System cascade constraints';
  40. EXCEPTION
  41.     WHEN OTHERS THEN NULL;
  42. END;
  43. /
  44.  
  45. CREATE TABLE Software (
  46.     PRIMARY KEY (Code),
  47.     Code           INTEGER
  48.                   CHECK ( Code > 0 ),
  49.     -- Code уже PK, Name просто Unique
  50.     Name           VARCHAR2(50) NOT NULL UNIQUE,
  51.     License       VARCHAR2(30),
  52.     Cost_per_month REAL
  53.                   CHECK ( Cost_per_month >= 0.0 )
  54. );
  55.  
  56. CREATE TABLE Applications (
  57.     PRIMARY KEY (Code),
  58.     FOREIGN KEY (Code) REFERENCES Software (Code),
  59.     Code       INTEGER
  60.                 CHECK ( Code > 0 ),
  61.     Description VARCHAR2(500),
  62.     Purpose     VARCHAR2(30) NOT NULL
  63. );
  64.  
  65. CREATE TABLE SystemSoft (
  66.     PRIMARY KEY (Code),
  67.     FOREIGN KEY (Code) REFERENCES Software (Code),
  68.     Code     INTEGER
  69.             CHECK ( Code > 0 ),
  70.     Hardware VARCHAR2(50
  71. );
  72.  
  73. CREATE TABLE Computer_System (
  74.     PRIMARY KEY (Code),
  75.     Code       INTEGER
  76.                 CHECK ( Code > 0 ),
  77.     Description VARCHAR2(500),
  78.     Purpose     VARCHAR2(30) NOT NULL
  79. );
  80.  
  81. -- Таблица ComputerSystem Component
  82. CREATE TABLE CS_Component (
  83.     PRIMARY KEY (ComponentID),
  84.     FOREIGN KEY (Computer_System_Code) REFERENCES Computer_System(Code),
  85.     FOREIGN KEY (NextComponent) REFERENCES CS_Component(ComponentID),
  86.     -- Суррогатный первичный ключ
  87.     ComponentID     NUMBER GENERATED ALWAYS AS IDENTITY,
  88.     Computer_System_Code         INTEGER
  89.                     CHECK ( Computer_System_code > 0 ),
  90.     Accountable_Emp VARCHAR2(100) NOT NULL,
  91.     -- Критичность будет определяться целым числом
  92.     Critical       INTEGER
  93.                     CHECK ( Critical >= 0 ),
  94.     NextComponent     NUMBER -- Ссылка на CS_Component верхнего уровня
  95. );
  96.  
  97. -- Таблица множественной ассоциации для CS и Software
  98. CREATE TABLE Software_Computer_System (
  99.     PRIMARY KEY (Code_Software, Code_CS),
  100.     FOREIGN KEY (Code_Software) REFERENCES Software(Code),
  101.     FOREIGN KEY (Code_CS) REFERENCES Computer_System(Code),
  102.     Code_Software INTEGER
  103.                   CHECK ( Code_Software > 0 ),
  104.     Code_CS       INTEGER
  105.                   CHECK ( Code_CS > 0 )
  106. );
  107.  
  108. -- Таблица множественной ассоциации для Applications и SystemSoft
  109. CREATE TABLE Applications_SystemSoft (
  110.     PRIMARY KEY (Applications_Code, SystemSoft_Code),
  111.     FOREIGN KEY (Applications_Code) REFERENCES Applications(Code),
  112.     FOREIGN KEY (SystemSoft_Code) REFERENCES SystemSoft(Code),
  113.     Applications_Code       INTEGER,
  114.                     CHECK ( Applications_Code > 0 ),
  115.     SystemSoft_Code INTEGER
  116.                     CHECK ( SystemSoft_Code > 0 )
  117. );
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement