Skip to content

Commit

Permalink
Adding SSDT project based on the Northwind database, including INSERT.
Browse files Browse the repository at this point in the history
  • Loading branch information
daiplusplus committed May 28, 2018
1 parent ed8233b commit b8d6def
Show file tree
Hide file tree
Showing 42 changed files with 660 additions and 0 deletions.
20 changes: 20 additions & 0 deletions EF.Reverse.POCO.Generator.sln
Expand Up @@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "Northwind", "Northwind\Northwind.sqlproj", "{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -72,6 +74,24 @@ Global
{14C1FD62-34DB-49B9-B35A-B363398D0914}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{14C1FD62-34DB-49B9-B35A-B363398D0914}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{14C1FD62-34DB-49B9-B35A-B363398D0914}.Release|x86.ActiveCfg = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|x86.ActiveCfg = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|x86.Build.0 = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Debug|x86.Deploy.0 = Debug|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|Any CPU.Build.0 = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|Any CPU.Deploy.0 = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|Mixed Platforms.Deploy.0 = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|x86.ActiveCfg = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|x86.Build.0 = Release|Any CPU
{F36D34E5-2087-4A27-8974-EBBAD4DB6D96}.Release|x86.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file added Northwind/InsertData.sql
Binary file not shown.
112 changes: 112 additions & 0 deletions Northwind/Northwind.sqlproj
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<Name>Northwind</Name>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>4.1</ProjectVersion>
<ProjectGuid>{f36d34e5-2087-4a27-8974-ebbad4db6d96}</ProjectGuid>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider</DSP>
<OutputType>Database</OutputType>
<RootPath>
</RootPath>
<RootNamespace>Northwind</RootNamespace>
<AssemblyName>Northwind</AssemblyName>
<ModelCollation>1033,CI</ModelCollation>
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
<DeployToDatabase>True</DeployToDatabase>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetLanguage>CS</TargetLanguage>
<AppDesignerFolder>Properties</AppDesignerFolder>
<SqlServerVerification>False</SqlServerVerification>
<IncludeCompositeObjects>True</IncludeCompositeObjects>
<TargetDatabaseSet>True</TargetDatabaseSet>
<DefaultCollation>SQL_Latin1_General_CP1_CI_AS</DefaultCollation>
<DefaultFilegroup>PRIMARY</DefaultFilegroup>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">11.0</VisualStudioVersion>
<!-- Default to the v11.0 targets path if the targets file for the current VS version is not found -->
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">11.0</VisualStudioVersion>
</PropertyGroup>
<Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
<Import Condition="'$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
<ItemGroup>
<Folder Include="Properties" />
<Folder Include="dbo\" />
<Folder Include="dbo\Tables\" />
<Folder Include="dbo\Views\" />
<Folder Include="dbo\Functions\" />
<Folder Include="dbo\Stored Procedures\" />
</ItemGroup>
<ItemGroup>
<Build Include="dbo\Tables\Orders.sql" />
<Build Include="dbo\Tables\Products.sql" />
<Build Include="dbo\Tables\Order Details.sql" />
<Build Include="dbo\Tables\CustomerCustomerDemo.sql" />
<Build Include="dbo\Tables\CustomerDemographics.sql" />
<Build Include="dbo\Tables\Region.sql" />
<Build Include="dbo\Tables\Territories.sql" />
<Build Include="dbo\Tables\EmployeeTerritories.sql" />
<Build Include="dbo\Tables\Employees.sql" />
<Build Include="dbo\Tables\Categories.sql" />
<Build Include="dbo\Tables\Customers.sql" />
<Build Include="dbo\Tables\Shippers.sql" />
<Build Include="dbo\Tables\Suppliers.sql" />
<Build Include="dbo\Views\Customer and Suppliers by City.sql" />
<Build Include="dbo\Views\Alphabetical list of products.sql" />
<Build Include="dbo\Views\Current Product List.sql" />
<Build Include="dbo\Views\Orders Qry.sql" />
<Build Include="dbo\Views\Products Above Average Price.sql" />
<Build Include="dbo\Views\Products by Category.sql" />
<Build Include="dbo\Views\Quarterly Orders.sql" />
<Build Include="dbo\Views\Invoices.sql" />
<Build Include="dbo\Views\Order Details Extended.sql" />
<Build Include="dbo\Views\Order Subtotals.sql" />
<Build Include="dbo\Views\Product Sales for 1997.sql" />
<Build Include="dbo\Views\Category Sales for 1997.sql" />
<Build Include="dbo\Views\Sales by Category.sql" />
<Build Include="dbo\Views\Sales Totals by Amount.sql" />
<Build Include="dbo\Views\Summary of Sales by Quarter.sql" />
<Build Include="dbo\Views\Summary of Sales by Year.sql" />
<Build Include="dbo\Functions\TotalProductUnitPriceByCategory.sql" />
<Build Include="dbo\Functions\MinUnitPriceByCategory.sql" />
<Build Include="dbo\Functions\ProductsUnderThisUnitPrice.sql" />
<Build Include="dbo\Stored Procedures\Ten Most Expensive Products.sql" />
<Build Include="dbo\Stored Procedures\Employee Sales by Country.sql" />
<Build Include="dbo\Stored Procedures\Sales by Year.sql" />
<Build Include="dbo\Stored Procedures\CustOrdersDetail.sql" />
<Build Include="dbo\Stored Procedures\CustOrdersOrders.sql" />
<Build Include="dbo\Stored Procedures\CustOrderHist.sql" />
<Build Include="dbo\Stored Procedures\SalesByCategory.sql" />
<PostDeploy Include="InsertData.sql">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</PostDeploy>
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions Northwind/dbo/Functions/MinUnitPriceByCategory.sql
@@ -0,0 +1,17 @@

CREATE FUNCTION [dbo].[MinUnitPriceByCategory]
(@categoryID INT
)
RETURNS Money
AS
BEGIN
-- Declare the return variable here
DECLARE @ResultVar Money

-- Add the T-SQL statements to compute the return value here
SELECT @ResultVar = MIN(p.UnitPrice) FROM Products as p WHERE p.CategoryID = @categoryID

-- Return the result of the function
RETURN @ResultVar

END
14 changes: 14 additions & 0 deletions Northwind/dbo/Functions/ProductsUnderThisUnitPrice.sql
@@ -0,0 +1,14 @@



CREATE FUNCTION [dbo].[ProductsUnderThisUnitPrice]
(@price Money
)
RETURNS TABLE
AS
RETURN
SELECT *
FROM Products as P
Where p.UnitPrice < @price


22 changes: 22 additions & 0 deletions Northwind/dbo/Functions/TotalProductUnitPriceByCategory.sql
@@ -0,0 +1,22 @@



CREATE FUNCTION [dbo].[TotalProductUnitPriceByCategory]
(@categoryID int)
RETURNS Money
AS
BEGIN
-- Declare the return variable here
DECLARE @ResultVar Money

-- Add the T-SQL statements to compute the return value here
SELECT @ResultVar = (Select SUM(UnitPrice)
from Products
where CategoryID = @categoryID)

-- Return the result of the function
RETURN @ResultVar

END


7 changes: 7 additions & 0 deletions Northwind/dbo/Stored Procedures/CustOrderHist.sql
@@ -0,0 +1,7 @@
CREATE PROCEDURE CustOrderHist @CustomerID nchar(5)
AS
SELECT ProductName, Total=SUM(Quantity)
FROM Products P, [Order Details] OD, Orders O, Customers C
WHERE C.CustomerID = @CustomerID
AND C.CustomerID = O.CustomerID AND O.OrderID = OD.OrderID AND OD.ProductID = P.ProductID
GROUP BY ProductName
10 changes: 10 additions & 0 deletions Northwind/dbo/Stored Procedures/CustOrdersDetail.sql
@@ -0,0 +1,10 @@

CREATE PROCEDURE CustOrdersDetail @OrderID int
AS
SELECT ProductName,
UnitPrice=ROUND(Od.UnitPrice, 2),
Quantity,
Discount=CONVERT(int, Discount * 100),
ExtendedPrice=ROUND(CONVERT(money, Quantity * (1 - Discount) * Od.UnitPrice), 2)
FROM Products P, [Order Details] Od
WHERE Od.ProductID = P.ProductID and Od.OrderID = @OrderID
10 changes: 10 additions & 0 deletions Northwind/dbo/Stored Procedures/CustOrdersOrders.sql
@@ -0,0 +1,10 @@

