Skip to content

Commit fc32c50

Browse files
SQL Server deployment (#21)
1 parent c9edc53 commit fc32c50

40 files changed

+762
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,4 @@ $RECYCLE.BIN/
440440
!.vscode/tasks.json
441441
!.vscode/launch.json
442442
!.vscode/extensions.json
443+
.vscode/settings.json

examples/dotnetcore/azure-pipelines.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
# ref: refs/heads/main
1010

1111
trigger:
12-
- main
13-
- feature/*
12+
branches:
13+
include:
14+
- main
15+
paths:
16+
include:
17+
- examples/dotnetcore
1418

1519
pool:
1620
vmImage: 'windows-latest'
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# If you are using this example in your oun repository,
2+
# you need to uncomment the lines below:
3+
# resources:
4+
# repositories:
5+
# - repository: UDP
6+
# type: github
7+
# endpoint: devopsnights
8+
# name: devopsnights/UDP
9+
# ref: refs/heads/main
10+
11+
trigger:
12+
- main
13+
- feature/*
14+
15+
# trigger:
16+
# branches:
17+
# include:
18+
# - main
19+
# - feature/*
20+
# paths:
21+
# include:
22+
# - examples/sqlserver
23+
24+
pool:
25+
vmImage: 'windows-latest'
26+
27+
extends:
28+
# If you are using this example in your oun repository,
29+
# you need to uncomment the next line and comment the line streight below
30+
#template: src\orchestrator.yml@UDP
31+
template: ..\..\src\orchestrator.yml
32+
parameters:
33+
serviceConnection: 'AzureServiceConnection'
34+
environments:
35+
- dev
36+
# - uat
37+
# - prd
38+
configuration:
39+
buildOnly: false
40+
resources:
41+
- type: sqlserver
42+
enabled: true
43+
solutionFilter: '**\sql-template.sln'
44+
deployment:
45+
type: azureWebApp
46+
name: wa-udp-dotnetcore-windows
47+
infrastructure:
48+
enabled: false
49+
application:
50+
enabled: true
51+
serverName: 'sql-udp.database.windows.net'
52+
databaseName: 'sqludp'
53+
sqlUsername: 'wesley'
54+
sqlPassword: '$(sqlPassword)'
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30611.23
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "sql-template", "sql-template\sql-template.sqlproj", "{59966C8C-FC3B-4F2C-A750-479BE6BDE614}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{59966C8C-FC3B-4F2C-A750-479BE6BDE614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{59966C8C-FC3B-4F2C-A750-479BE6BDE614}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{59966C8C-FC3B-4F2C-A750-479BE6BDE614}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
17+
{59966C8C-FC3B-4F2C-A750-479BE6BDE614}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{59966C8C-FC3B-4F2C-A750-479BE6BDE614}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{59966C8C-FC3B-4F2C-A750-479BE6BDE614}.Release|Any CPU.Deploy.0 = Release|Any CPU
20+
EndGlobalSection
21+
GlobalSection(SolutionProperties) = preSolution
22+
HideSolutionNode = FALSE
23+
EndGlobalSection
24+
GlobalSection(ExtensibilityGlobals) = postSolution
25+
SolutionGuid = {39525544-4595-4F38-9233-0A3DAA1B2348}
26+
EndGlobalSection
27+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE SEQUENCE [SalesLT].[SalesOrderNumber]
2+
AS INT
3+
START WITH 1
4+
INCREMENT BY 1;
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TABLE [SalesLT].[Address] (
2+
[AddressID] INT IDENTITY (1, 1) NOT NULL,
3+
[AddressLine1] NVARCHAR (60) NOT NULL,
4+
[AddressLine2] NVARCHAR (60) NULL,
5+
[City] NVARCHAR (30) NOT NULL,
6+
[StateProvince] [dbo].[Name] NOT NULL,
7+
[CountryRegion] [dbo].[Name] NOT NULL,
8+
[PostalCode] NVARCHAR (15) NOT NULL,
9+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_Address_rowguid] DEFAULT (newid()) NOT NULL,
10+
[ModifiedDate] DATETIME CONSTRAINT [DF_Address_ModifiedDate] DEFAULT (getdate()) NOT NULL,
11+
CONSTRAINT [PK_Address_AddressID] PRIMARY KEY CLUSTERED ([AddressID] ASC),
12+
CONSTRAINT [AK_Address_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
13+
);
14+
15+
16+
GO
17+
CREATE NONCLUSTERED INDEX [IX_Address_AddressLine1_AddressLine2_City_StateProvince_PostalCode_CountryRegion]
18+
ON [SalesLT].[Address]([AddressLine1] ASC, [AddressLine2] ASC, [City] ASC, [StateProvince] ASC, [PostalCode] ASC, [CountryRegion] ASC);
19+
20+
21+
GO
22+
CREATE NONCLUSTERED INDEX [IX_Address_StateProvince]
23+
ON [SalesLT].[Address]([StateProvince] ASC);
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
CREATE TABLE [SalesLT].[Customer] (
2+
[CustomerID] INT IDENTITY (1, 1) NOT NULL,
3+
[NameStyle] [dbo].[NameStyle] CONSTRAINT [DF_Customer_NameStyle] DEFAULT ((0)) NOT NULL,
4+
[Title] NVARCHAR (8) NULL,
5+
[FirstName] [dbo].[Name] NOT NULL,
6+
[MiddleName] [dbo].[Name] NULL,
7+
[LastName] [dbo].[Name] NOT NULL,
8+
[Suffix] NVARCHAR (10) NULL,
9+
[CompanyName] NVARCHAR (128) NULL,
10+
[SalesPerson] NVARCHAR (256) NULL,
11+
[EmailAddress] NVARCHAR (50) NULL,
12+
[Phone] [dbo].[Phone] NULL,
13+
[PasswordHash] VARCHAR (128) NOT NULL,
14+
[PasswordSalt] VARCHAR (10) NOT NULL,
15+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_Customer_rowguid] DEFAULT (newid()) NOT NULL,
16+
[ModifiedDate] DATETIME CONSTRAINT [DF_Customer_ModifiedDate] DEFAULT (getdate()) NOT NULL,
17+
CONSTRAINT [PK_Customer_CustomerID] PRIMARY KEY CLUSTERED ([CustomerID] ASC),
18+
CONSTRAINT [AK_Customer_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
19+
);
20+
21+
22+
GO
23+
CREATE NONCLUSTERED INDEX [IX_Customer_EmailAddress]
24+
ON [SalesLT].[Customer]([EmailAddress] ASC);
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE TABLE [SalesLT].[CustomerAddress] (
2+
[CustomerID] INT NOT NULL,
3+
[AddressID] INT NOT NULL,
4+
[AddressType] [dbo].[Name] NOT NULL,
5+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_CustomerAddress_rowguid] DEFAULT (newid()) NOT NULL,
6+
[ModifiedDate] DATETIME CONSTRAINT [DF_CustomerAddress_ModifiedDate] DEFAULT (getdate()) NOT NULL,
7+
CONSTRAINT [PK_CustomerAddress_CustomerID_AddressID] PRIMARY KEY CLUSTERED ([CustomerID] ASC, [AddressID] ASC),
8+
CONSTRAINT [FK_CustomerAddress_Address_AddressID] FOREIGN KEY ([AddressID]) REFERENCES [SalesLT].[Address] ([AddressID]),
9+
CONSTRAINT [FK_CustomerAddress_Customer_CustomerID] FOREIGN KEY ([CustomerID]) REFERENCES [SalesLT].[Customer] ([CustomerID]),
10+
CONSTRAINT [AK_CustomerAddress_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
11+
);
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE [SalesLT].[NewTable] (
2+
[ID] INT IDENTITY (1, 1) NOT NULL,
3+
[Title] NVARCHAR (8) NULL,
4+
);
5+
6+
7+
GO
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CREATE TABLE [SalesLT].[Product] (
2+
[ProductID] INT IDENTITY (1, 1) NOT NULL,
3+
[Name] [dbo].[Name] NOT NULL,
4+
[ProductNumber] NVARCHAR (25) NOT NULL,
5+
[Color] NVARCHAR (15) NULL,
6+
[StandardCost] MONEY NOT NULL,
7+
[ListPrice] MONEY NOT NULL,
8+
[Size] NVARCHAR (5) NULL,
9+
[Weight] DECIMAL (8, 2) NULL,
10+
[ProductCategoryID] INT NULL,
11+
[ProductModelID] INT NULL,
12+
[SellStartDate] DATETIME NOT NULL,
13+
[SellEndDate] DATETIME NULL,
14+
[DiscontinuedDate] DATETIME NULL,
15+
[ThumbNailPhoto] VARBINARY (MAX) NULL,
16+
[ThumbnailPhotoFileName] NVARCHAR (50) NULL,
17+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_Product_rowguid] DEFAULT (newid()) NOT NULL,
18+
[ModifiedDate] DATETIME CONSTRAINT [DF_Product_ModifiedDate] DEFAULT (getdate()) NOT NULL,
19+
CONSTRAINT [PK_Product_ProductID] PRIMARY KEY CLUSTERED ([ProductID] ASC),
20+
CONSTRAINT [CK_Product_ListPrice] CHECK ([ListPrice]>=(0.00)),
21+
CONSTRAINT [CK_Product_SellEndDate] CHECK ([SellEndDate]>=[SellStartDate] OR [SellEndDate] IS NULL),
22+
CONSTRAINT [CK_Product_StandardCost] CHECK ([StandardCost]>=(0.00)),
23+
CONSTRAINT [CK_Product_Weight] CHECK ([Weight]>(0.00)),
24+
CONSTRAINT [FK_Product_ProductCategory_ProductCategoryID] FOREIGN KEY ([ProductCategoryID]) REFERENCES [SalesLT].[ProductCategory] ([ProductCategoryID]),
25+
CONSTRAINT [FK_Product_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [SalesLT].[ProductModel] ([ProductModelID]),
26+
CONSTRAINT [AK_Product_Name] UNIQUE NONCLUSTERED ([Name] ASC),
27+
CONSTRAINT [AK_Product_ProductNumber] UNIQUE NONCLUSTERED ([ProductNumber] ASC),
28+
CONSTRAINT [AK_Product_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
29+
);
30+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE TABLE [SalesLT].[ProductCategory] (
2+
[ProductCategoryID] INT IDENTITY (1, 1) NOT NULL,
3+
[ParentProductCategoryID] INT NULL,
4+
[Name] [dbo].[Name] NOT NULL,
5+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_ProductCategory_rowguid] DEFAULT (newid()) NOT NULL,
6+
[ModifiedDate] DATETIME CONSTRAINT [DF_ProductCategory_ModifiedDate] DEFAULT (getdate()) NOT NULL,
7+
CONSTRAINT [PK_ProductCategory_ProductCategoryID] PRIMARY KEY CLUSTERED ([ProductCategoryID] ASC),
8+
CONSTRAINT [FK_ProductCategory_ProductCategory_ParentProductCategoryID_ProductCategoryID] FOREIGN KEY ([ParentProductCategoryID]) REFERENCES [SalesLT].[ProductCategory] ([ProductCategoryID]),
9+
CONSTRAINT [AK_ProductCategory_Name] UNIQUE NONCLUSTERED ([Name] ASC),
10+
CONSTRAINT [AK_ProductCategory_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
11+
);
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CREATE TABLE [SalesLT].[ProductDescription] (
2+
[ProductDescriptionID] INT IDENTITY (1, 1) NOT NULL,
3+
[Description] NVARCHAR (400) NOT NULL,
4+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_ProductDescription_rowguid] DEFAULT (newid()) NOT NULL,
5+
[ModifiedDate] DATETIME CONSTRAINT [DF_ProductDescription_ModifiedDate] DEFAULT (getdate()) NOT NULL,
6+
CONSTRAINT [PK_ProductDescription_ProductDescriptionID] PRIMARY KEY CLUSTERED ([ProductDescriptionID] ASC),
7+
CONSTRAINT [AK_ProductDescription_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
8+
);
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE [SalesLT].[ProductModel] (
2+
[ProductModelID] INT IDENTITY (1, 1) NOT NULL,
3+
[Name] [dbo].[Name] NOT NULL,
4+
[CatalogDescription] XML NULL,
5+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_ProductModel_rowguid] DEFAULT (newid()) NOT NULL,
6+
[ModifiedDate] DATETIME CONSTRAINT [DF_ProductModel_ModifiedDate] DEFAULT (getdate()) NOT NULL,
7+
CONSTRAINT [PK_ProductModel_ProductModelID] PRIMARY KEY CLUSTERED ([ProductModelID] ASC),
8+
CONSTRAINT [AK_ProductModel_Name] UNIQUE NONCLUSTERED ([Name] ASC),
9+
CONSTRAINT [AK_ProductModel_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
10+
);
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE TABLE [SalesLT].[ProductModelProductDescription] (
2+
[ProductModelID] INT NOT NULL,
3+
[ProductDescriptionID] INT NOT NULL,
4+
[Culture] NCHAR (6) NOT NULL,
5+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_ProductModelProductDescription_rowguid] DEFAULT (newid()) NOT NULL,
6+
[ModifiedDate] DATETIME CONSTRAINT [DF_ProductModelProductDescription_ModifiedDate] DEFAULT (getdate()) NOT NULL,
7+
CONSTRAINT [PK_ProductModelProductDescription_ProductModelID_ProductDescriptionID_Culture] PRIMARY KEY CLUSTERED ([ProductModelID] ASC, [ProductDescriptionID] ASC, [Culture] ASC),
8+
CONSTRAINT [FK_ProductModelProductDescription_ProductDescription_ProductDescriptionID] FOREIGN KEY ([ProductDescriptionID]) REFERENCES [SalesLT].[ProductDescription] ([ProductDescriptionID]),
9+
CONSTRAINT [FK_ProductModelProductDescription_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [SalesLT].[ProductModel] ([ProductModelID]),
10+
CONSTRAINT [AK_ProductModelProductDescription_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
11+
);
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
CREATE TABLE [SalesLT].[SalesOrderDetail] (
2+
[SalesOrderID] INT NOT NULL,
3+
[SalesOrderDetailID] INT IDENTITY (1, 1) NOT NULL,
4+
[OrderQty] SMALLINT NOT NULL,
5+
[ProductID] INT NOT NULL,
6+
[UnitPrice] MONEY NOT NULL,
7+
[UnitPriceDiscount] MONEY CONSTRAINT [DF_SalesOrderDetail_UnitPriceDiscount] DEFAULT ((0.0)) NOT NULL,
8+
[LineTotal] AS (isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0))),
9+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_SalesOrderDetail_rowguid] DEFAULT (newid()) NOT NULL,
10+
[ModifiedDate] DATETIME CONSTRAINT [DF_SalesOrderDetail_ModifiedDate] DEFAULT (getdate()) NOT NULL,
11+
CONSTRAINT [PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID] PRIMARY KEY CLUSTERED ([SalesOrderID] ASC, [SalesOrderDetailID] ASC),
12+
CONSTRAINT [CK_SalesOrderDetail_OrderQty] CHECK ([OrderQty]>(0)),
13+
CONSTRAINT [CK_SalesOrderDetail_UnitPrice] CHECK ([UnitPrice]>=(0.00)),
14+
CONSTRAINT [CK_SalesOrderDetail_UnitPriceDiscount] CHECK ([UnitPriceDiscount]>=(0.00)),
15+
CONSTRAINT [FK_SalesOrderDetail_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [SalesLT].[Product] ([ProductID]),
16+
CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID] FOREIGN KEY ([SalesOrderID]) REFERENCES [SalesLT].[SalesOrderHeader] ([SalesOrderID]) ON DELETE CASCADE,
17+
CONSTRAINT [AK_SalesOrderDetail_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC)
18+
);
19+
20+
21+
GO
22+
CREATE NONCLUSTERED INDEX [IX_SalesOrderDetail_ProductID]
23+
ON [SalesLT].[SalesOrderDetail]([ProductID] ASC);
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
CREATE TABLE [SalesLT].[SalesOrderHeader] (
2+
[SalesOrderID] INT CONSTRAINT [DF_SalesOrderHeader_OrderID] DEFAULT (NEXT VALUE FOR [SalesLT].[SalesOrderNumber]) NOT NULL,
3+
[RevisionNumber] TINYINT CONSTRAINT [DF_SalesOrderHeader_RevisionNumber] DEFAULT ((0)) NOT NULL,
4+
[OrderDate] DATETIME CONSTRAINT [DF_SalesOrderHeader_OrderDate] DEFAULT (getdate()) NOT NULL,
5+
[DueDate] DATETIME NOT NULL,
6+
[ShipDate] DATETIME NULL,
7+
[Status] TINYINT CONSTRAINT [DF_SalesOrderHeader_Status] DEFAULT ((1)) NOT NULL,
8+
[OnlineOrderFlag] [dbo].[Flag] CONSTRAINT [DF_SalesOrderHeader_OnlineOrderFlag] DEFAULT ((1)) NOT NULL,
9+
[SalesOrderNumber] AS (isnull(N'SO'+CONVERT([nvarchar](23),[SalesOrderID],(0)),N'*** ERROR ***')),
10+
[PurchaseOrderNumber] [dbo].[OrderNumber] NULL,
11+
[AccountNumber] [dbo].[AccountNumber] NULL,
12+
[CustomerID] INT NOT NULL,
13+
[ShipToAddressID] INT NULL,
14+
[BillToAddressID] INT NULL,
15+
[ShipMethod] NVARCHAR (50) NOT NULL,
16+
[CreditCardApprovalCode] VARCHAR (15) NULL,
17+
[SubTotal] MONEY CONSTRAINT [DF_SalesOrderHeader_SubTotal] DEFAULT ((0.00)) NOT NULL,
18+
[TaxAmt] MONEY CONSTRAINT [DF_SalesOrderHeader_TaxAmt] DEFAULT ((0.00)) NOT NULL,
19+
[Freight] MONEY CONSTRAINT [DF_SalesOrderHeader_Freight] DEFAULT ((0.00)) NOT NULL,
20+
[TotalDue] AS (isnull(([SubTotal]+[TaxAmt])+[Freight],(0))),
21+
[Comment] NVARCHAR (MAX) NULL,
22+
[rowguid] UNIQUEIDENTIFIER CONSTRAINT [DF_SalesOrderHeader_rowguid] DEFAULT (newid()) NOT NULL,
23+
[ModifiedDate] DATETIME CONSTRAINT [DF_SalesOrderHeader_ModifiedDate] DEFAULT (getdate()) NOT NULL,
24+
CONSTRAINT [PK_SalesOrderHeader_SalesOrderID] PRIMARY KEY CLUSTERED ([SalesOrderID] ASC),
25+
CONSTRAINT [CK_SalesOrderHeader_DueDate] CHECK ([DueDate]>=[OrderDate]),
26+
CONSTRAINT [CK_SalesOrderHeader_Freight] CHECK ([Freight]>=(0.00)),
27+
CONSTRAINT [CK_SalesOrderHeader_ShipDate] CHECK ([ShipDate]>=[OrderDate] OR [ShipDate] IS NULL),
28+
CONSTRAINT [CK_SalesOrderHeader_Status] CHECK ([Status]>=(0) AND [Status]<=(8)),
29+
CONSTRAINT [CK_SalesOrderHeader_SubTotal] CHECK ([SubTotal]>=(0.00)),
30+
CONSTRAINT [CK_SalesOrderHeader_TaxAmt] CHECK ([TaxAmt]>=(0.00)),
31+
CONSTRAINT [FK_SalesOrderHeader_Address_BillTo_AddressID] FOREIGN KEY ([BillToAddressID]) REFERENCES [SalesLT].[Address] ([AddressID]),
32+
CONSTRAINT [FK_SalesOrderHeader_Address_ShipTo_AddressID] FOREIGN KEY ([ShipToAddressID]) REFERENCES [SalesLT].[Address] ([AddressID]),
33+
CONSTRAINT [FK_SalesOrderHeader_Customer_CustomerID] FOREIGN KEY ([CustomerID]) REFERENCES [SalesLT].[Customer] ([CustomerID]),
34+
CONSTRAINT [AK_SalesOrderHeader_rowguid] UNIQUE NONCLUSTERED ([rowguid] ASC),
35+
CONSTRAINT [AK_SalesOrderHeader_SalesOrderNumber] UNIQUE NONCLUSTERED ([SalesOrderNumber] ASC)
36+
);
37+
38+
39+
GO
40+
CREATE NONCLUSTERED INDEX [IX_SalesOrderHeader_CustomerID]
41+
ON [SalesLT].[SalesOrderHeader]([CustomerID] ASC);
42+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE VIEW [SalesLT].[vGetAllCategories]
2+
WITH SCHEMABINDING
3+
AS
4+
-- Returns the CustomerID, first name, and last name for the specified customer.
5+
WITH CategoryCTE([ParentProductCategoryID], [ProductCategoryID], [Name]) AS
6+
(
7+
SELECT [ParentProductCategoryID], [ProductCategoryID], [Name]
8+
FROM SalesLT.ProductCategory
9+
WHERE ParentProductCategoryID IS NULL
10+
11+
UNION ALL
12+
13+
SELECT C.[ParentProductCategoryID], C.[ProductCategoryID], C.[Name]
14+
FROM SalesLT.ProductCategory AS C
15+
INNER JOIN CategoryCTE AS BC ON BC.ProductCategoryID = C.ParentProductCategoryID
16+
)
17+
18+
SELECT PC.[Name] AS [ParentProductCategoryName], CCTE.[Name] as [ProductCategoryName], CCTE.[ProductCategoryID]
19+
FROM CategoryCTE AS CCTE
20+
JOIN SalesLT.ProductCategory AS PC
21+
ON PC.[ProductCategoryID] = CCTE.[ParentProductCategoryID]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CREATE VIEW [SalesLT].[vProductAndDescription]
2+
WITH SCHEMABINDING
3+
AS
4+
-- View (indexed or standard) to display products and product descriptions by language.
5+
SELECT
6+
p.[ProductID]
7+
,p.[Name]
8+
,pm.[Name] AS [ProductModel]
9+
,pmx.[Culture]
10+
,pd.[Description]
11+
FROM [SalesLT].[Product] p
12+
INNER JOIN [SalesLT].[ProductModel] pm
13+
ON p.[ProductModelID] = pm.[ProductModelID]
14+
INNER JOIN [SalesLT].[ProductModelProductDescription] pmx
15+
ON pm.[ProductModelID] = pmx.[ProductModelID]
16+
INNER JOIN [SalesLT].[ProductDescription] pd
17+
ON pmx.[ProductDescriptionID] = pd.[ProductDescriptionID];
18+
19+
GO
20+
CREATE UNIQUE CLUSTERED INDEX [IX_vProductAndDescription]
21+
ON [SalesLT].[vProductAndDescription]([Culture] ASC, [ProductID] ASC);
22+

0 commit comments

Comments
 (0)