Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. USE [master]
  2. GO
  3.  
  4. CREATE DATABASE [Shop]
  5. GO
  6.  
  7. USE [Shop]
  8. GO
  9.  
  10. CREATE TABLE Promotions (
  11. Terms VARCHAR(320),
  12. Multiplier FLOAT(3),
  13. Availability VARCHAR(3),
  14. PromotionID int identity not null,
  15. PRIMARY KEY (PromotionID)
  16. );
  17. GO
  18.  
  19. CREATE TABLE Providers (
  20. FirmID int identity not null,
  21. Email VARCHAR(320),
  22. PhoneNumber char(12) not null,
  23. PRIMARY KEY (FirmID)
  24. );
  25. GO
  26.  
  27. CREATE TABLE Products (
  28. ProductName VARCHAR(320),
  29. ProductID int identity not null,
  30. Cost FLOAT(20),
  31. StorageInfo VARCHAR(140),
  32. ProductAmount int,
  33. Terms VARCHAR(320),
  34. PromotionID int,
  35. FirmID int not null,
  36. PRIMARY KEY (ProductID),
  37. FOREIGN KEY (FirmID) REFERENCES Providers(FirmID)
  38. );
  39. GO
  40.  
  41. CREATE TABLE Users (
  42. FullName VARCHAR(80),
  43. Email VARCHAR(320),
  44. PhoneNumber char(12) not null,
  45. UserID int identity not null,
  46. PRIMARY KEY (UserID)
  47. );
  48. GO
  49.  
  50. CREATE TABLE Orders (
  51. ExecutionStatus VARCHAR(20) not null,
  52. DeliveryInfo VARCHAR(100) not null,
  53. OrderDate DATETIME not null,
  54. OrderID int not null,
  55. UserID int not null,
  56. PRIMARY KEY (OrderID),
  57. FOREIGN KEY (UserID) REFERENCES Users(UserID)
  58. );
  59. GO
  60.  
  61. CREATE TABLE OrderDetailing (
  62.  
  63. TotalCost AS (Price * Quantity) PERSISTED,
  64. Quantity int not null,
  65. OrderID int,
  66. ProductID int,
  67. Price int not null,
  68. PRIMARY KEY (OrderID, ProductID),
  69. FOREIGN KEY (ProductID) REFERENCES Products(ProductID),
  70. FOREIGN KEY (OrderID) REFERENCES Orders(OrderID)
  71. );
  72. GO
  73.  
  74.  
  75. -- Providers
  76.  
  77. INSERT INTO Providers
  78. VALUES ('123@ms.ua','89995380535');
  79. GO
  80.  
  81. INSERT INTO Providers
  82. VALUES ('12321@mamamam.ua','89995380536');
  83. GO
  84.  
  85. INSERT INTO Providers
  86. VALUES ('123321123321123321@mamamam.ua','89995380537');
  87. GO
  88.  
  89. INSERT INTO Promotions
  90. VALUES ('If product is available for promotion then user gets 20% discount', '0.8', 'Yes');
  91. GO
  92.  
  93. INSERT INTO Promotions
  94. VALUES ('If product is available for promotion then user gets 40% discount', '0.6', 'No');
  95. GO
  96.  
  97. INSERT INTO Promotions
  98. VALUES ('If product is available for promotion then user gets 50% discount', '0.5', 'No');
  99. GO
  100.  
  101.  
  102. INSERT INTO Products
  103. VALUES ('Apple MacBook Air i5 1.6/8Gb/128Gb SSD Gold (MREE2RU/A)', '104990', 'Available', '8', 'Available for any promotions', '1', '1');
  104. GO
  105.  
  106. INSERT INTO Products
  107. VALUES ('Apple MacBook Air i5 1.6/8Gb/256Gb SSD Space Grey MRE92', '120990', 'Not available', '0', 'Available for any promotions', '1', '1');
  108. GO
  109.  
  110. INSERT INTO Products
  111. VALUES ('Apple MacBook Air 13 i5 1.8/8Gb/128SSD (MQD32RU/A)', '69790', 'Available', '6', 'Not available', '1', '1');
  112. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement