-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/20/2011 09:47:54
-- Generated from EDMX file: E:\Job\projects\WebTest\EF\Model1.edmx
-- --------------------------------------------------
SET QUOTED_IDENTIFIER OFF;
GO
USE [SchoolDB];
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_ClassStudent]', 'F') IS NOT NULL
ALTER TABLE [dbo].[T_Student] DROP CONSTRAINT [FK_ClassStudent];
GO
IF OBJECT_ID(N'[dbo].[FK_ClassTeacher]', 'F') IS NOT NULL
ALTER TABLE [dbo].[T_Teacher] DROP CONSTRAINT [FK_ClassTeacher];
GO
-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------
IF OBJECT_ID(N'[dbo].[T_Class]', 'U') IS NOT NULL
DROP TABLE [dbo].[T_Class];
GO
IF OBJECT_ID(N'[dbo].[T_Student]', 'U') IS NOT NULL
DROP TABLE [dbo].[T_Student];
GO
IF OBJECT_ID(N'[dbo].[T_Teacher]', 'U') IS NOT NULL
DROP TABLE [dbo].[T_Teacher];
GO
-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------
-- Creating table 'T_Class'
CREATE TABLE [dbo].[T_Class] (
[ID] int IDENTITY(1,1) NOT NULL,
[Name] nvarchar(max) NOT NULL
);
GO
-- Creating table 'T_Student'
CREATE TABLE [dbo].[T_Student] (
[ID] uniqueidentifier NOT NULL,
[Name] nvarchar(max) NOT NULL,
[ClassID] int NOT NULL,
[Phone] nvarchar(max) NOT NULL,
[Email] nvarchar(max) NOT NULL
);
GO
-- Creating table 'T_Teacher'
CREATE TABLE [dbo].[T_Teacher] (
[ID] int IDENTITY(1,1) NOT NULL,
[Name] nvarchar(max) NOT NULL,
[Address] nvarchar(max) NOT NULL,
[Phone] nvarchar(max) NOT NULL,
[Email] nvarchar(max) NOT NULL,
[ClassID] int NOT NULL
);
GO
-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------
-- Creating primary key on [ID] in table 'T_Class'
ALTER TABLE [dbo].[T_Class]
ADD CONSTRAINT [PK_T_Class]
PRIMARY KEY CLUSTERED ([ID] ASC);
GO
-- Creating primary key on [ID] in table 'T_Student'
ALTER TABLE [dbo].[T_Student]
ADD CONSTRAINT [PK_T_Student]
PRIMARY KEY CLUSTERED ([ID] ASC);
GO
-- Creating primary key on [ID] in table 'T_Teacher'
ALTER TABLE [dbo].[T_Teacher]
ADD CONSTRAINT [PK_T_Teacher]
PRIMARY KEY CLUSTERED ([ID] ASC);
GO
-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------
-- Creating foreign key on [ClassID] in table 'T_Student'
ALTER TABLE [dbo].[T_Student]
ADD CONSTRAINT [FK_ClassStudent]
FOREIGN KEY ([ClassID])
REFERENCES [dbo].[T_Class]
([ID])
ON DELETE NO ACTION ON UPDATE NO ACTION;
-- Creating non-clustered index for FOREIGN KEY 'FK_ClassStudent'
CREATE INDEX [IX_FK_ClassStudent]
ON [dbo].[T_Student]
([ClassID]);
GO
-- Creating foreign key on [ClassID] in table 'T_Teacher'
ALTER TABLE [dbo].[T_Teacher]
ADD CONSTRAINT [FK_ClassTeacher]
FOREIGN KEY ([ClassID])
REFERENCES [dbo].[T_Class]
([ID])
ON DELETE NO ACTION ON UPDATE NO ACTION;
-- Creating non-clustered index for FOREIGN KEY 'FK_ClassTeacher'
CREATE INDEX [IX_FK_ClassTeacher]
ON [dbo].[T_Teacher]
([ClassID]);
GO
-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------