
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/02/2014 02:03:41
-- Generated from EDMX file: D:\root\yura\institute\!!!_asp_net_mvc\projects\scaffolding\ScaffoldingExample\ScaffoldingExample\Models\Model1.edmx
-- --------------------------------------------------

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

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

IF OBJECT_ID(N'[dbo].[FK_ProcessorComputer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Computers] DROP CONSTRAINT [FK_ProcessorComputer];
GO

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

IF OBJECT_ID(N'[dbo].[Processors]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Processors];
GO
IF OBJECT_ID(N'[dbo].[Computers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Computers];
GO
IF OBJECT_ID(N'[dbo].[Settings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Settings];
GO

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

-- Creating table 'Processors'
CREATE TABLE [dbo].[Processors] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ProcessorName] nvarchar(max)  NOT NULL,
    [Order] int  NULL
);
GO

-- Creating table 'Computers'
CREATE TABLE [dbo].[Computers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ComputerName] nvarchar(max)  NOT NULL,
    [HDD] int  NOT NULL,
    [UpgradeDate] datetime  NOT NULL,
    [ProcessorId] int  NOT NULL
);
GO

-- Creating table 'Settings'
CREATE TABLE [dbo].[Settings] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Key] nvarchar(max)  NOT NULL,
    [Value] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [VType] nvarchar(max)  NOT NULL
);
GO

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

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

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

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

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

-- Creating foreign key on [ProcessorId] in table 'Computers'
ALTER TABLE [dbo].[Computers]
ADD CONSTRAINT [FK_ProcessorComputer]
    FOREIGN KEY ([ProcessorId])
    REFERENCES [dbo].[Processors]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProcessorComputer'
CREATE INDEX [IX_FK_ProcessorComputer]
ON [dbo].[Computers]
    ([ProcessorId]);
GO

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