
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 11/12/2019 19:03:35
-- Generated from EDMX file: D:\@Dev\_\_Repo.ASPnix\simple-shop\Simple-Shop\Models\Models.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [simple-shop-0];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Items'
CREATE TABLE [dbo].[Items] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Info] nvarchar(max)  NULL,
    [ItemCategory_Id] int  NOT NULL,
    [PriceCategory_Id] int  NOT NULL,
    [DealItem_Id] int  NOT NULL
);
GO

-- Creating table 'ItemCategories'
CREATE TABLE [dbo].[ItemCategories] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Info] nvarchar(max)  NULL,
    [Tangibility] int  NOT NULL,
    [DealItem_Id] int  NOT NULL,
    [ItemCategoryImage_Id] int  NULL
);
GO

-- Creating table 'PriceCategories'
CREATE TABLE [dbo].[PriceCategories] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Info] nvarchar(max)  NULL
);
GO

-- Creating table 'PricePoints'
CREATE TABLE [dbo].[PricePoints] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Qty] float  NOT NULL,
    [Currency_Id] int  NOT NULL
);
GO

-- Creating table 'Deals'
CREATE TABLE [dbo].[Deals] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Info] nvarchar(max)  NOT NULL,
    [DateBegin] datetime  NOT NULL,
    [DateEnd] datetime  NULL
);
GO

-- Creating table 'DealItems'
CREATE TABLE [dbo].[DealItems] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Deal_Id] int  NOT NULL,
    [PriceCategory_Id] int  NULL
);
GO

-- Creating table 'ItemImages'
CREATE TABLE [dbo].[ItemImages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [ImageURL] nvarchar(max)  NULL,
    [Image] nvarchar(max)  NOT NULL,
    [Author] nvarchar(max)  NULL,
    [Items_Id] int  NULL
);
GO

-- Creating table 'Currencies'
CREATE TABLE [dbo].[Currencies] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [Info] nvarchar(max)  NULL,
    [CurrencyCategory_Id] int  NOT NULL
);
GO

-- Creating table 'CurrencyCategories'
CREATE TABLE [dbo].[CurrencyCategories] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [CurrencyCategoryImage_Id] int  NULL
);
GO

-- Creating table 'ItemCategoryImages'
CREATE TABLE [dbo].[ItemCategoryImages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [ImageURL] nvarchar(max)  NULL,
    [Image] varbinary(max)  NULL,
    [Author] nvarchar(max)  NULL
);
GO

-- Creating table 'CurrencyImages'
CREATE TABLE [dbo].[CurrencyImages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [ImageURL] nvarchar(max)  NULL,
    [Image] varbinary(max)  NULL,
    [Author] nvarchar(max)  NULL,
    [Currencies_Id] int  NULL
);
GO

-- Creating table 'CurrencyCategoryImages'
CREATE TABLE [dbo].[CurrencyCategoryImages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [ImageURL] nvarchar(max)  NULL,
    [Image] varbinary(max)  NULL,
    [Author] nvarchar(max)  NULL
);
GO

-- Creating table 'DealItemsPricePoints'
CREATE TABLE [dbo].[DealItemsPricePoints] (
    [DealItem_Id] int  NOT NULL,
    [PricePoints_Id] int  NOT NULL
);
GO

-- Creating table 'PriceCategoriesPricePoints'
CREATE TABLE [dbo].[PriceCategoriesPricePoints] (
    [PriceCategory_Id] int  NOT NULL,
    [PricePoints_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Items'
ALTER TABLE [dbo].[Items]
ADD CONSTRAINT [PK_Items]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ItemCategories'
ALTER TABLE [dbo].[ItemCategories]
ADD CONSTRAINT [PK_ItemCategories]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PriceCategories'
ALTER TABLE [dbo].[PriceCategories]
ADD CONSTRAINT [PK_PriceCategories]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PricePoints'
ALTER TABLE [dbo].[PricePoints]
ADD CONSTRAINT [PK_PricePoints]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Deals'
ALTER TABLE [dbo].[Deals]
ADD CONSTRAINT [PK_Deals]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DealItems'
ALTER TABLE [dbo].[DealItems]
ADD CONSTRAINT [PK_DealItems]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ItemImages'
ALTER TABLE [dbo].[ItemImages]
ADD CONSTRAINT [PK_ItemImages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Currencies'
ALTER TABLE [dbo].[Currencies]
ADD CONSTRAINT [PK_Currencies]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CurrencyCategories'
ALTER TABLE [dbo].[CurrencyCategories]
ADD CONSTRAINT [PK_CurrencyCategories]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ItemCategoryImages'
ALTER TABLE [dbo].[ItemCategoryImages]
ADD CONSTRAINT [PK_ItemCategoryImages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CurrencyImages'
ALTER TABLE [dbo].[CurrencyImages]
ADD CONSTRAINT [PK_CurrencyImages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CurrencyCategoryImages'
ALTER TABLE [dbo].[CurrencyCategoryImages]
ADD CONSTRAINT [PK_CurrencyCategoryImages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [DealItem_Id], [PricePoints_Id] in table 'DealItemsPricePoints'
ALTER TABLE [dbo].[DealItemsPricePoints]
ADD CONSTRAINT [PK_DealItemsPricePoints]
    PRIMARY KEY CLUSTERED ([DealItem_Id], [PricePoints_Id] ASC);
GO

-- Creating primary key on [PriceCategory_Id], [PricePoints_Id] in table 'PriceCategoriesPricePoints'
ALTER TABLE [dbo].[PriceCategoriesPricePoints]
ADD CONSTRAINT [PK_PriceCategoriesPricePoints]
    PRIMARY KEY CLUSTERED ([PriceCategory_Id], [PricePoints_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [ItemCategory_Id] in table 'Items'
ALTER TABLE [dbo].[Items]
ADD CONSTRAINT [FK_ItemCategoryItem]
    FOREIGN KEY ([ItemCategory_Id])
    REFERENCES [dbo].[ItemCategories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_ItemCategoryItem'
CREATE INDEX [IX_FK_ItemCategoryItem]
ON [dbo].[Items]
    ([ItemCategory_Id]);
GO

-- Creating foreign key on [PriceCategory_Id] in table 'Items'
ALTER TABLE [dbo].[Items]
ADD CONSTRAINT [FK_PriceCategoryItem]
    FOREIGN KEY ([PriceCategory_Id])
    REFERENCES [dbo].[PriceCategories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_PriceCategoryItem'
CREATE INDEX [IX_FK_PriceCategoryItem]
ON [dbo].[Items]
    ([PriceCategory_Id]);
GO

-- Creating foreign key on [Deal_Id] in table 'DealItems'
ALTER TABLE [dbo].[DealItems]
ADD CONSTRAINT [FK_DealsDealItems]
    FOREIGN KEY ([Deal_Id])
    REFERENCES [dbo].[Deals]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DealsDealItems'
CREATE INDEX [IX_FK_DealsDealItems]
ON [dbo].[DealItems]
    ([Deal_Id]);
GO

-- Creating foreign key on [DealItem_Id] in table 'Items'
ALTER TABLE [dbo].[Items]
ADD CONSTRAINT [FK_DealItemsItems]
    FOREIGN KEY ([DealItem_Id])
    REFERENCES [dbo].[DealItems]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DealItemsItems'
CREATE INDEX [IX_FK_DealItemsItems]
ON [dbo].[Items]
    ([DealItem_Id]);
GO

-- Creating foreign key on [PriceCategory_Id] in table 'DealItems'
ALTER TABLE [dbo].[DealItems]
ADD CONSTRAINT [FK_DealItemsPriceCategories]
    FOREIGN KEY ([PriceCategory_Id])
    REFERENCES [dbo].[PriceCategories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DealItemsPriceCategories'
CREATE INDEX [IX_FK_DealItemsPriceCategories]
ON [dbo].[DealItems]
    ([PriceCategory_Id]);
GO

-- Creating foreign key on [DealItem_Id] in table 'DealItemsPricePoints'
ALTER TABLE [dbo].[DealItemsPricePoints]
ADD CONSTRAINT [FK_DealItemsPricePoints_DealItems]
    FOREIGN KEY ([DealItem_Id])
    REFERENCES [dbo].[DealItems]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [PricePoints_Id] in table 'DealItemsPricePoints'
ALTER TABLE [dbo].[DealItemsPricePoints]
ADD CONSTRAINT [FK_DealItemsPricePoints_PricePoints]
    FOREIGN KEY ([PricePoints_Id])
    REFERENCES [dbo].[PricePoints]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DealItemsPricePoints_PricePoints'
CREATE INDEX [IX_FK_DealItemsPricePoints_PricePoints]
ON [dbo].[DealItemsPricePoints]
    ([PricePoints_Id]);
GO

-- Creating foreign key on [PriceCategory_Id] in table 'PriceCategoriesPricePoints'
ALTER TABLE [dbo].[PriceCategoriesPricePoints]
ADD CONSTRAINT [FK_PriceCategoriesPricePoints_PriceCategories]
    FOREIGN KEY ([PriceCategory_Id])
    REFERENCES [dbo].[PriceCategories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [PricePoints_Id] in table 'PriceCategoriesPricePoints'
ALTER TABLE [dbo].[PriceCategoriesPricePoints]
ADD CONSTRAINT [FK_PriceCategoriesPricePoints_PricePoints]
    FOREIGN KEY ([PricePoints_Id])
    REFERENCES [dbo].[PricePoints]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_PriceCategoriesPricePoints_PricePoints'
CREATE INDEX [IX_FK_PriceCategoriesPricePoints_PricePoints]
ON [dbo].[PriceCategoriesPricePoints]
    ([PricePoints_Id]);
GO

-- Creating foreign key on [DealItem_Id] in table 'ItemCategories'
ALTER TABLE [dbo].[ItemCategories]
ADD CONSTRAINT [FK_DealItemsItemCategories]
    FOREIGN KEY ([DealItem_Id])
    REFERENCES [dbo].[DealItems]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_DealItemsItemCategories'
CREATE INDEX [IX_FK_DealItemsItemCategories]
ON [dbo].[ItemCategories]
    ([DealItem_Id]);
GO

-- Creating foreign key on [Items_Id] in table 'ItemImages'
ALTER TABLE [dbo].[ItemImages]
ADD CONSTRAINT [FK_ImagesItems]
    FOREIGN KEY ([Items_Id])
    REFERENCES [dbo].[Items]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_ImagesItems'
CREATE INDEX [IX_FK_ImagesItems]
ON [dbo].[ItemImages]
    ([Items_Id]);
GO

-- Creating foreign key on [CurrencyCategory_Id] in table 'Currencies'
ALTER TABLE [dbo].[Currencies]
ADD CONSTRAINT [FK_CurrencyCategoryCurrencies]
    FOREIGN KEY ([CurrencyCategory_Id])
    REFERENCES [dbo].[CurrencyCategories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_CurrencyCategoryCurrencies'
CREATE INDEX [IX_FK_CurrencyCategoryCurrencies]
ON [dbo].[Currencies]
    ([CurrencyCategory_Id]);
GO

-- Creating foreign key on [Currency_Id] in table 'PricePoints'
ALTER TABLE [dbo].[PricePoints]
ADD CONSTRAINT [FK_PricePointsCurrencies]
    FOREIGN KEY ([Currency_Id])
    REFERENCES [dbo].[Currencies]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_PricePointsCurrencies'
CREATE INDEX [IX_FK_PricePointsCurrencies]
ON [dbo].[PricePoints]
    ([Currency_Id]);
GO

-- Creating foreign key on [ItemCategoryImage_Id] in table 'ItemCategories'
ALTER TABLE [dbo].[ItemCategories]
ADD CONSTRAINT [FK_ItemCategoryImageItemCategory]
    FOREIGN KEY ([ItemCategoryImage_Id])
    REFERENCES [dbo].[ItemCategoryImages]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_ItemCategoryImageItemCategory'
CREATE INDEX [IX_FK_ItemCategoryImageItemCategory]
ON [dbo].[ItemCategories]
    ([ItemCategoryImage_Id]);
GO

-- Creating foreign key on [CurrencyCategoryImage_Id] in table 'CurrencyCategories'
ALTER TABLE [dbo].[CurrencyCategories]
ADD CONSTRAINT [FK_CurrencyCategoryImageCurrencyCategory]
    FOREIGN KEY ([CurrencyCategoryImage_Id])
    REFERENCES [dbo].[CurrencyCategoryImages]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_CurrencyCategoryImageCurrencyCategory'
CREATE INDEX [IX_FK_CurrencyCategoryImageCurrencyCategory]
ON [dbo].[CurrencyCategories]
    ([CurrencyCategoryImage_Id]);
GO

-- Creating foreign key on [Currencies_Id] in table 'CurrencyImages'
ALTER TABLE [dbo].[CurrencyImages]
ADD CONSTRAINT [FK_CurrencyImageCurrency]
    FOREIGN KEY ([Currencies_Id])
    REFERENCES [dbo].[Currencies]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_CurrencyImageCurrency'
CREATE INDEX [IX_FK_CurrencyImageCurrency]
ON [dbo].[CurrencyImages]
    ([Currencies_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------