Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 6.53 KB | None | 0 0
  1. -- ****************** SqlDBM: Microsoft SQL Server ******************
  2. -- ******************************************************************
  3.  
  4. -- ************************************** [Ticket]
  5.  
  6. CREATE TABLE [Ticket]
  7. (
  8.  [TicketId]     int IDENTITY (1, 1) NOT NULL ,
  9.  [DiscountId]   int NOT NULL ,
  10.  [PriceId]      int NOT NULL ,
  11.  [AreaId]       int NOT NULL ,
  12.  [ValidityDate] timestamp NOT NULL ,
  13.  CONSTRAINT PK_Ticket PRIMARY KEY NONCLUSTERED ([TicketId]),
  14.  );
  15. GO
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22. -- ************************************** [ControlSchedule]
  23.  
  24. CREATE TABLE [ControlSchedule]
  25. (
  26.  [ControlScheduleId] int IDENTITY (1, 1) NOT NULL ,
  27.  [RegionId]          int NOT NULL ,
  28.  [MeanOfTransportId] int NOT NULL ,
  29.  [Month]             int NOT NULL ,
  30.  CONSTRAINT PK_ControlSchedule PRIMARY KEY NONCLUSTERED ([ControlScheduleId]),
  31.  
  32. );
  33. GO
  34.  
  35. -- ************************************** [Company]
  36.  
  37. CREATE TABLE [Company]
  38. (
  39.  [CompanyId]      int IDENTITY (1, 1) NOT NULL ,
  40.  [CompanyName]    varchar(45) NOT NULL ,
  41.  [CityId]         int NOT NULL ,
  42.  [StreetId]       int NOT NULL ,
  43.  [BuildingNumber] int NOT NULL ,
  44.  [PostalCode]     varchar(7) NOT NULL ,
  45.  [PhoneNumber]    int NOT NULL ,
  46.  [EmailAddress]   varchar(30) NOT NULL ,
  47.  CONSTRAINT PK_CompanyId PRIMARY KEY NONCLUSTERED ([CompanyId]),
  48.  
  49. );
  50. GO
  51.  
  52.  
  53.  
  54. EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'NIP / REGON
  55.  
  56. ', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Company', @level2type=N'COLUMN', @level2name=N'CompanyId';
  57. GO
  58.  
  59.  
  60. -- ************************************** [Person]
  61. CREATE TABLE [Person]
  62. (
  63.  [PersonId]       int IDENTITY (1, 1) NOT NULL ,
  64.  [Name]           varchar(30) NOT NULL ,
  65.  [Surname]        varchar(30) NOT NULL ,
  66.  [PESEL]          varchar(11) NULL ,
  67.  [TicketId]       int NULL ,
  68.  [DocumentTypeId] int NOT NULL ,
  69.  [DocumentSeries] int NOT NULL ,
  70.  [FathersName]    varchar(30) NULL ,
  71.  [CityId]         int NOT NULL ,
  72.  [StreetId]       int NOT NULL ,
  73.  [BuildingNumber] int NOT NULL ,
  74.  [FlatNumber]     int NULL ,
  75.  [NationalityId]  int NULL ,
  76.  [BirthCountryId] int NULL ,
  77.  [BirthCityId]    int NULL ,
  78.  [BirthDate]      date NULL ,
  79.  CONSTRAINT PK_Person PRIMARY KEY NONCLUSTERED ([PersonId]),    
  80.  CONSTRAINT FK_Person_Ticket FOREIGN KEY (PersonId)    
  81.     REFERENCES Ticket (TicketId)  
  82. );
  83. GO
  84.  
  85.  
  86.  
  87.  
  88. -- ************************************** [Accounts]
  89.  
  90. CREATE TABLE [Accounts]
  91. (
  92.  [AccountsId]      int IDENTITY (1, 1) NOT NULL ,
  93.  [CompanyId]       int NOT NULL ,
  94.  [Revenue]         float NOT NULL ,
  95.  [OperationalCost] float NOT NULL ,
  96.  [Month]           int NOT NULL ,
  97.  [Year]            int NOT NULL ,
  98.  CONSTRAINT PK_Accounts PRIMARY KEY NONCLUSTERED (AccountsId),    
  99.  CONSTRAINT FK_Accounts_Company FOREIGN KEY (AccountsId)    
  100.     REFERENCES [Company] ([CompanyId])  
  101. );
  102. GO
  103.  
  104.  
  105. -- ************************************** [TicketCollector]
  106.  
  107. CREATE TABLE [TicketCollector]
  108. (
  109.  [TicketCollectorId]          int IDENTITY (1, 1) NOT NULL ,
  110.  [CompanyId]                  int NOT NULL ,
  111.  [ControlScheduleId]          int NULL ,
  112.  [Name]                       varchar(30) NOT NULL ,
  113.  [Surname]                    varchar(30) NOT NULL ,
  114.  [MedicalExamValidity]        date NOT NULL ,
  115.  [Age]                        int NOT NULL ,
  116.  [LicenseNumber]              int NOT NULL ,
  117.  [TrainingValidity]           date NOT NULL ,
  118.  [JobStatusId]                int NOT NULL ,
  119.  [BankAccountNumber]          varchar(26) NOT NULL ,
  120.  [ColleagueTicketCollectorId] int NULL ,
  121.   CONSTRAINT PK_TicketCollector PRIMARY KEY NONCLUSTERED ([TicketCollectorId]),    
  122.  CONSTRAINT FK_TicketCollector_Company FOREIGN KEY ([TicketCollectorId])    
  123.     REFERENCES [Company] ([CompanyId]),
  124. CONSTRAINT FK_TicketCollector_ControlSchedule FOREIGN KEY ([TicketCollectorId])    
  125.     REFERENCES [ControlSchedule] ([ControlScheduleId])      
  126.  
  127.  
  128. -- CONSTRAINT [FK_158] FOREIGN KEY ([ColleagueTicketCollectorId])  REFERENCES [TicketCollector]([TicketCollectorId]),
  129.  
  130. );
  131. GO
  132. ALTER TABLE [TicketCollector]
  133. ADD CONSTRAINT FK_TicketCollector_TicketCollector FOREIGN KEY ([TicketCollectorId])    
  134.     REFERENCES TicketCollector ([TicketCollectorId])    
  135.  
  136. EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'#1 - working
  137. #2 - vacation
  138. #3 - suspended', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'TicketCollector', @level2type=N'COLUMN', @level2name=N'JobStatusId';
  139. GO
  140. -- ************************************** [Payroll]
  141.  
  142. CREATE TABLE [Payroll]
  143. (
  144.  [PayrollId]         int IDENTITY (1, 1) NOT NULL ,
  145.  [TicketCollectorId] int NOT NULL ,
  146.  [ContractTypeId]    int NOT NULL ,
  147.  [GrossSalary]       float NOT NULL ,
  148.  [Bonus]             float NOT NULL ,
  149.  [Year]              int NOT NULL ,
  150.  [Month]             int NOT NULL ,
  151.   CONSTRAINT PK_Payroll PRIMARY KEY NONCLUSTERED ([PayrollId]),    
  152.  CONSTRAINT FK_Payroll_TicketCollector FOREIGN KEY ([PayrollId])    
  153.     REFERENCES [TicketCollector] ([TicketCollectorId])  
  154. );
  155. GO
  156.  
  157. -- ************************************** [Fine]
  158.  
  159. CREATE TABLE [Fine]
  160. (
  161.  [FineId]                  int IDENTITY (1, 1) NOT NULL ,
  162.  [TicketCollectorId]       int NOT NULL ,
  163.  [PersonId]                int NOT NULL ,
  164.  [WritingDate]             timestamp NOT NULL ,
  165.  [FineTypeId]              int NOT NULL ,
  166.  [FineAmountWithInterests] float NOT NULL ,
  167.  [PaymentStatusId]         int NOT NULL ,
  168.  CONSTRAINT PK_Fine PRIMARY KEY NONCLUSTERED ([FineId]),    
  169.  CONSTRAINT FK_Fine_TicketCollector FOREIGN KEY ([FineId])    
  170.     REFERENCES [TicketCollector] ([TicketCollectorId]),
  171. CONSTRAINT FK_Fine_Person FOREIGN KEY ([FineId])    
  172.     REFERENCES [Person] ([PersonId])      
  173. );
  174. GO
  175.  
  176.  
  177. -- ************************************** [Complaint]
  178.  
  179. CREATE TABLE [Complaint]
  180. (
  181.  [ComplaintId]       int NOT NULL ,
  182.  [PersonId]          int NULL ,
  183.  [TicketCollectorId] int NULL ,
  184.  [Justification]     varchar(3000) NOT NULL ,
  185.  [ArrivalDate]       timestamp NOT NULL ,
  186.  [ComplaintStatusId] int NOT NULL ,
  187.  CONSTRAINT PK_Complaint PRIMARY KEY NONCLUSTERED ([ComplaintId]),    
  188.  CONSTRAINT FK_Complaint_TicketCollector FOREIGN KEY ([ComplaintId])    
  189.     REFERENCES [TicketCollector] ([TicketCollectorId]),
  190. CONSTRAINT FK_Complaint_Person FOREIGN KEY ([ComplaintId])    
  191.     REFERENCES [Person] ([PersonId])      
  192. );
  193. GO
  194.  
  195.  
  196. EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'#1 - successfull
  197. #2 - pending
  198. #3 - rejected', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'Complaint', @level2type=N'COLUMN', @level2name=N'ComplaintStatusId';
  199. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement