-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinitdb.sql
More file actions
67 lines (59 loc) · 1.87 KB
/
initdb.sql
File metadata and controls
67 lines (59 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
DROP DATABASE IF EXISTS [AdventureWorks]
GO
CREATE DATABASE [AdventureWorks]
GO
USE [AdventureWorks]
GO
CREATE SCHEMA [Production] AUTHORIZATION [dbo];
GO
CREATE TABLE [Production].[Product](
[ProductID] [int] IDENTITY (1, 1) NOT NULL PRIMARY KEY ,
[Name] [nvarchar](15) NOT NULL,
[ProductNumber] [nvarchar](25) NOT NULL,
[Color] [nvarchar](15) NULL,
[SafetyStockLevel] [smallint] NOT NULL,
[ReorderPoint] [smallint] NOT NULL,
[StandardCost] [money] NOT NULL,
[ListPrice] [money] NOT NULL,
[Size] [nvarchar](5) NULL,
[SizeUnitMeasureCode] [nchar](3) NULL,
[WeightUnitMeasureCode] [nchar](3) NULL,
[Weight] [decimal](8, 2) NULL,
[DaysToManufacture] [int] NOT NULL,
[ProductLine] [nchar](2) NULL,
[Class] [nchar](2) NULL,
[Style] [nchar](2) NULL,
[ProductSubcategoryID] [int] NULL,
[ProductModelID] [int] NULL,
[SellStartDate] [datetime] NOT NULL,
[SellEndDate] [datetime] NULL,
[DiscontinuedDate] [datetime] NULL
) ON [PRIMARY];
GO
CREATE TABLE [Production].[ProductCategory](
[ProductCategoryID] [int] IDENTITY (1, 1) NOT NULL PRIMARY KEY ,
[Name] [nvarchar](15) NOT NULL
) ON [PRIMARY];
GO
CREATE TABLE [Production].[ProductSubcategory](
[ProductSubcategoryID] [int] IDENTITY (1, 1) NOT NULL PRIMARY KEY ,
[ProductCategoryID] [int] NOT NULL,
[Name] [nvarchar](15) NOT NULL
) ON [PRIMARY];
GO
ALTER TABLE [Production].[ProductSubcategory] ADD
CONSTRAINT [FK_ProductSubcategory_ProductCategory_ProductCategoryID] FOREIGN KEY
(
[ProductCategoryID]
) REFERENCES [Production].[ProductCategory](
[ProductCategoryID]
);
GO
ALTER TABLE [Production].[Product] ADD
CONSTRAINT [FK_Product_ProductSubcategory_ProductSubcategoryID] FOREIGN KEY
(
[ProductSubcategoryID]
) REFERENCES [Production].[ProductSubcategory](
[ProductSubcategoryID]
);
GO