Guest User

Untitled

a guest
May 1st, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 9.86 KB | None | 0 0
  1. -- ****************** SqlDBM: Microsoft SQL Server ******************
  2. -- ******************************************************************
  3.  
  4. DROP TABLE [dbo].[document];
  5. GO
  6.  
  7.  
  8. DROP TABLE [dbo].[ptv_id];
  9. GO
  10.  
  11.  
  12. DROP TABLE [dbo].[route_detail];
  13. GO
  14.  
  15.  
  16. DROP TABLE [dbo].[cotg];
  17. GO
  18.  
  19.  
  20. DROP TABLE [dbo].[summon_stamp];
  21. GO
  22.  
  23.  
  24. DROP TABLE [dbo].[planetpress_control];
  25. GO
  26.  
  27.  
  28. DROP TABLE [dbo].[summon_control];
  29. GO
  30.  
  31.  
  32. DROP TABLE [dbo].[summon_cost];
  33. GO
  34.  
  35.  
  36. DROP TABLE [dbo].[summon_casenumber];
  37. GO
  38.  
  39.  
  40. DROP TABLE [dbo].[summon_metadata];
  41. GO
  42.  
  43.  
  44. DROP TABLE [dbo].[subset];
  45. GO
  46.  
  47.  
  48. DROP TABLE [dbo].[cotg_category_description];
  49. GO
  50.  
  51.  
  52. DROP TABLE [dbo].[cotg_item_description];
  53. GO
  54.  
  55.  
  56. DROP TABLE [dbo].[control_description];
  57. GO
  58.  
  59.  
  60. DROP TABLE [dbo].[route];
  61. GO
  62.  
  63.  
  64. DROP TABLE [dbo].[summon];
  65. GO
  66.  
  67.  
  68. --************************************** [dbo].[cotg_category_description]
  69.  
  70. CREATE TABLE [dbo].[cotg_category_description]
  71. (
  72.  [id]          INT IDENTITY (1, 1) NOT NULL ,
  73.  [name]        VARCHAR(50) NOT NULL ,
  74.  [description] VARCHAR(800) NOT NULL ,
  75.  
  76.  CONSTRAINT [pk_cotg_category_description] PRIMARY KEY CLUSTERED ([id] ASC),
  77.  CONSTRAINT [ux_cotg_category_name] UNIQUE NONCLUSTERED ([name] ASC)
  78. );
  79. GO
  80.  
  81.  
  82.  
  83. --************************************** [dbo].[cotg_item_description]
  84.  
  85. CREATE TABLE [dbo].[cotg_item_description]
  86. (
  87.  [id]          INT IDENTITY (1, 1) NOT NULL ,
  88.  [name]        VARCHAR(50) NOT NULL ,
  89.  [description] VARCHAR(800) NOT NULL ,
  90.  
  91.  CONSTRAINT [pk_cotg_item_description] PRIMARY KEY CLUSTERED ([id] ASC),
  92.  CONSTRAINT [ux_cotg_item_name] UNIQUE NONCLUSTERED ([name] ASC)
  93. );
  94. GO
  95.  
  96.  
  97.  
  98. --************************************** [dbo].[control_description]
  99.  
  100. CREATE TABLE [dbo].[control_description]
  101. (
  102.  [id]          INT NOT NULL ,
  103.  [name]        VARCHAR(30) NOT NULL ,
  104.  [description] VARCHAR(800) NOT NULL ,
  105.  
  106.  CONSTRAINT [pk_control_description] PRIMARY KEY CLUSTERED ([id] ASC)
  107. );
  108. GO
  109.  
  110.  
  111.  
  112. --************************************** [dbo].[route]
  113.  
  114. CREATE TABLE [dbo].[route]
  115. (
  116.  [id]          INT IDENTITY (1, 1) NOT NULL ,
  117.  [NUMBER]      VARCHAR(50) NOT NULL ,
  118.  [bailiff]     INT NOT NULL ,
  119.  [drive_date]  DATE NOT NULL ,
  120.  [costs]       DECIMAL(18,2) NOT NULL ,
  121.  [LENGTH]      INT NOT NULL ,
  122.  [index_count] INT NOT NULL CONSTRAINT [DF_route_index_count] DEFAULT 1 ,
  123.  [ptv_id]      INT NOT NULL ,
  124.  
  125.  CONSTRAINT [pk_route] PRIMARY KEY CLUSTERED ([id] ASC)
  126. );
  127. GO
  128.  
  129.  
  130.  
  131. --************************************** [dbo].[summon]
  132.  
  133. CREATE TABLE [dbo].[summon]
  134. (
  135.  [id]          INT IDENTITY (1, 1) NOT NULL ,
  136.  [name]        VARCHAR(50) NULL ,
  137.  [TYPE]        VARCHAR(50) NULL ,
  138.  [action_code] VARCHAR(50) NULL ,
  139.  [action_id]   INT NULL ,
  140.  [location]    VARCHAR(500) NULL ,
  141.  
  142.  CONSTRAINT [pk_summon] PRIMARY KEY CLUSTERED ([id] ASC)
  143. );
  144. GO
  145.  
  146.  
  147.  
  148. --************************************** [dbo].[ptv_id]
  149.  
  150. CREATE TABLE [dbo].[ptv_id]
  151. (
  152.  [summon_id] INT NOT NULL ,
  153.  [id]        INT NOT NULL ,
  154.  [DTS]       DATETIME NOT NULL ,
  155.  
  156.  CONSTRAINT [pk_link_id] PRIMARY KEY CLUSTERED ([summon_id] ASC),
  157.  CONSTRAINT [fk_summon_id_ptv_link] FOREIGN KEY ([summon_id])
  158.   REFERENCES [dbo].[summon]([id])
  159. );
  160. GO
  161.  
  162.  
  163. CREATE NONCLUSTERED INDEX [ix_link_summon_id] ON [dbo].[ptv_id]
  164.  (
  165.   [summon_id] ASC
  166.  )
  167.  
  168. GO
  169.  
  170.  
  171. --************************************** [dbo].[route_detail]
  172.  
  173. CREATE TABLE [dbo].[route_detail]
  174. (
  175.  [id]                 INT NOT NULL ,
  176.  [route_id]           INT NOT NULL ,
  177.  [sub_number]         INT NOT NULL ,
  178.  [address]            VARCHAR(200) NOT NULL ,
  179.  [merge_same_address] BIT NOT NULL ,
  180.  
  181.  CONSTRAINT [pk_route_detail] PRIMARY KEY CLUSTERED ([id] ASC, [route_id] ASC),
  182.  CONSTRAINT [fk_route_id_route_detail] FOREIGN KEY ([route_id])
  183.   REFERENCES [dbo].[route]([id]),
  184.  CONSTRAINT [fk_summon_id_ptv_link_id] FOREIGN KEY ([id])
  185.   REFERENCES [dbo].[summon]([id])
  186. );
  187. GO
  188.  
  189.  
  190. CREATE NONCLUSTERED INDEX [ix_route_id_route_detail] ON [dbo].[route_detail]
  191.  (
  192.   [route_id] ASC
  193.  )
  194.  
  195. GO
  196.  
  197. CREATE NONCLUSTERED INDEX [ix_summon_id_link_id] ON [dbo].[route_detail]
  198.  (
  199.   [id] ASC
  200.  )
  201.  
  202. GO
  203.  
  204.  
  205. --************************************** [dbo].[cotg]
  206.  
  207. CREATE TABLE [dbo].[cotg]
  208. (
  209.  [summon_id]   INT NOT NULL ,
  210.  [category_id] INT NOT NULL ,
  211.  [item_id]     INT NOT NULL ,
  212.  [index_nr]    INT NOT NULL ,
  213.  [DATA]        VARCHAR(400) NOT NULL ,
  214.  
  215.  CONSTRAINT [ux_summon_category_item_index] UNIQUE NONCLUSTERED ([summon_id] ASC, [index_nr] ASC),
  216.  CONSTRAINT [fk_cotg_item_id] FOREIGN KEY ([item_id])
  217.   REFERENCES [dbo].[cotg_item_description]([id]),
  218.  CONSTRAINT [fk_cotg_category_id] FOREIGN KEY ([category_id])
  219.   REFERENCES [dbo].[cotg_category_description]([id]),
  220.  CONSTRAINT [fk_cotg_summon_id] FOREIGN KEY ([summon_id])
  221.   REFERENCES [dbo].[summon]([id])
  222. );
  223. GO
  224.  
  225.  
  226. CREATE CLUSTERED INDEX [pk_cotg_simmon_id] ON [dbo].[cotg]
  227.  (
  228.   [summon_id] ASC
  229.  )
  230.  
  231. GO
  232.  
  233.  
  234. --************************************** [dbo].[summon_stamp]
  235.  
  236. CREATE TABLE [dbo].[summon_stamp]
  237. (
  238.  [summon_id]     INT NOT NULL ,
  239.  [stamp_type]    VARCHAR(50) NOT NULL ,
  240.  [index_count]   INT NOT NULL CONSTRAINT [DF_summon_stamp_index_count] DEFAULT 1 ,
  241.  [stamp_data]    VARCHAR(MAX) NULL ,
  242.  [y_coordinates] INT NOT NULL ,
  243.  [x_coordinates] INT NOT NULL ,
  244.  [page_nr]       INT NOT NULL ,
  245.  
  246.  CONSTRAINT [ux_summon_type_index_count] UNIQUE NONCLUSTERED ([summon_id] ASC, [stamp_type] ASC, [index_count] ASC)
  247. );
  248. GO
  249.  
  250.  
  251. CREATE NONCLUSTERED INDEX [ix_summon_id_stamp] ON [dbo].[summon_stamp]
  252.  (
  253.   [summon_id] ASC
  254.  )
  255.  
  256. GO
  257.  
  258.  
  259. --************************************** [dbo].[planetpress_control]
  260.  
  261. CREATE TABLE [dbo].[planetpress_control]
  262. (
  263.  [description_id] INT NOT NULL ,
  264.  [summon_id]      INT NOT NULL ,
  265.  [index_count]    INT NOT NULL CONSTRAINT [DF_planetpress_control_index_count] DEFAULT 1 ,
  266.  [RESULT]         BIT NOT NULL ,
  267.  [dts]            DATETIME NOT NULL ,
  268.  
  269.  CONSTRAINT [pk_planetpress_control] PRIMARY KEY CLUSTERED),
  270.  CONSTRAINT [fk_summon_id_planetpress_control] FOREIGN KEY ([summon_id])
  271.   REFERENCES [dbo].[summon]([id])
  272. );
  273. GO
  274.  
  275.  
  276. CREATE NONCLUSTERED INDEX [ix_summon_id_planetpress_control] ON [dbo].[planetpress_control]
  277.  (
  278.   [summon_id] ASC
  279.  )
  280.  
  281. GO
  282.  
  283. CREATE NONCLUSTERED INDEX [ix_control_id_planetpress_control] ON [dbo].[planetpress_control]
  284.  (
  285.   [description_id] ASC
  286.  )
  287.  
  288. GO
  289.  
  290.  
  291. --************************************** [dbo].[summon_control]
  292.  
  293. CREATE TABLE [dbo].[summon_control]
  294. (
  295.  [id]             INT NOT NULL ,
  296.  [description_id] INT NOT NULL ,
  297.  [index_count]    INT NOT NULL CONSTRAINT [DF_summon_control_index_count] DEFAULT 1 ,
  298.  [RESULT]         BIT NOT NULL ,
  299.  [extra]          VARCHAR(500) NULL ,
  300.  [dts]            DATETIME NOT NULL ,
  301.  
  302.  CONSTRAINT [pk_summon_control] PRIMARY KEY CLUSTERED ([id] ASC),
  303.  CONSTRAINT [fk_summon_id_control] FOREIGN KEY ([id])
  304.   REFERENCES [dbo].[summon]([id]),
  305.  CONSTRAINT [fk_control_id_control] FOREIGN KEY ([description_id])
  306.   REFERENCES [dbo].[control_description]([id])
  307. );
  308. GO
  309.  
  310.  
  311. CREATE NONCLUSTERED INDEX [ix_summon_id_control] ON [dbo].[summon_control]
  312.  (
  313.   [id] ASC
  314.  )
  315.  
  316. GO
  317.  
  318. CREATE NONCLUSTERED INDEX [ix_control_id_control] ON [dbo].[summon_control]
  319.  (
  320.   [description_id] ASC
  321.  )
  322.  
  323. GO
  324.  
  325.  
  326. --************************************** [dbo].[summon_cost]
  327.  
  328. CREATE TABLE [dbo].[summon_cost]
  329. (
  330.  [summon_id] INT NOT NULL ,
  331.  [TYPE]      VARCHAR(50) NOT NULL ,
  332.  [amount]    DECIMAL(18,2) NOT NULL ,
  333.  
  334.  CONSTRAINT [ux_summon_id_type] UNIQUE NONCLUSTERED ([summon_id] ASC, [TYPE] ASC)
  335. );
  336. GO
  337.  
  338.  
  339. CREATE NONCLUSTERED INDEX [ix_summon_id_cost] ON [dbo].[summon_cost]
  340.  (
  341.   [summon_id] ASC
  342.  )
  343.  
  344. GO
  345.  
  346.  
  347. --************************************** [dbo].[summon_casenumber]
  348.  
  349. CREATE TABLE [dbo].[summon_casenumber]
  350. (
  351.  [summon_id]  INT NOT NULL ,
  352.  [casenumber] VARCHAR(11) NOT NULL ,
  353.  
  354.  CONSTRAINT [pk_summon_casenumber] PRIMARY KEY CLUSTERED),
  355.  CONSTRAINT [fk_summon_id_casenumber] FOREIGN KEY ([summon_id])
  356.   REFERENCES [dbo].[summon]([id])
  357. );
  358. GO
  359.  
  360.  
  361. CREATE NONCLUSTERED INDEX [ix_summon_id_casenumber] ON [dbo].[summon_casenumber]
  362.  (
  363.   [summon_id] ASC
  364.  )
  365.  
  366. GO
  367.  
  368.  
  369. --************************************** [dbo].[summon_metadata]
  370.  
  371. CREATE TABLE [dbo].[summon_metadata]
  372. (
  373.  [id]                 INT NOT NULL ,
  374.  [DATE]               DATE NULL ,
  375.  [TYPE]               VARCHAR(5) NULL ,
  376.  [created_by]         VARCHAR(10) NULL ,
  377.  [printed_deleted_by] VARCHAR(10) NULL ,
  378.  [team]               VARCHAR(30) NULL ,
  379.  [vat]                BIT NULL ,
  380.  [latest_info_check]  DATE NULL ,
  381.  [cotg_storage_id]    INT NULL ,
  382.  [cn_storage_id]      INT NULL ,
  383.  [batch_nr]           INT NULL ,
  384.  
  385.  CONSTRAINT [pk_summon_metadata] PRIMARY KEY CLUSTERED ([id] ASC),
  386.  CONSTRAINT [fk_summon_id_metadata] FOREIGN KEY ([id])
  387.   REFERENCES [dbo].[summon]([id])
  388. );
  389. GO
  390.  
  391.  
  392. CREATE NONCLUSTERED INDEX [ix_summon_id_metadata] ON [dbo].[summon_metadata]
  393.  (
  394.   [id] ASC
  395.  )
  396.  
  397. GO
  398.  
  399.  
  400. --************************************** [dbo].[subset]
  401.  
  402. CREATE TABLE [dbo].[subset]
  403. (
  404.  [id]              INT IDENTITY (1, 1) NOT NULL ,
  405.  [summon_id]       INT NOT NULL ,
  406.  [staple]          BIT NOT NULL ,
  407.  [name]            VARCHAR(50) NULL ,
  408.  [location]        VARCHAR(500) NULL ,
  409.  [duplicate_count] AS 1 ,
  410.  
  411.  CONSTRAINT [pk_subset] PRIMARY KEY CLUSTERED ([id] ASC)
  412. );
  413. GO
  414.  
  415.  
  416. CREATE NONCLUSTERED INDEX [ix_subset_documentset] ON [dbo].[subset]
  417.  (
  418.   [summon_id] ASC
  419.  )
  420.  
  421. GO
  422.  
  423.  
  424. --************************************** [dbo].[document]
  425.  
  426. CREATE TABLE [dbo].[document]
  427. (
  428.  [id]          INT IDENTITY (1, 1) NULL ,
  429.  [subset_id]   INT NOT NULL ,
  430.  [code]        VARCHAR(50) NOT NULL ,
  431.  [name]        VARCHAR(50) NOT NULL ,
  432.  [duplex]      BIT NOT NULL ,
  433.  [TYPE]        VARCHAR(20) NOT NULL ,
  434.  [media]       VARCHAR(50) NOT NULL ,
  435.  [stamp]       VARCHAR(50) NULL ,
  436.  [page_count]  INT NULL ,
  437.  [action_code] VARCHAR(50) NULL ,
  438.  [action_id]   INT NULL ,
  439.  [location]    VARCHAR(500) NULL ,
  440.  
  441.  CONSTRAINT [pk_document] PRIMARY KEY CLUSTERED ([id] ASC)
  442. );
  443. GO
  444.  
  445.  
  446. CREATE NONCLUSTERED INDEX [ix_subset_document] ON [dbo].[document]
  447.  (
  448.   [subset_id] ASC
  449.  )
  450.  
  451. GO
Advertisement
Add Comment
Please, Sign In to add comment