DROP TABLE IF EXISTS dbo.ProductProperty DROP TABLE IF EXISTS dbo.PropertyValue DROP TABLE IF EXISTS dbo.Product DROP TABLE IF EXISTS dbo.PropertyType
CREATE TABLE dbo.ProductProperty(
ProductID int NOT NULL, ProductPropertyID int IDENTITY(1,1) NOT NULL, PropertyTypeID int NULL, PropertyValueID int NULL, PropertyValue varchar(200) NULL, CONSTRAINT PK_ProductProperty PRIMARY KEY CLUSTERED (ProductID, ProductPropertyID)) GO
CREATE TABLE dbo.PropertyValue(
PropertyValueID int IDENTITY(1,1) NOT NULL, PropertyValue varchar(100) NOT NULL, PropertyValueE varchar(100) NULL, PropertyTypeID int NULL, CONSTRAINT PK_PropertyValue PRIMARY KEY CLUSTERED (PropertyValueID)) GO
CREATE TABLE dbo.Product(
ProductID int IDENTITY(1,1) NOT NULL, ProductName varchar(200) NOT NULL, ProductNameE varchar(200) NULL, ProductNumber varchar(20) NULL, ListPrice money NULL, CONSTRAINT PK_Product PRIMARY KEY CLUSTERED (ProductID)) GO
CREATE TABLE dbo.PropertyType(
PropertyTypeID int IDENTITY(1,1) NOT NULL, PropertyTypeName varchar(100) NOT NULL, PropertyTypeNameE varchar(100) NULL, ParentPropertyID int NULL, PropertyDateType varchar(20) NULL, MeasureCode varchar(10) NULL, FromValue int NULL, ToValue int NULL) GO
CREATE VIEW dbo.vProduct AS
SELECT P.*, PPT.PropertyTypeName ParentPropertyTypeName, PT.PropertyTypeName, COALESCE(PP.PropertyValue + COALESCE(' ' + PT.MeasureCode,''), PV.PropertyValue) Property FROM Product P LEFT JOIN ProductProperty PP ON P.ProductID = PP.ProductID LEFT JOIN PropertyType PT ON PP.PropertyTypeID = PT.PropertyTypeID LEFT JOIN PropertyType PPT ON PT.ParentPropertyID = PPT.PropertyTypeID LEFT JOIN PropertyValue PV ON PP.PropertyValueID = PV.PropertyValueID GO SET IDENTITY_INSERT dbo.Product ON INSERT dbo.Product (ProductID, ProductName, ProductNameE, ProductNumber, ListPrice) VALUES (1, N'Whirlpool FFL6238WEE elöltöltős mosógép, 6kg, A+++', NULL, N'FFL 6238 W EE', 119890.0000) INSERT dbo.Product (ProductID, ProductName, ProductNameE, ProductNumber, ListPrice) VALUES (2, N'Samsung LC24F390FHRXEN Ívelt Gaming monitor LED VA 24",1800R, Full HD, FreeSync, Flicker Free, HDMI, Slim, Fekete', NULL, N'LC24F390FHRXEN', 47990.0000) SET IDENTITY_INSERT dbo.Product OFF GO