CREATE PROCEDURE CustOrdersOrders @CustomerID nchar(5)
AS
SELECT OrderID,
OrderDate,
RequiredDate,
ShippedDate
FROM Orders
WHERE CustomerID = @CustomerID
ORDER BY OrderID
8 changes: 8 additions & 0 deletions Northwind/dbo/Stored Procedures/Employee Sales by Country.sql
@@ -0,0 +1,8 @@

create procedure "Employee Sales by Country"
@Beginning_Date DateTime, @Ending_Date DateTime AS
SELECT Employees.Country, Employees.LastName, Employees.FirstName, Orders.ShippedDate, Orders.OrderID, "Order Subtotals".Subtotal AS SaleAmount
FROM Employees INNER JOIN
(Orders INNER JOIN "Order Subtotals" ON Orders.OrderID = "Order Subtotals".OrderID)
ON Employees.EmployeeID = Orders.EmployeeID
WHERE Orders.ShippedDate Between @Beginning_Date And @Ending_Date
6 changes: 6 additions & 0 deletions Northwind/dbo/Stored Procedures/Sales by Year.sql
@@ -0,0 +1,6 @@

create procedure "Sales by Year"
@Beginning_Date DateTime, @Ending_Date DateTime AS
SELECT Orders.ShippedDate, Orders.OrderID, "Order Subtotals".Subtotal, DATENAME(yy,ShippedDate) AS Year
FROM Orders INNER JOIN "Order Subtotals" ON Orders.OrderID = "Order Subtotals".OrderID
WHERE Orders.ShippedDate Between @Beginning_Date And @Ending_Date
18 changes: 18 additions & 0 deletions Northwind/dbo/Stored Procedures/SalesByCategory.sql
@@ -0,0 +1,18 @@
CREATE PROCEDURE SalesByCategory
@CategoryName nvarchar(15), @OrdYear nvarchar(4) = '1998'
AS
IF @OrdYear != '1996' AND @OrdYear != '1997' AND @OrdYear != '1998'
BEGIN
SELECT @OrdYear = '1998'
END

SELECT ProductName,
TotalPurchase=ROUND(SUM(CONVERT(decimal(14,2), OD.Quantity * (1-OD.Discount) * OD.UnitPrice)), 0)
FROM [Order Details] OD, Orders O, Products P, Categories C
WHERE OD.OrderID = O.OrderID
AND OD.ProductID = P.ProductID
AND P.CategoryID = C.CategoryID
AND C.CategoryName = @CategoryName
AND SUBSTRING(CONVERT(nvarchar(22), O.OrderDate, 111), 1, 4) = @OrdYear
GROUP BY ProductName
ORDER BY ProductName
@@ -0,0 +1,6 @@

create procedure "Ten Most Expensive Products" AS
SET ROWCOUNT 10
SELECT Products.ProductName AS TenMostExpensiveProducts, Products.UnitPrice
FROM Products
ORDER BY Products.UnitPrice DESC
13 changes: 13 additions & 0 deletions Northwind/dbo/Tables/Categories.sql
@@ -0,0 +1,13 @@
CREATE TABLE [dbo].[Categories] (
[CategoryID] INT IDENTITY (1, 1) NOT NULL,
[CategoryName] NVARCHAR (15) NOT NULL,
[Description] NTEXT NULL,
[Picture] IMAGE NULL,
CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED ([CategoryID] ASC)
);


GO
CREATE NONCLUSTERED INDEX [CategoryName]
ON [dbo].[Categories]([CategoryName] ASC);

8 changes: 8 additions & 0 deletions Northwind/dbo/Tables/CustomerCustomerDemo.sql
@@ -0,0 +1,8 @@
CREATE TABLE [dbo].[CustomerCustomerDemo] (
[CustomerID] NCHAR (5) NOT NULL,
[CustomerTypeID] NCHAR (10) NOT NULL,
CONSTRAINT [PK_CustomerCustomerDemo] PRIMARY KEY NONCLUSTERED ([CustomerID] ASC, [CustomerTypeID] ASC),
CONSTRAINT [FK_CustomerCustomerDemo] FOREIGN KEY ([CustomerTypeID]) REFERENCES [dbo].[CustomerDemographics] ([CustomerTypeID]),
CONSTRAINT [FK_CustomerCustomerDemo_Customers] FOREIGN KEY ([CustomerID]) REFERENCES [dbo].[Customers] ([CustomerID])
);

6 changes: 6 additions & 0 deletions Northwind/dbo/Tables/CustomerDemographics.sql
@@ -0,0 +1,6 @@
CREATE TABLE [dbo].[CustomerDemographics] (
[CustomerTypeID] NCHAR (10) NOT NULL,
[CustomerDesc] NTEXT NULL,
CONSTRAINT [PK_CustomerDemographics] PRIMARY KEY NONCLUSTERED ([CustomerTypeID] ASC)
);

35 changes: 35 additions & 0 deletions Northwind/dbo/Tables/Customers.sql
@@ -0,0 +1,35 @@
CREATE TABLE [dbo].[Customers] (
[CustomerID] NCHAR (5) NOT NULL,
[CompanyName] NVARCHAR (40) NOT NULL,
[ContactName] NVARCHAR (30) NULL,
[ContactTitle] NVARCHAR (30) NULL,
[Address] NVARCHAR (60) NULL,
[City] NVARCHAR (15) NULL,
[Region] NVARCHAR (15) NULL,
[PostalCode] NVARCHAR (10) NULL,
[Country] NVARCHAR (15) NULL,
[Phone] NVARCHAR (24) NULL,
[Fax] NVARCHAR (24) NULL,
CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED ([CustomerID] ASC)
);


GO
CREATE NONCLUSTERED INDEX [City]
ON [dbo].[Customers]([City] ASC);


GO
CREATE NONCLUSTERED INDEX [CompanyName]
ON [dbo].[Customers]([CompanyName] ASC);


GO
CREATE NONCLUSTERED INDEX [PostalCode]
ON [dbo].[Customers]([PostalCode] ASC);


GO
CREATE NONCLUSTERED INDEX [Region]
ON [dbo].[Customers]([Region] ASC);

8 changes: 8 additions & 0 deletions Northwind/dbo/Tables/EmployeeTerritories.sql
@@ -0,0 +1,8 @@
CREATE TABLE [dbo].[EmployeeTerritories] (
[EmployeeID] INT NOT NULL,
[TerritoryID] NVARCHAR (20) NOT NULL,
CONSTRAINT [PK_EmployeeTerritories] PRIMARY KEY NONCLUSTERED ([EmployeeID] ASC, [TerritoryID] ASC),
CONSTRAINT [FK_EmployeeTerritories_Employees] FOREIGN KEY ([EmployeeID]) REFERENCES [dbo].[Employees] ([EmployeeID]),
CONSTRAINT [FK_EmployeeTerritories_Territories] FOREIGN KEY ([TerritoryID]) REFERENCES [dbo].[Territories] ([TerritoryID])
);

34 changes: 34 additions & 0 deletions Northwind/dbo/Tables/Employees.sql
@@ -0,0 +1,34 @@
CREATE TABLE [dbo].[Employees] (
[EmployeeID] INT IDENTITY (1, 1) NOT NULL,
[LastName] NVARCHAR (20) NOT NULL,
[FirstName] NVARCHAR (10) NOT NULL,
[Title] NVARCHAR (30) NULL,
[TitleOfCourtesy] NVARCHAR (25) NULL,
[BirthDate] DATETIME NULL,
[HireDate] DATETIME NULL,
[Address] NVARCHAR (60) NULL,
[City] NVARCHAR (15) NULL,
[Region] NVARCHAR (15) NULL,
[PostalCode] NVARCHAR (10) NULL,
[Country] NVARCHAR (15) NULL,
[HomePhone] NVARCHAR (24) NULL,
[Extension] NVARCHAR (4) NULL,
[Photo] IMAGE NULL,
[Notes] NTEXT NULL,
[ReportsTo] INT NULL,
[PhotoPath] NVARCHAR (255) NULL,
CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED ([EmployeeID] ASC),
CONSTRAINT [CK_Birthdate] CHECK ([BirthDate] < getdate()),
CONSTRAINT [FK_Employees_Employees] FOREIGN KEY ([ReportsTo]) REFERENCES [dbo].[Employees] ([EmployeeID])
);


GO
CREATE NONCLUSTERED INDEX [LastName]
ON [dbo].[Employees]([LastName] ASC);


GO
CREATE NONCLUSTERED INDEX [PostalCode]
ON [dbo].[Employees]([PostalCode] ASC);

0 comments on commit b8d6def

Please sign in to comment.