Guest User

Untitled

a guest
Jul 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. CREATE TABLE Products
  2. (
  3. Id INT PRIMARY KEY,
  4. Name VARCHAR(255)
  5. );
  6.  
  7. CREATE TABLE AttributesDefinition
  8. (
  9. Id INT PRIMARY KEY,
  10. Name VARCHAR(255)
  11. );
  12.  
  13. CREATE TABLE Attributes
  14. (
  15. Id INT,
  16. Name VARCHAR(255),
  17. Value VARCHAR(255),
  18. DefinitionId INT FOREIGN KEY REFERENCES AttributesDefinition (Id),
  19. ProductId INT FOREIGN KEY REFERENCES Products (Id)
  20. );
  21.  
  22.  
  23. CREATE VIEW ProductsWithAttributesView AS
  24. SELECT p.Name AS Products
  25. ,ad.Name AS AttributeDefinition
  26. ,a.Name AS AttributeName
  27. ,a.Value AS AttributeValue
  28. FROM Products p
  29. INNER JOIN Attributes a ON p.Id = a.ProductId
  30. INNER JOIN AttributesDefinition ad ON ad.Id = a.DefinitionId;
  31.  
  32. SELECT * FROM ProductsWithAttributesView;
Add Comment
Please, Sign In to add comment