Db Schema

Oct 4, 2011 at 12:29 PM
Edited Oct 4, 2011 at 12:29 PM

This is the DB script (for SQL Server 2008) needed to run the app:

USE [master]
GO
/****** Object:  Database [Karhu]    Script Date: 10/04/2011 13:03:54 ******/
CREATE DATABASE [Karhu] ON  PRIMARY
( NAME = N'Karhu', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Karhu.mdf' , SIZE = 2304KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON
( NAME = N'Karhu_log', FILENAME = N'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\Karhu_log.LDF' , SIZE = 576KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [Karhu] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [Karhu].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [Karhu] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [Karhu] SET ANSI_NULLS OFF
GO
ALTER DATABASE [Karhu] SET ANSI_PADDING OFF
GO
ALTER DATABASE [Karhu] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [Karhu] SET ARITHABORT OFF
GO
ALTER DATABASE [Karhu] SET AUTO_CLOSE ON
GO
ALTER DATABASE [Karhu] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [Karhu] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [Karhu] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [Karhu] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [Karhu] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [Karhu] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [Karhu] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [Karhu] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [Karhu] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [Karhu] SET  ENABLE_BROKER
GO
ALTER DATABASE [Karhu] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [Karhu] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [Karhu] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [Karhu] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [Karhu] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [Karhu] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [Karhu] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [Karhu] SET  READ_WRITE
GO
ALTER DATABASE [Karhu] SET RECOVERY SIMPLE
GO
ALTER DATABASE [Karhu] SET  MULTI_USER
GO
ALTER DATABASE [Karhu] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [Karhu] SET DB_CHAINING OFF
GO
USE [Karhu]
GO
/****** Object:  Table [dbo].[Categories]    Script Date: 10/04/2011 13:03:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Categories](
    [Id] [int] NOT NULL,
    [Name] [nvarchar](100) NOT NULL,
    [Description] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_Categories] 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
/****** Object:  Table [dbo].[Products]    Script Date: 10/04/2011 13:03:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Products](
    [Id] [int] NOT NULL,
    [Name] [nvarchar](100) NOT NULL,
    [Description] [nvarchar](max) NOT NULL,
    [UnitPrice] [money] NOT NULL,
    [ValidTo] [smalldatetime] NOT NULL,
    [Category_Id] [int] NOT NULL,
 CONSTRAINT [PK_Products] 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
/****** Object:  ForeignKey [FK_Products_Categories]    Script Date: 10/04/2011 13:03:56 ******/
ALTER TABLE [dbo].[Products]  WITH CHECK ADD  CONSTRAINT [FK_Products_Categories] FOREIGN KEY([Category_Id])
REFERENCES [dbo].[Categories] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Products] CHECK CONSTRAINT [FK_Products_Categories]
GO

Oct 8, 2011 at 2:18 PM

Both tables must have Id as identity columns.