
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/31/2011 15:08:13
-- Generated from EDMX file: D:\subversion\OpenEarthTools\WmsNameService\WNS.DAL\Model\WMSNamingService.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [WMSNamingService];
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_OrganizationDevision]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Devisions] DROP CONSTRAINT [FK_OrganizationDevision];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationContact]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contacts] DROP CONSTRAINT [FK_OrganizationContact];
GO
IF OBJECT_ID(N'[dbo].[FK_DevisionContact]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contacts] DROP CONSTRAINT [FK_DevisionContact];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationContactInformation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContactInformationSet] DROP CONSTRAINT [FK_OrganizationContactInformation];
GO
IF OBJECT_ID(N'[dbo].[FK_DevisionContactInformation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContactInformationSet] DROP CONSTRAINT [FK_DevisionContactInformation];
GO
IF OBJECT_ID(N'[dbo].[FK_ContactContactInformation]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ContactInformationSet] DROP CONSTRAINT [FK_ContactContactInformation];
GO
IF OBJECT_ID(N'[dbo].[FK_WebMapServiceOrganization]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[WebMapServices] DROP CONSTRAINT [FK_WebMapServiceOrganization];
GO
IF OBJECT_ID(N'[dbo].[FK_WebMapServiceKeywordList]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[KeywordLists] DROP CONSTRAINT [FK_WebMapServiceKeywordList];
GO

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

IF OBJECT_ID(N'[dbo].[Organizations]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Organizations];
GO
IF OBJECT_ID(N'[dbo].[Devisions]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Devisions];
GO
IF OBJECT_ID(N'[dbo].[Contacts]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contacts];
GO
IF OBJECT_ID(N'[dbo].[ContactInformationSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ContactInformationSet];
GO
IF OBJECT_ID(N'[dbo].[WebMapServices]', 'U') IS NOT NULL
    DROP TABLE [dbo].[WebMapServices];
GO
IF OBJECT_ID(N'[dbo].[KeywordLists]', 'U') IS NOT NULL
    DROP TABLE [dbo].[KeywordLists];
GO

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

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

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

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

-- Creating table 'ContactInformationSet'
CREATE TABLE [dbo].[ContactInformationSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Adres] nvarchar(max)  NOT NULL,
    [Postal] nvarchar(max)  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [Country] nvarchar(max)  NOT NULL,
    [Mail] nvarchar(max)  NOT NULL,
    [Telephone] nvarchar(max)  NOT NULL,
    [OrganizationId] int  NOT NULL,
    [DevisionId] int  NOT NULL,
    [ContactId] int  NOT NULL
);
GO

-- Creating table 'WebMapServices'
CREATE TABLE [dbo].[WebMapServices] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Abstract] nvarchar(max)  NOT NULL,
    [OnlineResource] nvarchar(max)  NOT NULL,
    [URL] nvarchar(max)  NOT NULL,
    [Organization_Id] int  NOT NULL
);
GO

-- Creating table 'KeywordLists'
CREATE TABLE [dbo].[KeywordLists] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Keyword] nvarchar(max)  NOT NULL,
    [WebMapServiceId] int  NOT NULL
);
GO

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

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

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

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

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

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

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

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

-- Creating foreign key on [OrganizationId] in table 'Devisions'
ALTER TABLE [dbo].[Devisions]
ADD CONSTRAINT [FK_OrganizationDevision]
    FOREIGN KEY ([OrganizationId])
    REFERENCES [dbo].[Organizations]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationDevision'
CREATE INDEX [IX_FK_OrganizationDevision]
ON [dbo].[Devisions]
    ([OrganizationId]);
GO

-- Creating foreign key on [OrganizationId] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [FK_OrganizationContact]
    FOREIGN KEY ([OrganizationId])
    REFERENCES [dbo].[Organizations]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationContact'
CREATE INDEX [IX_FK_OrganizationContact]
ON [dbo].[Contacts]
    ([OrganizationId]);
GO

-- Creating foreign key on [DevisionId] in table 'Contacts'
ALTER TABLE [dbo].[Contacts]
ADD CONSTRAINT [FK_DevisionContact]
    FOREIGN KEY ([DevisionId])
    REFERENCES [dbo].[Devisions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DevisionContact'
CREATE INDEX [IX_FK_DevisionContact]
ON [dbo].[Contacts]
    ([DevisionId]);
GO

-- Creating foreign key on [OrganizationId] in table 'ContactInformationSet'
ALTER TABLE [dbo].[ContactInformationSet]
ADD CONSTRAINT [FK_OrganizationContactInformation]
    FOREIGN KEY ([OrganizationId])
    REFERENCES [dbo].[Organizations]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationContactInformation'
CREATE INDEX [IX_FK_OrganizationContactInformation]
ON [dbo].[ContactInformationSet]
    ([OrganizationId]);
GO

-- Creating foreign key on [DevisionId] in table 'ContactInformationSet'
ALTER TABLE [dbo].[ContactInformationSet]
ADD CONSTRAINT [FK_DevisionContactInformation]
    FOREIGN KEY ([DevisionId])
    REFERENCES [dbo].[Devisions]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DevisionContactInformation'
CREATE INDEX [IX_FK_DevisionContactInformation]
ON [dbo].[ContactInformationSet]
    ([DevisionId]);
GO

-- Creating foreign key on [ContactId] in table 'ContactInformationSet'
ALTER TABLE [dbo].[ContactInformationSet]
ADD CONSTRAINT [FK_ContactContactInformation]
    FOREIGN KEY ([ContactId])
    REFERENCES [dbo].[Contacts]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContactContactInformation'
CREATE INDEX [IX_FK_ContactContactInformation]
ON [dbo].[ContactInformationSet]
    ([ContactId]);
GO

-- Creating foreign key on [Organization_Id] in table 'WebMapServices'
ALTER TABLE [dbo].[WebMapServices]
ADD CONSTRAINT [FK_WebMapServiceOrganization]
    FOREIGN KEY ([Organization_Id])
    REFERENCES [dbo].[Organizations]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WebMapServiceOrganization'
CREATE INDEX [IX_FK_WebMapServiceOrganization]
ON [dbo].[WebMapServices]
    ([Organization_Id]);
GO

-- Creating foreign key on [WebMapServiceId] in table 'KeywordLists'
ALTER TABLE [dbo].[KeywordLists]
ADD CONSTRAINT [FK_WebMapServiceKeywordList]
    FOREIGN KEY ([WebMapServiceId])
    REFERENCES [dbo].[WebMapServices]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_WebMapServiceKeywordList'
CREATE INDEX [IX_FK_WebMapServiceKeywordList]
ON [dbo].[KeywordLists]
    ([WebMapServiceId]);
GO

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