Skip to content

Instantly share code, notes, and snippets.

@mitch-b
Created January 4, 2015 16:14
Show Gist options
  • Save mitch-b/b49dc98a691b462a0684 to your computer and use it in GitHub Desktop.
Save mitch-b/b49dc98a691b462a0684 to your computer and use it in GitHub Desktop.
Web API OData Lab 1 Database Creation Script
CREATE DATABASE [WebAPIDemo]
GO
USE [WebAPIDemo]
GO
CREATE USER [WebAPIDemoUser] FOR LOGIN [WebAPIDemoUser] WITH DEFAULT_SCHEMA=[dbo]
GO
ALTER ROLE [db_datareader] ADD MEMBER [WebAPIDemoUser]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [WebAPIDemoUser]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Todos](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](100) NOT NULL,
[Description] [nvarchar](500) NOT NULL,
[DueDate] [datetime] NULL,
[CreatedOn] [datetime] NULL,
[CompletedOn] [datetime] NULL,
[Finished] [bit] NULL,
[CreatedBy] [varchar](50) NULL,
[CompletedBy] [varchar](50) NULL,
CONSTRAINT [PK_Todos] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Users](
[Id] [varchar](50) NOT NULL,
[Name] [varchar](200) NOT NULL,
[Email] [varchar](200) NULL,
[Active] [bit] NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Todos] WITH CHECK ADD CONSTRAINT [FK_Todos_Users_CompletedBy] FOREIGN KEY([CompletedBy])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[Todos] CHECK CONSTRAINT [FK_Todos_Users_CompletedBy]
GO
ALTER TABLE [dbo].[Todos] WITH CHECK ADD CONSTRAINT [FK_Todos_Users_CreatedBy] FOREIGN KEY([CreatedBy])
REFERENCES [dbo].[Users] ([Id])
GO
ALTER TABLE [dbo].[Todos] CHECK CONSTRAINT [FK_Todos_Users_CreatedBy]
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment