��CREATE DATABASE [TutorialDatabase]

GO



USE [TutorialDatabase]

GO



SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Project](

	[ID] [int] IDENTITY(1,1) NOT NULL,

	[Code] [nvarchar](25) NOT NULL,

	[Name] [nvarchar](200) NOT NULL,

	[BeginDate] [date] NOT NULL,

	[EndDate] [date] NULL,

 CONSTRAINT [PK_Project] PRIMARY KEY CLUSTERED 

(

	[ID] ASC

)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF)

)



GO



SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[Task](

	[ID] [int] IDENTITY(1,1) NOT NULL,

	[ProjectID] [int] NOT NULL,

	[Description] [nvarchar](250) NOT NULL,

	[Completed] [bit] NOT NULL,

 CONSTRAINT [PK_Task] PRIMARY KEY CLUSTERED 

(

	[ID] ASC

)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF)

)



GO

SET ANSI_PADDING ON



GO



CREATE UNIQUE NONCLUSTERED INDEX [IX_Project] ON [dbo].[Project]

(

	[Code] ASC

)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF)

GO

ALTER TABLE [dbo].[Task]  WITH CHECK ADD  CONSTRAINT [FK_Task_Project] FOREIGN KEY([ProjectID])

REFERENCES [dbo].[Project] ([ID])

GO

ALTER TABLE [dbo].[Task] CHECK CONSTRAINT [FK_Task_Project]

GO

