Advertisement
JanuszKowalski123

OZE - tylko tworzenie tabel

May 8th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Tworzenie tabeli urządzeń OZE
  2.  
  3. CREATE TABLE Renewable_Energy_Devices (
  4.     device_id NVARCHAR(26) PRIMARY KEY,
  5.     device_status INT CHECK (device_status >= 0 AND device_status <= 6),
  6.     device_power DECIMAL(18,0),
  7.     company_id INT
  8. );
  9.  
  10.  
  11. -- Tworzenie tabeli zgłoszeń awarii
  12.  
  13. CREATE TABLE Device_Failures (
  14.     failure_id INT PRIMARY KEY IDENTITY,
  15.     device_id NVARCHAR(26),
  16.     shift_number INT,
  17.     failure_start DATETIME,
  18.     failure_end DATETIME,
  19.     FOREIGN KEY (device_id) REFERENCES Renewable_Energy_Devices(device_id)
  20. );
  21.  
  22. -- Tworzenie tabeli klientów
  23.  
  24. CREATE TABLE Customers (
  25.     customer_id INT PRIMARY KEY,
  26.     name VARCHAR(255),
  27.     email VARCHAR(255),
  28.     phone VARCHAR(20),
  29.     address VARCHAR(255)
  30. );
  31.  
  32. -- Tworzenie tabeli zamówień
  33.  
  34. CREATE TABLE Customers_Orders (
  35.     customer_order_id INT PRIMARY KEY,
  36.     customer_id INT,
  37.     customer_order_date_start DATETIME,
  38.     customer_order_date_end DATETIME,
  39.     customer_order_amount_of_energy DECIMAL(18,0),
  40.     FOREIGN KEY (customer_id) REFERENCES Customers(customer_id)
  41. );
  42.  
  43.  
  44. -- Tworzenie tabeli firm serwisowych
  45.  
  46. CREATE TABLE Servicing_Companies (
  47.     company_id INT PRIMARY KEY,
  48.     name VARCHAR(255),
  49.     working_hours VARCHAR(255)
  50. );
  51.  
  52. -- Wstawianie danych do tabeli firm serwisowych
  53.  
  54. INSERT INTO Servicing_Companies (company_id, name, working_hours)
  55. VALUES (1, 'Company Y', '6:00-14:00, 14:00-22:00, 22:00-6:00');
  56.  
  57.  
  58. ----------
  59. ALTER TABLE dbo.Renewable_Energy_Devices
  60. ADD CONSTRAINT FK_OZE_SC FOREIGN KEY (company_id) REFERENCES Servicing_Companies(company_id);
  61. ----------
  62.  
  63. -- Tworzenie tabeli zmian serwisowych
  64.  
  65. CREATE TABLE Servicing_Shifts (
  66.     shift_number INT PRIMARY KEY IDENTITY,
  67.     shift_date DATE,
  68.     shift_type INT CHECK (shift_type >= 1 AND shift_type <= 3),
  69.     start_time TIME,
  70.     end_time TIME
  71. );
  72.  
  73.  
  74.  
  75. -- Tworzenie tabeli napraw
  76.  
  77.  CREATE TABLE Repairs (
  78.     repair_id INT PRIMARY KEY IDENTITY,
  79.     device_id NVARCHAR(26),
  80.     repair_start DATETIME,
  81.     repair_end DATETIME,
  82.     repair_description NVARCHAR(255),
  83.     FOREIGN KEY (device_id) REFERENCES Renewable_Energy_Devices(device_id)
  84. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement