From c89080d7f70390b3cebf928a144f7899ce2bd8dd Mon Sep 17 00:00:00 2001 From: Marco von Ballmoos Date: Wed, 3 Feb 2021 08:17:20 +0100 Subject: [PATCH 1/5] Extend E2E Docker tests to verify all files The former test verified only the cache, which failed when the output changed, but it made it very difficult to see in the diff _why_ the test had failed and _why_ the cache snapshot had changed. This commit extends the test to verify the contents of each file to make it easier to see what effect a change had on the actual SQL output. --- .gitignore | 2 +- docker/index.spec.ts | 35 ++- .../_sql-database/cache.json} | 0 .../_sql-database/data/Person.AddressType.sql | 12 + .../_sql-database/data/Person.ContactType.sql | 26 ++ .../data/Person.CountryRegion.sql | 240 ++++++++++++++++++ .../data/Person.PhoneNumberType.sql | 9 + .../data/Purchasing.ShipMethod.sql | 11 + .../functions/dbo.ufnGetAccountingEndDate.sql | 10 + .../dbo.ufnGetAccountingStartDate.sql | 10 + .../dbo.ufnGetContactInformation.sql | 73 ++++++ .../dbo.ufnGetDocumentStatusText.sql | 21 ++ .../dbo.ufnGetProductDealerPrice.sql | 25 ++ .../functions/dbo.ufnGetProductListPrice.sql | 19 ++ .../dbo.ufnGetProductStandardCost.sql | 20 ++ .../dbo.ufnGetPurchaseOrderStatusText.sql | 22 ++ .../dbo.ufnGetSalesOrderStatusText.sql | 24 ++ .../functions/dbo.ufnGetStock.sql | 21 ++ .../functions/dbo.ufnLeadingZeros.sql | 18 ++ .../_sql-database/schemas/HumanResources.sql | 2 + .../_sql-database/schemas/Person.sql | 2 + .../_sql-database/schemas/Production.sql | 2 + .../_sql-database/schemas/Purchasing.sql | 2 + .../_sql-database/schemas/Sales.sql | 2 + .../_sql-database/schemas/dbo.sql | 2 + ...manResources.uspUpdateEmployeeHireInfo.sql | 46 ++++ .../HumanResources.uspUpdateEmployeeLogin.sql | 29 +++ ...esources.uspUpdateEmployeePersonalInfo.sql | 27 ++ .../dbo.uspGetBillOfMaterials.sql | 40 +++ .../dbo.uspGetEmployeeManagers.sql | 37 +++ .../dbo.uspGetManagerEmployees.sql | 37 +++ .../dbo.uspGetWhereUsedProductID.sql | 38 +++ .../stored-procedures/dbo.uspLogError.sql | 64 +++++ .../stored-procedures/dbo.uspPrintError.sql | 21 ++ .../dbo.uspSearchCandidateResumes.sql | 59 +++++ .../tables/HumanResources.Department.sql | 12 + .../tables/HumanResources.Employee.sql | 45 ++++ ...manResources.EmployeeDepartmentHistory.sql | 41 +++ .../HumanResources.EmployeePayHistory.sql | 20 ++ .../tables/HumanResources.JobCandidate.sql | 18 ++ .../tables/HumanResources.Shift.sql | 19 ++ .../_sql-database/tables/Person.Address.sql | 35 +++ .../tables/Person.AddressType.sql | 15 ++ .../tables/Person.BusinessEntity.sql | 11 + .../tables/Person.BusinessEntityAddress.sql | 42 +++ .../tables/Person.BusinessEntityContact.sql | 42 +++ .../tables/Person.ContactType.sql | 11 + .../tables/Person.CountryRegion.sql | 11 + .../tables/Person.EmailAddress.sql | 23 ++ .../_sql-database/tables/Person.Password.sql | 16 ++ .../_sql-database/tables/Person.Person.sql | 34 +++ .../tables/Person.PersonPhone.sql | 29 +++ .../tables/Person.PhoneNumberType.sql | 8 + .../tables/Person.StateProvince.sql | 37 +++ .../tables/Production.BillOfMaterials.sql | 42 +++ .../tables/Production.Culture.sql | 11 + .../tables/Production.Document.sql | 43 ++++ .../tables/Production.Illustration.sql | 8 + .../tables/Production.Location.sql | 13 + .../tables/Production.Product.sql | 63 +++++ .../tables/Production.ProductCategory.sql | 15 ++ .../tables/Production.ProductCostHistory.sql | 20 ++ .../tables/Production.ProductDescription.sql | 12 + .../tables/Production.ProductDocument.sql | 24 ++ .../tables/Production.ProductInventory.sql | 28 ++ .../Production.ProductListPriceHistory.sql | 20 ++ .../tables/Production.ProductModel.sql | 17 ++ .../Production.ProductModelIllustration.sql | 24 ++ ....ProductModelProductDescriptionCulture.sql | 32 +++ .../tables/Production.ProductPhoto.sql | 11 + .../tables/Production.ProductProductPhoto.sql | 25 ++ .../tables/Production.ProductReview.sql | 25 ++ .../tables/Production.ProductSubcategory.sql | 22 ++ .../tables/Production.ScrapReason.sql | 11 + .../tables/Production.TransactionHistory.sql | 29 +++ .../Production.TransactionHistoryArchive.sql | 23 ++ .../tables/Production.UnitMeasure.sql | 11 + .../tables/Production.WorkOrder.sql | 33 +++ .../tables/Production.WorkOrderRouting.sql | 37 +++ .../tables/Purchasing.ProductVendor.sql | 44 ++++ .../tables/Purchasing.PurchaseOrderDetail.sql | 35 +++ .../tables/Purchasing.PurchaseOrderHeader.sql | 42 +++ .../tables/Purchasing.ShipMethod.sql | 17 ++ .../tables/Purchasing.Vendor.sql | 22 ++ .../tables/Sales.CountryRegionCurrency.sql | 27 ++ .../_sql-database/tables/Sales.CreditCard.sql | 14 + .../_sql-database/tables/Sales.Currency.sql | 11 + .../tables/Sales.CurrencyRate.sql | 31 +++ .../_sql-database/tables/Sales.Customer.sql | 39 +++ .../tables/Sales.PersonCreditCard.sql | 24 ++ .../tables/Sales.SalesOrderDetail.sql | 44 ++++ .../tables/Sales.SalesOrderHeader.sql | 91 +++++++ .../Sales.SalesOrderHeaderSalesReason.sql | 24 ++ .../tables/Sales.SalesPerson.sql | 29 +++ .../tables/Sales.SalesPersonQuotaHistory.sql | 23 ++ .../tables/Sales.SalesReason.sql | 9 + .../tables/Sales.SalesTaxRate.sql | 27 ++ .../tables/Sales.SalesTerritory.sql | 27 ++ .../tables/Sales.SalesTerritoryHistory.sql | 31 +++ .../tables/Sales.ShoppingCartItem.sql | 23 ++ .../tables/Sales.SpecialOffer.sql | 19 ++ .../tables/Sales.SpecialOfferProduct.sql | 31 +++ .../_sql-database/tables/Sales.Store.sql | 29 +++ .../tables/dbo.AWBuildVersion.sql | 9 + .../_sql-database/tables/dbo.DatabaseLog.sql | 13 + .../_sql-database/tables/dbo.ErrorLog.sql | 14 + .../triggers/HumanResources.dEmployee.sql | 28 ++ .../triggers/Person.iuPerson.sql | 38 +++ .../triggers/Production.iWorkOrder.sql | 45 ++++ .../triggers/Production.uWorkOrder.sql | 46 ++++ .../triggers/Purchasing.dVendor.sql | 46 ++++ .../Purchasing.iPurchaseOrderDetail.sql | 58 +++++ .../Purchasing.uPurchaseOrderDetail.sql | 70 +++++ .../Purchasing.uPurchaseOrderHeader.sql | 39 +++ .../triggers/Sales.iduSalesOrderDetail.sql | 87 +++++++ .../triggers/Sales.uSalesOrderHeader.sql | 72 ++++++ .../_sql-database/types/dbo.AccountNumber.sql | 7 + .../_sql-database/types/dbo.Flag.sql | 7 + .../_sql-database/types/dbo.Name.sql | 7 + .../_sql-database/types/dbo.NameStyle.sql | 7 + .../_sql-database/types/dbo.OrderNumber.sql | 7 + .../_sql-database/types/dbo.Phone.sql | 7 + .../views/HumanResources.vEmployee.sql | 42 +++ .../HumanResources.vEmployeeDepartment.sql | 25 ++ ...anResources.vEmployeeDepartmentHistory.sql | 27 ++ .../views/HumanResources.vJobCandidate.sql | 39 +++ .../HumanResources.vJobCandidateEducation.sql | 35 +++ ...HumanResources.vJobCandidateEmployment.sql | 31 +++ .../views/Person.vAdditionalContactInfo.sql | 51 ++++ .../Person.vStateProvinceCountryRegion.sql | 18 ++ .../Production.vProductAndDescription.sql | 21 ++ ...uction.vProductModelCatalogDescription.sql | 65 +++++ .../Production.vProductModelInstructions.sql | 24 ++ .../views/Purchasing.vVendorWithAddresses.sql | 26 ++ .../views/Purchasing.vVendorWithContacts.sql | 31 +++ .../views/Sales.vIndividualCustomer.sql | 45 ++++ .../views/Sales.vPersonDemographics.sql | 36 +++ .../views/Sales.vSalesPerson.sql | 50 ++++ .../Sales.vSalesPersonSalesByFiscalYears.sql | 37 +++ .../views/Sales.vStoreWithAddresses.sql | 26 ++ .../views/Sales.vStoreWithContacts.sql | 31 +++ .../views/Sales.vStoreWithDemographics.sql | 29 +++ 142 files changed, 4080 insertions(+), 5 deletions(-) rename snapshots/{AdventureWorks2017.json => AdventureWorks2017/_sql-database/cache.json} (100%) create mode 100644 snapshots/AdventureWorks2017/_sql-database/data/Person.AddressType.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/data/Person.ContactType.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/data/Person.CountryRegion.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/data/Person.PhoneNumberType.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/data/Purchasing.ShipMethod.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetAccountingEndDate.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetAccountingStartDate.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetContactInformation.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetDocumentStatusText.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductDealerPrice.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductListPrice.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductStandardCost.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetPurchaseOrderStatusText.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetSalesOrderStatusText.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetStock.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnLeadingZeros.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/schemas/HumanResources.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/schemas/Person.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/schemas/Production.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/schemas/Purchasing.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/schemas/Sales.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/schemas/dbo.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeHireInfo.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeLogin.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeePersonalInfo.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetBillOfMaterials.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetEmployeeManagers.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetManagerEmployees.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetWhereUsedProductID.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspLogError.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspPrintError.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspSearchCandidateResumes.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Department.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Employee.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeePayHistory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.JobCandidate.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Shift.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.Address.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.AddressType.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntity.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityAddress.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityContact.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.ContactType.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.CountryRegion.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.EmailAddress.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.Password.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.Person.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.PersonPhone.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.PhoneNumberType.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Person.StateProvince.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.BillOfMaterials.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.Culture.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.Document.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.Illustration.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.Location.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.Product.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductCategory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductCostHistory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductDescription.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductDocument.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductInventory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductListPriceHistory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModel.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelIllustration.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductPhoto.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductProductPhoto.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductReview.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductSubcategory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.ScrapReason.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.TransactionHistory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.TransactionHistoryArchive.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.UnitMeasure.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrder.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrderRouting.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ProductVendor.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderDetail.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderHeader.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ShipMethod.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.Vendor.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.CountryRegionCurrency.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.CreditCard.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.Currency.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.CurrencyRate.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.Customer.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.PersonCreditCard.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderDetail.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeader.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeaderSalesReason.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPerson.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPersonQuotaHistory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesReason.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTaxRate.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTerritory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTerritoryHistory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.ShoppingCartItem.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SpecialOffer.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.SpecialOfferProduct.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/Sales.Store.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/dbo.AWBuildVersion.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/dbo.DatabaseLog.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/tables/dbo.ErrorLog.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/HumanResources.dEmployee.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Person.iuPerson.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Production.iWorkOrder.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Production.uWorkOrder.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.dVendor.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.iPurchaseOrderDetail.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.uPurchaseOrderDetail.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.uPurchaseOrderHeader.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Sales.iduSalesOrderDetail.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/triggers/Sales.uSalesOrderHeader.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/types/dbo.AccountNumber.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/types/dbo.Flag.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/types/dbo.Name.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/types/dbo.NameStyle.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/types/dbo.OrderNumber.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/types/dbo.Phone.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployee.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployeeDepartment.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployeeDepartmentHistory.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidate.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidateEducation.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidateEmployment.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Person.vAdditionalContactInfo.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Person.vStateProvinceCountryRegion.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Production.vProductAndDescription.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Production.vProductModelCatalogDescription.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Production.vProductModelInstructions.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Purchasing.vVendorWithAddresses.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Purchasing.vVendorWithContacts.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Sales.vIndividualCustomer.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Sales.vPersonDemographics.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Sales.vSalesPerson.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Sales.vSalesPersonSalesByFiscalYears.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithAddresses.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithContacts.sql create mode 100644 snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithDemographics.sql diff --git a/.gitignore b/.gitignore index 6d6ddaa..e62e94c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ # Other *.bak coverage/ -_sql-database/ +/_sql-database/ dist/ node_modules/ ssc.json diff --git a/docker/index.spec.ts b/docker/index.spec.ts index fb6218e..2468efc 100644 --- a/docker/index.spec.ts +++ b/docker/index.spec.ts @@ -1,8 +1,35 @@ -const snapshot = require('../snapshots/AdventureWorks2017.json'); -const cache = require('../_sql-database/cache.json'); +import { readFileSync, statSync } from 'fs-extra'; +import { glob } from 'glob'; describe('docker', () => { - it('cache should match snapshot', () => { - expect(cache).toEqual(snapshot); + it('file contents should match snapshots', () => { + const getAllFilenames = (folder: string): string[] => { + return glob.sync(folder + '**/*'); + }; + + const snapshots = getAllFilenames( + 'snapshots/AdventureWorks2017/_sql-database/' + ); + const results = getAllFilenames('_sql-database/'); + + // Just in case the glob results aren't in a predictable order + snapshots.sort(); + results.sort(); + + expect(snapshots.length).toEqual(results.length); + + snapshots.map((snapshot, index) => { + const result = results[index]; + + expect(snapshot).toContain(result); + + const stat = statSync(result); + if (stat.isFile()) { + const resultContent = readFileSync(result).toString(); + const snapshotContent = readFileSync(snapshot).toString(); + + expect(resultContent).toEqual(snapshotContent); + } + }); }); }); diff --git a/snapshots/AdventureWorks2017.json b/snapshots/AdventureWorks2017/_sql-database/cache.json similarity index 100% rename from snapshots/AdventureWorks2017.json rename to snapshots/AdventureWorks2017/_sql-database/cache.json diff --git a/snapshots/AdventureWorks2017/_sql-database/data/Person.AddressType.sql b/snapshots/AdventureWorks2017/_sql-database/data/Person.AddressType.sql new file mode 100644 index 0000000..a5f20eb --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/data/Person.AddressType.sql @@ -0,0 +1,12 @@ +TRUNCATE TABLE [Person].[AddressType] + +SET IDENTITY_INSERT [Person].[AddressType] ON + +INSERT INTO [Person].[AddressType] (AddressTypeID, Name, rowguid, ModifiedDate) VALUES (1, 'Billing', 'B84F78B1-4EFE-4A0E-8CB7-70E9F112F886', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[AddressType] (AddressTypeID, Name, rowguid, ModifiedDate) VALUES (2, 'Home', '41BC2FF6-F0FC-475F-8EB9-CEC0805AA0F2', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[AddressType] (AddressTypeID, Name, rowguid, ModifiedDate) VALUES (3, 'Main Office', '8EEEC28C-07A2-4FB9-AD0A-42D4A0BBC575', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[AddressType] (AddressTypeID, Name, rowguid, ModifiedDate) VALUES (4, 'Primary', '24CB3088-4345-47C4-86C5-17B535133D1E', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[AddressType] (AddressTypeID, Name, rowguid, ModifiedDate) VALUES (5, 'Shipping', 'B29DA3F8-19A3-47DA-9DAA-15C84F4A83A5', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[AddressType] (AddressTypeID, Name, rowguid, ModifiedDate) VALUES (6, 'Archive', 'A67F238A-5BA2-444B-966C-0467ED9C427F', '2008-04-30T00:00:00.000Z') + +SET IDENTITY_INSERT [Person].[AddressType] OFF \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/data/Person.ContactType.sql b/snapshots/AdventureWorks2017/_sql-database/data/Person.ContactType.sql new file mode 100644 index 0000000..95b1aad --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/data/Person.ContactType.sql @@ -0,0 +1,26 @@ +TRUNCATE TABLE [Person].[ContactType] + +SET IDENTITY_INSERT [Person].[ContactType] ON + +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (1, 'Accounting Manager', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (2, 'Assistant Sales Agent', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (3, 'Assistant Sales Representative', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (4, 'Coordinator Foreign Markets', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (5, 'Export Administrator', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (6, 'International Marketing Manager', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (7, 'Marketing Assistant', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (8, 'Marketing Manager', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (9, 'Marketing Representative', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (10, 'Order Administrator', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (11, 'Owner', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (12, 'Owner/Marketing Assistant', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (13, 'Product Manager', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (14, 'Purchasing Agent', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (15, 'Purchasing Manager', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (16, 'Regional Account Representative', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (17, 'Sales Agent', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (18, 'Sales Associate', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (19, 'Sales Manager', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[ContactType] (ContactTypeID, Name, ModifiedDate) VALUES (20, 'Sales Representative', '2008-04-30T00:00:00.000Z') + +SET IDENTITY_INSERT [Person].[ContactType] OFF \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/data/Person.CountryRegion.sql b/snapshots/AdventureWorks2017/_sql-database/data/Person.CountryRegion.sql new file mode 100644 index 0000000..6f45089 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/data/Person.CountryRegion.sql @@ -0,0 +1,240 @@ +TRUNCATE TABLE [Person].[CountryRegion] + +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AD', 'Andorra', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AE', 'United Arab Emirates', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AF', 'Afghanistan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AG', 'Antigua and Barbuda', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AI', 'Anguilla', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AL', 'Albania', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AM', 'Armenia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AN', 'Netherlands Antilles', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AO', 'Angola', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AQ', 'Antarctica', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AR', 'Argentina', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AS', 'American Samoa', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AT', 'Austria', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AU', 'Australia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AW', 'Aruba', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('AZ', 'Azerbaijan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BA', 'Bosnia and Herzegovina', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BB', 'Barbados', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BD', 'Bangladesh', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BE', 'Belgium', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BF', 'Burkina Faso', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BG', 'Bulgaria', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BH', 'Bahrain', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BI', 'Burundi', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BJ', 'Benin', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BM', 'Bermuda', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BN', 'Brunei', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BO', 'Bolivia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BR', 'Brazil', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BS', 'Bahamas, The', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BT', 'Bhutan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BV', 'Bouvet Island', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BW', 'Botswana', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BY', 'Belarus', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('BZ', 'Belize', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CA', 'Canada', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CC', 'Cocos (Keeling) Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CD', 'Congo (DRC)', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CF', 'Central African Republic', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CG', 'Congo', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CH', 'Switzerland', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CI', 'Côte d''Ivoire', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CK', 'Cook Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CL', 'Chile', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CM', 'Cameroon', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CN', 'China', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CO', 'Colombia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CR', 'Costa Rica', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CS', 'Serbia and Montenegro', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CU', 'Cuba', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CV', 'Cape Verde', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CX', 'Christmas Island', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CY', 'Cyprus', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('CZ', 'Czech Republic', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('DE', 'Germany', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('DJ', 'Djibouti', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('DK', 'Denmark', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('DM', 'Dominica', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('DO', 'Dominican Republic', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('DZ', 'Algeria', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('EC', 'Ecuador', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('EE', 'Estonia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('EG', 'Egypt', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ER', 'Eritrea', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ES', 'Spain', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ET', 'Ethiopia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('FI', 'Finland', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('FJ', 'Fiji Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('FK', 'Falkland Islands (Islas Malvinas)', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('FM', 'Micronesia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('FO', 'Faroe Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('FR', 'France', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GA', 'Gabon', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GB', 'United Kingdom', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GD', 'Grenada', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GE', 'Georgia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GF', 'French Guiana', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GH', 'Ghana', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GI', 'Gibraltar', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GL', 'Greenland', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GM', 'Gambia, The', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GN', 'Guinea', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GP', 'Guadeloupe', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GQ', 'Equatorial Guinea', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GR', 'Greece', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GS', 'South Georgia and the South Sandwich Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GT', 'Guatemala', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GU', 'Guam', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GW', 'Guinea-Bissau', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('GY', 'Guyana', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('HK', 'Hong Kong SAR', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('HM', 'Heard Island and McDonald Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('HN', 'Honduras', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('HR', 'Croatia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('HT', 'Haiti', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('HU', 'Hungary', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ID', 'Indonesia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('IE', 'Ireland', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('IL', 'Israel', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('IN', 'India', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('IO', 'British Indian Ocean Territory', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('IQ', 'Iraq', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('IR', 'Iran', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('IS', 'Iceland', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('IT', 'Italy', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('JM', 'Jamaica', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('JO', 'Jordan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('JP', 'Japan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KE', 'Kenya', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KG', 'Kyrgyzstan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KH', 'Cambodia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KI', 'Kiribati', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KM', 'Comoros', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KN', 'Saint Kitts and Nevis', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KP', 'North Korea', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KR', 'Korea', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KW', 'Kuwait', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KY', 'Cayman Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('KZ', 'Kazakhstan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LA', 'Laos', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LB', 'Lebanon', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LC', 'Saint Lucia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LI', 'Liechtenstein', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LK', 'Sri Lanka', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LR', 'Liberia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LS', 'Lesotho', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LT', 'Lithuania', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LU', 'Luxembourg', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LV', 'Latvia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('LY', 'Libya', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MA', 'Morocco', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MC', 'Monaco', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MD', 'Moldova', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MG', 'Madagascar', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MH', 'Marshall Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MK', 'Macedonia, Former Yugoslav Republic of', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ML', 'Mali', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MM', 'Myanmar', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MN', 'Mongolia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MO', 'Macao SAR', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MP', 'Northern Mariana Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MQ', 'Martinique', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MR', 'Mauritania', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MS', 'Montserrat', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MT', 'Malta', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MU', 'Mauritius', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MV', 'Maldives', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MW', 'Malawi', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MX', 'Mexico', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MY', 'Malaysia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('MZ', 'Mozambique', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NA', 'Namibia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NC', 'New Caledonia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NE', 'Niger', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NF', 'Norfolk Island', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NG', 'Nigeria', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NI', 'Nicaragua', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NL', 'Netherlands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NO', 'Norway', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NP', 'Nepal', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NR', 'Nauru', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NU', 'Niue', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('NZ', 'New Zealand', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('OM', 'Oman', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PA', 'Panama', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PE', 'Peru', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PF', 'French Polynesia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PG', 'Papua New Guinea', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PH', 'Philippines', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PK', 'Pakistan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PL', 'Poland', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PM', 'Saint Pierre and Miquelon', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PN', 'Pitcairn Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PR', 'Puerto Rico', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PS', 'Palestinian Authority', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PT', 'Portugal', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PW', 'Palau', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('PY', 'Paraguay', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('QA', 'Qatar', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('RE', 'Réunion', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('RO', 'Romania', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('RU', 'Russia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('RW', 'Rwanda', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SA', 'Saudi Arabia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SB', 'Solomon Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SC', 'Seychelles', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SD', 'Sudan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SE', 'Sweden', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SG', 'Singapore', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SH', 'Saint Helena', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SI', 'Slovenia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SJ', 'Svalbard and Jan Mayen', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SK', 'Slovakia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SL', 'Sierra Leone', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SM', 'San Marino', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SN', 'Senegal', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SO', 'Somalia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SR', 'Suriname', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ST', 'São Tomé and Príncipe', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SV', 'El Salvador', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SY', 'Syria', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('SZ', 'Swaziland', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TC', 'Turks and Caicos Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TD', 'Chad', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TF', 'French Southern and Antarctic Lands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TG', 'Togo', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TH', 'Thailand', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TJ', 'Tajikistan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TK', 'Tokelau', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TL', 'Timor-Leste', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TM', 'Turkmenistan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TN', 'Tunisia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TO', 'Tonga', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TR', 'Turkey', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TT', 'Trinidad and Tobago', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TV', 'Tuvalu', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TW', 'Taiwan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('TZ', 'Tanzania', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('UA', 'Ukraine', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('UG', 'Uganda', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('UM', 'U.S. Minor Outlying Islands', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('US', 'United States', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('UY', 'Uruguay', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('UZ', 'Uzbekistan', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('VA', 'Vatican City', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('VC', 'Saint Vincent and the Grenadine', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('VE', 'Venezuela', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('VG', 'Virgin Islands, British', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('VI', 'Virgin Islands, U.S.', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('VN', 'Vietnam', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('VU', 'Vanuatu', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('WF', 'Wallis and Futuna', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('WS', 'Samoa', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('YE', 'Yemen', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('YT', 'Mayotte', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ZA', 'South Africa', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ZM', 'Zambia', '2008-04-30T00:00:00.000Z') +INSERT INTO [Person].[CountryRegion] (CountryRegionCode, Name, ModifiedDate) VALUES ('ZW', 'Zimbabwe', '2008-04-30T00:00:00.000Z') \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/data/Person.PhoneNumberType.sql b/snapshots/AdventureWorks2017/_sql-database/data/Person.PhoneNumberType.sql new file mode 100644 index 0000000..d46dd5e --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/data/Person.PhoneNumberType.sql @@ -0,0 +1,9 @@ +TRUNCATE TABLE [Person].[PhoneNumberType] + +SET IDENTITY_INSERT [Person].[PhoneNumberType] ON + +INSERT INTO [Person].[PhoneNumberType] (PhoneNumberTypeID, Name, ModifiedDate) VALUES (1, 'Cell', '2017-12-13T13:19:22.273Z') +INSERT INTO [Person].[PhoneNumberType] (PhoneNumberTypeID, Name, ModifiedDate) VALUES (2, 'Home', '2017-12-13T13:19:22.273Z') +INSERT INTO [Person].[PhoneNumberType] (PhoneNumberTypeID, Name, ModifiedDate) VALUES (3, 'Work', '2017-12-13T13:19:22.273Z') + +SET IDENTITY_INSERT [Person].[PhoneNumberType] OFF \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/data/Purchasing.ShipMethod.sql b/snapshots/AdventureWorks2017/_sql-database/data/Purchasing.ShipMethod.sql new file mode 100644 index 0000000..685a032 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/data/Purchasing.ShipMethod.sql @@ -0,0 +1,11 @@ +TRUNCATE TABLE [Purchasing].[ShipMethod] + +SET IDENTITY_INSERT [Purchasing].[ShipMethod] ON + +INSERT INTO [Purchasing].[ShipMethod] (ShipMethodID, Name, ShipBase, ShipRate, rowguid, ModifiedDate) VALUES (1, 'XRQ - TRUCK GROUND', 3.95, 0.99, '6BE756D9-D7BE-4463-8F2C-AE60C710D606', '2008-04-30T00:00:00.000Z') +INSERT INTO [Purchasing].[ShipMethod] (ShipMethodID, Name, ShipBase, ShipRate, rowguid, ModifiedDate) VALUES (2, 'ZY - EXPRESS', 9.95, 1.99, '3455079B-F773-4DC6-8F1E-2A58649C4AB8', '2008-04-30T00:00:00.000Z') +INSERT INTO [Purchasing].[ShipMethod] (ShipMethodID, Name, ShipBase, ShipRate, rowguid, ModifiedDate) VALUES (3, 'OVERSEAS - DELUXE', 29.95, 2.99, '22F4E461-28CF-4ACE-A980-F686CF112EC8', '2008-04-30T00:00:00.000Z') +INSERT INTO [Purchasing].[ShipMethod] (ShipMethodID, Name, ShipBase, ShipRate, rowguid, ModifiedDate) VALUES (4, 'OVERNIGHT J-FAST', 21.95, 1.29, '107E8356-E7A8-463D-B60C-079FFF467F3F', '2008-04-30T00:00:00.000Z') +INSERT INTO [Purchasing].[ShipMethod] (ShipMethodID, Name, ShipBase, ShipRate, rowguid, ModifiedDate) VALUES (5, 'CARGO TRANSPORT 5', 8.99, 1.49, 'B166019A-B134-4E76-B957-2B0490C610ED', '2008-04-30T00:00:00.000Z') + +SET IDENTITY_INSERT [Purchasing].[ShipMethod] OFF \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetAccountingEndDate.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetAccountingEndDate.sql new file mode 100644 index 0000000..c9c9206 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetAccountingEndDate.sql @@ -0,0 +1,10 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetAccountingEndDate]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetAccountingEndDate] +GO + +CREATE FUNCTION [dbo].[ufnGetAccountingEndDate]() +RETURNS [datetime] +AS +BEGIN + RETURN DATEADD(millisecond, -2, CONVERT(datetime, '20040701', 112)); +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetAccountingStartDate.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetAccountingStartDate.sql new file mode 100644 index 0000000..4842ea4 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetAccountingStartDate.sql @@ -0,0 +1,10 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetAccountingStartDate]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetAccountingStartDate] +GO + +CREATE FUNCTION [dbo].[ufnGetAccountingStartDate]() +RETURNS [datetime] +AS +BEGIN + RETURN CONVERT(datetime, '20030701', 112); +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetContactInformation.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetContactInformation.sql new file mode 100644 index 0000000..9c01177 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetContactInformation.sql @@ -0,0 +1,73 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetContactInformation]') AND type = 'TF') +DROP FUNCTION [dbo].[ufnGetContactInformation] +GO + +CREATE FUNCTION [dbo].[ufnGetContactInformation](@PersonID int) +RETURNS @retContactInformation TABLE +( + -- Columns returned by the function + [PersonID] int NOT NULL, + [FirstName] [nvarchar](50) NULL, + [LastName] [nvarchar](50) NULL, + [JobTitle] [nvarchar](50) NULL, + [BusinessEntityType] [nvarchar](50) NULL +) +AS +-- Returns the first name, last name, job title and business entity type for the specified contact. +-- Since a contact can serve multiple roles, more than one row may be returned. +BEGIN + IF @PersonID IS NOT NULL + BEGIN + IF EXISTS(SELECT * FROM [HumanResources].[Employee] e + WHERE e.[BusinessEntityID] = @PersonID) + INSERT INTO @retContactInformation + SELECT @PersonID, p.FirstName, p.LastName, e.[JobTitle], 'Employee' + FROM [HumanResources].[Employee] AS e + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + WHERE e.[BusinessEntityID] = @PersonID; + + IF EXISTS(SELECT * FROM [Purchasing].[Vendor] AS v + INNER JOIN [Person].[BusinessEntityContact] bec + ON bec.[BusinessEntityID] = v.[BusinessEntityID] + WHERE bec.[PersonID] = @PersonID) + INSERT INTO @retContactInformation + SELECT @PersonID, p.FirstName, p.LastName, ct.[Name], 'Vendor Contact' + FROM [Purchasing].[Vendor] AS v + INNER JOIN [Person].[BusinessEntityContact] bec + ON bec.[BusinessEntityID] = v.[BusinessEntityID] + INNER JOIN [Person].ContactType ct + ON ct.[ContactTypeID] = bec.[ContactTypeID] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = bec.[PersonID] + WHERE bec.[PersonID] = @PersonID; + + IF EXISTS(SELECT * FROM [Sales].[Store] AS s + INNER JOIN [Person].[BusinessEntityContact] bec + ON bec.[BusinessEntityID] = s.[BusinessEntityID] + WHERE bec.[PersonID] = @PersonID) + INSERT INTO @retContactInformation + SELECT @PersonID, p.FirstName, p.LastName, ct.[Name], 'Store Contact' + FROM [Sales].[Store] AS s + INNER JOIN [Person].[BusinessEntityContact] bec + ON bec.[BusinessEntityID] = s.[BusinessEntityID] + INNER JOIN [Person].ContactType ct + ON ct.[ContactTypeID] = bec.[ContactTypeID] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = bec.[PersonID] + WHERE bec.[PersonID] = @PersonID; + + IF EXISTS(SELECT * FROM [Person].[Person] AS p + INNER JOIN [Sales].[Customer] AS c + ON c.[PersonID] = p.[BusinessEntityID] + WHERE p.[BusinessEntityID] = @PersonID AND c.[StoreID] IS NULL) + INSERT INTO @retContactInformation + SELECT @PersonID, p.FirstName, p.LastName, NULL, 'Consumer' + FROM [Person].[Person] AS p + INNER JOIN [Sales].[Customer] AS c + ON c.[PersonID] = p.[BusinessEntityID] + WHERE p.[BusinessEntityID] = @PersonID AND c.[StoreID] IS NULL; + END + + RETURN; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetDocumentStatusText.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetDocumentStatusText.sql new file mode 100644 index 0000000..f6c4ff0 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetDocumentStatusText.sql @@ -0,0 +1,21 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetDocumentStatusText]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetDocumentStatusText] +GO + +CREATE FUNCTION [dbo].[ufnGetDocumentStatusText](@Status [tinyint]) +RETURNS [nvarchar](16) +AS +-- Returns the sales order status text representation for the status value. +BEGIN + DECLARE @ret [nvarchar](16); + + SET @ret = + CASE @Status + WHEN 1 THEN N'Pending approval' + WHEN 2 THEN N'Approved' + WHEN 3 THEN N'Obsolete' + ELSE N'** Invalid **' + END; + + RETURN @ret +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductDealerPrice.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductDealerPrice.sql new file mode 100644 index 0000000..934190c --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductDealerPrice.sql @@ -0,0 +1,25 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetProductDealerPrice]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetProductDealerPrice] +GO + + + +CREATE FUNCTION [dbo].[ufnGetProductDealerPrice](@ProductID [int], @OrderDate [datetime]) +RETURNS [money] +AS +-- Returns the dealer price for the product on a specific date. +BEGIN + DECLARE @DealerPrice money; + DECLARE @DealerDiscount money; + + SET @DealerDiscount = 0.60 -- 60% of list price + + SELECT @DealerPrice = plph.[ListPrice] * @DealerDiscount + FROM [Production].[Product] p + INNER JOIN [Production].[ProductListPriceHistory] plph + ON p.[ProductID] = plph.[ProductID] + AND p.[ProductID] = @ProductID + AND @OrderDate BETWEEN plph.[StartDate] AND COALESCE(plph.[EndDate], CONVERT(datetime, '99991231', 112)); -- Make sure we get all the prices! + + RETURN @DealerPrice; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductListPrice.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductListPrice.sql new file mode 100644 index 0000000..36b39d4 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductListPrice.sql @@ -0,0 +1,19 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetProductListPrice]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetProductListPrice] +GO + +CREATE FUNCTION [dbo].[ufnGetProductListPrice](@ProductID [int], @OrderDate [datetime]) +RETURNS [money] +AS +BEGIN + DECLARE @ListPrice money; + + SELECT @ListPrice = plph.[ListPrice] + FROM [Production].[Product] p + INNER JOIN [Production].[ProductListPriceHistory] plph + ON p.[ProductID] = plph.[ProductID] + AND p.[ProductID] = @ProductID + AND @OrderDate BETWEEN plph.[StartDate] AND COALESCE(plph.[EndDate], CONVERT(datetime, '99991231', 112)); -- Make sure we get all the prices! + + RETURN @ListPrice; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductStandardCost.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductStandardCost.sql new file mode 100644 index 0000000..da63090 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetProductStandardCost.sql @@ -0,0 +1,20 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetProductStandardCost]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetProductStandardCost] +GO + +CREATE FUNCTION [dbo].[ufnGetProductStandardCost](@ProductID [int], @OrderDate [datetime]) +RETURNS [money] +AS +-- Returns the standard cost for the product on a specific date. +BEGIN + DECLARE @StandardCost money; + + SELECT @StandardCost = pch.[StandardCost] + FROM [Production].[Product] p + INNER JOIN [Production].[ProductCostHistory] pch + ON p.[ProductID] = pch.[ProductID] + AND p.[ProductID] = @ProductID + AND @OrderDate BETWEEN pch.[StartDate] AND COALESCE(pch.[EndDate], CONVERT(datetime, '99991231', 112)); -- Make sure we get all the prices! + + RETURN @StandardCost; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetPurchaseOrderStatusText.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetPurchaseOrderStatusText.sql new file mode 100644 index 0000000..c143bf5 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetPurchaseOrderStatusText.sql @@ -0,0 +1,22 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetPurchaseOrderStatusText]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetPurchaseOrderStatusText] +GO + +CREATE FUNCTION [dbo].[ufnGetPurchaseOrderStatusText](@Status [tinyint]) +RETURNS [nvarchar](15) +AS +-- Returns the sales order status text representation for the status value. +BEGIN + DECLARE @ret [nvarchar](15); + + SET @ret = + CASE @Status + WHEN 1 THEN 'Pending' + WHEN 2 THEN 'Approved' + WHEN 3 THEN 'Rejected' + WHEN 4 THEN 'Complete' + ELSE '** Invalid **' + END; + + RETURN @ret +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetSalesOrderStatusText.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetSalesOrderStatusText.sql new file mode 100644 index 0000000..aaa4b66 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetSalesOrderStatusText.sql @@ -0,0 +1,24 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetSalesOrderStatusText]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetSalesOrderStatusText] +GO + +CREATE FUNCTION [dbo].[ufnGetSalesOrderStatusText](@Status [tinyint]) +RETURNS [nvarchar](15) +AS +-- Returns the sales order status text representation for the status value. +BEGIN + DECLARE @ret [nvarchar](15); + + SET @ret = + CASE @Status + WHEN 1 THEN 'In process' + WHEN 2 THEN 'Approved' + WHEN 3 THEN 'Backordered' + WHEN 4 THEN 'Rejected' + WHEN 5 THEN 'Shipped' + WHEN 6 THEN 'Cancelled' + ELSE '** Invalid **' + END; + + RETURN @ret +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetStock.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetStock.sql new file mode 100644 index 0000000..e403b88 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnGetStock.sql @@ -0,0 +1,21 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnGetStock]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnGetStock] +GO + +CREATE FUNCTION [dbo].[ufnGetStock](@ProductID [int]) +RETURNS [int] +AS +-- Returns the stock level for the product. This function is used internally only +BEGIN + DECLARE @ret int; + + SELECT @ret = SUM(p.[Quantity]) + FROM [Production].[ProductInventory] p + WHERE p.[ProductID] = @ProductID + AND p.[LocationID] = '6'; -- Only look at inventory in the misc storage + + IF (@ret IS NULL) + SET @ret = 0 + + RETURN @ret +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnLeadingZeros.sql b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnLeadingZeros.sql new file mode 100644 index 0000000..9a194e3 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/functions/dbo.ufnLeadingZeros.sql @@ -0,0 +1,18 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ufnLeadingZeros]') AND type = 'FN') +DROP FUNCTION [dbo].[ufnLeadingZeros] +GO + +CREATE FUNCTION [dbo].[ufnLeadingZeros]( + @Value int +) +RETURNS varchar(8) +WITH SCHEMABINDING +AS +BEGIN + DECLARE @ReturnValue varchar(8); + + SET @ReturnValue = CONVERT(varchar(8), @Value); + SET @ReturnValue = REPLICATE('0', 8 - DATALENGTH(@ReturnValue)) + @ReturnValue; + + RETURN (@ReturnValue); +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/schemas/HumanResources.sql b/snapshots/AdventureWorks2017/_sql-database/schemas/HumanResources.sql new file mode 100644 index 0000000..811c329 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/schemas/HumanResources.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'HumanResources') +EXEC('CREATE SCHEMA HumanResources') \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/schemas/Person.sql b/snapshots/AdventureWorks2017/_sql-database/schemas/Person.sql new file mode 100644 index 0000000..31ed728 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/schemas/Person.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Person') +EXEC('CREATE SCHEMA Person') \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/schemas/Production.sql b/snapshots/AdventureWorks2017/_sql-database/schemas/Production.sql new file mode 100644 index 0000000..3c36715 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/schemas/Production.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Production') +EXEC('CREATE SCHEMA Production') \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/schemas/Purchasing.sql b/snapshots/AdventureWorks2017/_sql-database/schemas/Purchasing.sql new file mode 100644 index 0000000..4c33d21 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/schemas/Purchasing.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Purchasing') +EXEC('CREATE SCHEMA Purchasing') \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/schemas/Sales.sql b/snapshots/AdventureWorks2017/_sql-database/schemas/Sales.sql new file mode 100644 index 0000000..f57b0a7 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/schemas/Sales.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'Sales') +EXEC('CREATE SCHEMA Sales') \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/schemas/dbo.sql b/snapshots/AdventureWorks2017/_sql-database/schemas/dbo.sql new file mode 100644 index 0000000..81b5e30 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/schemas/dbo.sql @@ -0,0 +1,2 @@ +IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'dbo') +EXEC('CREATE SCHEMA dbo') \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeHireInfo.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeHireInfo.sql new file mode 100644 index 0000000..6cd44de --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeHireInfo.sql @@ -0,0 +1,46 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[uspUpdateEmployeeHireInfo]') AND type = 'P') +DROP PROCEDURE [HumanResources].[uspUpdateEmployeeHireInfo] +GO + +CREATE PROCEDURE [HumanResources].[uspUpdateEmployeeHireInfo] + @BusinessEntityID [int], + @JobTitle [nvarchar](50), + @HireDate [datetime], + @RateChangeDate [datetime], + @Rate [money], + @PayFrequency [tinyint], + @CurrentFlag [dbo].[Flag] +WITH EXECUTE AS CALLER +AS +BEGIN + SET NOCOUNT ON; + + BEGIN TRY + BEGIN TRANSACTION; + + UPDATE [HumanResources].[Employee] + SET [JobTitle] = @JobTitle + ,[HireDate] = @HireDate + ,[CurrentFlag] = @CurrentFlag + WHERE [BusinessEntityID] = @BusinessEntityID; + + INSERT INTO [HumanResources].[EmployeePayHistory] + ([BusinessEntityID] + ,[RateChangeDate] + ,[Rate] + ,[PayFrequency]) + VALUES (@BusinessEntityID, @RateChangeDate, @Rate, @PayFrequency); + + COMMIT TRANSACTION; + END TRY + BEGIN CATCH + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeLogin.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeLogin.sql new file mode 100644 index 0000000..eb088a3 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeLogin.sql @@ -0,0 +1,29 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[uspUpdateEmployeeLogin]') AND type = 'P') +DROP PROCEDURE [HumanResources].[uspUpdateEmployeeLogin] +GO + +CREATE PROCEDURE [HumanResources].[uspUpdateEmployeeLogin] + @BusinessEntityID [int], + @OrganizationNode [hierarchyid], + @LoginID [nvarchar](256), + @JobTitle [nvarchar](50), + @HireDate [datetime], + @CurrentFlag [dbo].[Flag] +WITH EXECUTE AS CALLER +AS +BEGIN + SET NOCOUNT ON; + + BEGIN TRY + UPDATE [HumanResources].[Employee] + SET [OrganizationNode] = @OrganizationNode + ,[LoginID] = @LoginID + ,[JobTitle] = @JobTitle + ,[HireDate] = @HireDate + ,[CurrentFlag] = @CurrentFlag + WHERE [BusinessEntityID] = @BusinessEntityID; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeePersonalInfo.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeePersonalInfo.sql new file mode 100644 index 0000000..c8b0dca --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/HumanResources.uspUpdateEmployeePersonalInfo.sql @@ -0,0 +1,27 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[uspUpdateEmployeePersonalInfo]') AND type = 'P') +DROP PROCEDURE [HumanResources].[uspUpdateEmployeePersonalInfo] +GO + +CREATE PROCEDURE [HumanResources].[uspUpdateEmployeePersonalInfo] + @BusinessEntityID [int], + @NationalIDNumber [nvarchar](15), + @BirthDate [datetime], + @MaritalStatus [nchar](1), + @Gender [nchar](1) +WITH EXECUTE AS CALLER +AS +BEGIN + SET NOCOUNT ON; + + BEGIN TRY + UPDATE [HumanResources].[Employee] + SET [NationalIDNumber] = @NationalIDNumber + ,[BirthDate] = @BirthDate + ,[MaritalStatus] = @MaritalStatus + ,[Gender] = @Gender + WHERE [BusinessEntityID] = @BusinessEntityID; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetBillOfMaterials.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetBillOfMaterials.sql new file mode 100644 index 0000000..58f88d1 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetBillOfMaterials.sql @@ -0,0 +1,40 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[uspGetBillOfMaterials]') AND type = 'P') +DROP PROCEDURE [dbo].[uspGetBillOfMaterials] +GO + +CREATE PROCEDURE [dbo].[uspGetBillOfMaterials] + @StartProductID [int], + @CheckDate [datetime] +AS +BEGIN + SET NOCOUNT ON; + + -- Use recursive query to generate a multi-level Bill of Material (i.e. all level 1 + -- components of a level 0 assembly, all level 2 components of a level 1 assembly) + -- The CheckDate eliminates any components that are no longer used in the product on this date. + WITH [BOM_cte]([ProductAssemblyID], [ComponentID], [ComponentDesc], [PerAssemblyQty], [StandardCost], [ListPrice], [BOMLevel], [RecursionLevel]) -- CTE name and columns + AS ( + SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], 0 -- Get the initial list of components for the bike assembly + FROM [Production].[BillOfMaterials] b + INNER JOIN [Production].[Product] p + ON b.[ComponentID] = p.[ProductID] + WHERE b.[ProductAssemblyID] = @StartProductID + AND @CheckDate >= b.[StartDate] + AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate) + UNION ALL + SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], [RecursionLevel] + 1 -- Join recursive member to anchor + FROM [BOM_cte] cte + INNER JOIN [Production].[BillOfMaterials] b + ON b.[ProductAssemblyID] = cte.[ComponentID] + INNER JOIN [Production].[Product] p + ON b.[ComponentID] = p.[ProductID] + WHERE @CheckDate >= b.[StartDate] + AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate) + ) + -- Outer select from the CTE + SELECT b.[ProductAssemblyID], b.[ComponentID], b.[ComponentDesc], SUM(b.[PerAssemblyQty]) AS [TotalQuantity] , b.[StandardCost], b.[ListPrice], b.[BOMLevel], b.[RecursionLevel] + FROM [BOM_cte] b + GROUP BY b.[ComponentID], b.[ComponentDesc], b.[ProductAssemblyID], b.[BOMLevel], b.[RecursionLevel], b.[StandardCost], b.[ListPrice] + ORDER BY b.[BOMLevel], b.[ProductAssemblyID], b.[ComponentID] + OPTION (MAXRECURSION 25) +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetEmployeeManagers.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetEmployeeManagers.sql new file mode 100644 index 0000000..783cc5f --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetEmployeeManagers.sql @@ -0,0 +1,37 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[uspGetEmployeeManagers]') AND type = 'P') +DROP PROCEDURE [dbo].[uspGetEmployeeManagers] +GO + +CREATE PROCEDURE [dbo].[uspGetEmployeeManagers] + @BusinessEntityID [int] +AS +BEGIN + SET NOCOUNT ON; + + -- Use recursive query to list out all Employees required for a particular Manager + WITH [EMP_cte]([BusinessEntityID], [OrganizationNode], [FirstName], [LastName], [JobTitle], [RecursionLevel]) -- CTE name and columns + AS ( + SELECT e.[BusinessEntityID], e.[OrganizationNode], p.[FirstName], p.[LastName], e.[JobTitle], 0 -- Get the initial Employee + FROM [HumanResources].[Employee] e + INNER JOIN [Person].[Person] as p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + WHERE e.[BusinessEntityID] = @BusinessEntityID + UNION ALL + SELECT e.[BusinessEntityID], e.[OrganizationNode], p.[FirstName], p.[LastName], e.[JobTitle], [RecursionLevel] + 1 -- Join recursive member to anchor + FROM [HumanResources].[Employee] e + INNER JOIN [EMP_cte] + ON e.[OrganizationNode] = [EMP_cte].[OrganizationNode].GetAncestor(1) + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + ) + -- Join back to Employee to return the manager name + SELECT [EMP_cte].[RecursionLevel], [EMP_cte].[BusinessEntityID], [EMP_cte].[FirstName], [EMP_cte].[LastName], + [EMP_cte].[OrganizationNode].ToString() AS [OrganizationNode], p.[FirstName] AS 'ManagerFirstName', p.[LastName] AS 'ManagerLastName' -- Outer select from the CTE + FROM [EMP_cte] + INNER JOIN [HumanResources].[Employee] e + ON [EMP_cte].[OrganizationNode].GetAncestor(1) = e.[OrganizationNode] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + ORDER BY [RecursionLevel], [EMP_cte].[OrganizationNode].ToString() + OPTION (MAXRECURSION 25) +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetManagerEmployees.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetManagerEmployees.sql new file mode 100644 index 0000000..9298d5d --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetManagerEmployees.sql @@ -0,0 +1,37 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[uspGetManagerEmployees]') AND type = 'P') +DROP PROCEDURE [dbo].[uspGetManagerEmployees] +GO + +CREATE PROCEDURE [dbo].[uspGetManagerEmployees] + @BusinessEntityID [int] +AS +BEGIN + SET NOCOUNT ON; + + -- Use recursive query to list out all Employees required for a particular Manager + WITH [EMP_cte]([BusinessEntityID], [OrganizationNode], [FirstName], [LastName], [RecursionLevel]) -- CTE name and columns + AS ( + SELECT e.[BusinessEntityID], e.[OrganizationNode], p.[FirstName], p.[LastName], 0 -- Get the initial list of Employees for Manager n + FROM [HumanResources].[Employee] e + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + WHERE e.[BusinessEntityID] = @BusinessEntityID + UNION ALL + SELECT e.[BusinessEntityID], e.[OrganizationNode], p.[FirstName], p.[LastName], [RecursionLevel] + 1 -- Join recursive member to anchor + FROM [HumanResources].[Employee] e + INNER JOIN [EMP_cte] + ON e.[OrganizationNode].GetAncestor(1) = [EMP_cte].[OrganizationNode] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + ) + -- Join back to Employee to return the manager name + SELECT [EMP_cte].[RecursionLevel], [EMP_cte].[OrganizationNode].ToString() as [OrganizationNode], p.[FirstName] AS 'ManagerFirstName', p.[LastName] AS 'ManagerLastName', + [EMP_cte].[BusinessEntityID], [EMP_cte].[FirstName], [EMP_cte].[LastName] -- Outer select from the CTE + FROM [EMP_cte] + INNER JOIN [HumanResources].[Employee] e + ON [EMP_cte].[OrganizationNode].GetAncestor(1) = e.[OrganizationNode] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + ORDER BY [RecursionLevel], [EMP_cte].[OrganizationNode].ToString() + OPTION (MAXRECURSION 25) +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetWhereUsedProductID.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetWhereUsedProductID.sql new file mode 100644 index 0000000..7844f3b --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspGetWhereUsedProductID.sql @@ -0,0 +1,38 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[uspGetWhereUsedProductID]') AND type = 'P') +DROP PROCEDURE [dbo].[uspGetWhereUsedProductID] +GO + +CREATE PROCEDURE [dbo].[uspGetWhereUsedProductID] + @StartProductID [int], + @CheckDate [datetime] +AS +BEGIN + SET NOCOUNT ON; + + --Use recursive query to generate a multi-level Bill of Material (i.e. all level 1 components of a level 0 assembly, all level 2 components of a level 1 assembly) + WITH [BOM_cte]([ProductAssemblyID], [ComponentID], [ComponentDesc], [PerAssemblyQty], [StandardCost], [ListPrice], [BOMLevel], [RecursionLevel]) -- CTE name and columns + AS ( + SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], 0 -- Get the initial list of components for the bike assembly + FROM [Production].[BillOfMaterials] b + INNER JOIN [Production].[Product] p + ON b.[ProductAssemblyID] = p.[ProductID] + WHERE b.[ComponentID] = @StartProductID + AND @CheckDate >= b.[StartDate] + AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate) + UNION ALL + SELECT b.[ProductAssemblyID], b.[ComponentID], p.[Name], b.[PerAssemblyQty], p.[StandardCost], p.[ListPrice], b.[BOMLevel], [RecursionLevel] + 1 -- Join recursive member to anchor + FROM [BOM_cte] cte + INNER JOIN [Production].[BillOfMaterials] b + ON cte.[ProductAssemblyID] = b.[ComponentID] + INNER JOIN [Production].[Product] p + ON b.[ProductAssemblyID] = p.[ProductID] + WHERE @CheckDate >= b.[StartDate] + AND @CheckDate <= ISNULL(b.[EndDate], @CheckDate) + ) + -- Outer select from the CTE + SELECT b.[ProductAssemblyID], b.[ComponentID], b.[ComponentDesc], SUM(b.[PerAssemblyQty]) AS [TotalQuantity] , b.[StandardCost], b.[ListPrice], b.[BOMLevel], b.[RecursionLevel] + FROM [BOM_cte] b + GROUP BY b.[ComponentID], b.[ComponentDesc], b.[ProductAssemblyID], b.[BOMLevel], b.[RecursionLevel], b.[StandardCost], b.[ListPrice] + ORDER BY b.[BOMLevel], b.[ProductAssemblyID], b.[ComponentID] + OPTION (MAXRECURSION 25) +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspLogError.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspLogError.sql new file mode 100644 index 0000000..c363888 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspLogError.sql @@ -0,0 +1,64 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[uspLogError]') AND type = 'P') +DROP PROCEDURE [dbo].[uspLogError] +GO + +-- uspLogError logs error information in the ErrorLog table about the +-- error that caused execution to jump to the CATCH block of a +-- TRY...CATCH construct. This should be executed from within the scope +-- of a CATCH block otherwise it will return without inserting error +-- information. +CREATE PROCEDURE [dbo].[uspLogError] + @ErrorLogID [int] = 0 OUTPUT -- contains the ErrorLogID of the row inserted +AS -- by uspLogError in the ErrorLog table +BEGIN + SET NOCOUNT ON; + + -- Output parameter value of 0 indicates that error + -- information was not logged + SET @ErrorLogID = 0; + + BEGIN TRY + -- Return if there is no error information to log + IF ERROR_NUMBER() IS NULL + RETURN; + + -- Return if inside an uncommittable transaction. + -- Data insertion/modification is not allowed when + -- a transaction is in an uncommittable state. + IF XACT_STATE() = -1 + BEGIN + PRINT 'Cannot log error since the current transaction is in an uncommittable state. ' + + 'Rollback the transaction before executing uspLogError in order to successfully log error information.'; + RETURN; + END + + INSERT [dbo].[ErrorLog] + ( + [UserName], + [ErrorNumber], + [ErrorSeverity], + [ErrorState], + [ErrorProcedure], + [ErrorLine], + [ErrorMessage] + ) + VALUES + ( + CONVERT(sysname, CURRENT_USER), + ERROR_NUMBER(), + ERROR_SEVERITY(), + ERROR_STATE(), + ERROR_PROCEDURE(), + ERROR_LINE(), + ERROR_MESSAGE() + ); + + -- Pass back the ErrorLogID of the row inserted + SET @ErrorLogID = @@IDENTITY; + END TRY + BEGIN CATCH + PRINT 'An error occurred in stored procedure uspLogError: '; + EXECUTE [dbo].[uspPrintError]; + RETURN -1; + END CATCH +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspPrintError.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspPrintError.sql new file mode 100644 index 0000000..76184b0 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspPrintError.sql @@ -0,0 +1,21 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[uspPrintError]') AND type = 'P') +DROP PROCEDURE [dbo].[uspPrintError] +GO + +-- uspPrintError prints error information about the error that caused +-- execution to jump to the CATCH block of a TRY...CATCH construct. +-- Should be executed from within the scope of a CATCH block otherwise +-- it will return without printing any error information. +CREATE PROCEDURE [dbo].[uspPrintError] +AS +BEGIN + SET NOCOUNT ON; + + -- Print error information. + PRINT 'Error ' + CONVERT(varchar(50), ERROR_NUMBER()) + + ', Severity ' + CONVERT(varchar(5), ERROR_SEVERITY()) + + ', State ' + CONVERT(varchar(5), ERROR_STATE()) + + ', Procedure ' + ISNULL(ERROR_PROCEDURE(), '-') + + ', Line ' + CONVERT(varchar(5), ERROR_LINE()); + PRINT ERROR_MESSAGE(); +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspSearchCandidateResumes.sql b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspSearchCandidateResumes.sql new file mode 100644 index 0000000..70bc106 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/stored-procedures/dbo.uspSearchCandidateResumes.sql @@ -0,0 +1,59 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[uspSearchCandidateResumes]') AND type = 'P') +DROP PROCEDURE [dbo].[uspSearchCandidateResumes] +GO + +--A stored procedure which demonstrates integrated full text search + +CREATE PROCEDURE [dbo].[uspSearchCandidateResumes] + @searchString [nvarchar](1000), + @useInflectional [bit]=0, + @useThesaurus [bit]=0, + @language[int]=0 + + +WITH EXECUTE AS CALLER +AS +BEGIN + SET NOCOUNT ON; + + DECLARE @string nvarchar(1050) + --setting the lcid to the default instance LCID if needed + IF @language = NULL OR @language = 0 + BEGIN + SELECT @language =CONVERT(int, serverproperty('lcid')) + END + + + --FREETEXTTABLE case as inflectional and Thesaurus were required + IF @useThesaurus = 1 AND @useInflectional = 1 + BEGIN + SELECT FT_TBL.[JobCandidateID], KEY_TBL.[RANK] FROM [HumanResources].[JobCandidate] AS FT_TBL + INNER JOIN FREETEXTTABLE([HumanResources].[JobCandidate],*, @searchString,LANGUAGE @language) AS KEY_TBL + ON FT_TBL.[JobCandidateID] =KEY_TBL.[KEY] + END + + ELSE IF @useThesaurus = 1 + BEGIN + SELECT @string ='FORMSOF(THESAURUS,"'+@searchString +'"'+')' + SELECT FT_TBL.[JobCandidateID], KEY_TBL.[RANK] FROM [HumanResources].[JobCandidate] AS FT_TBL + INNER JOIN CONTAINSTABLE([HumanResources].[JobCandidate],*, @string,LANGUAGE @language) AS KEY_TBL + ON FT_TBL.[JobCandidateID] =KEY_TBL.[KEY] + END + + ELSE IF @useInflectional = 1 + BEGIN + SELECT @string ='FORMSOF(INFLECTIONAL,"'+@searchString +'"'+')' + SELECT FT_TBL.[JobCandidateID], KEY_TBL.[RANK] FROM [HumanResources].[JobCandidate] AS FT_TBL + INNER JOIN CONTAINSTABLE([HumanResources].[JobCandidate],*, @string,LANGUAGE @language) AS KEY_TBL + ON FT_TBL.[JobCandidateID] =KEY_TBL.[KEY] + END + + ELSE --base case, plain CONTAINSTABLE + BEGIN + SELECT @string='"'+@searchString +'"' + SELECT FT_TBL.[JobCandidateID],KEY_TBL.[RANK] FROM [HumanResources].[JobCandidate] AS FT_TBL + INNER JOIN CONTAINSTABLE([HumanResources].[JobCandidate],*,@string,LANGUAGE @language) AS KEY_TBL + ON FT_TBL.[JobCandidateID] =KEY_TBL.[KEY] + END + +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Department.sql b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Department.sql new file mode 100644 index 0000000..4e429a0 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Department.sql @@ -0,0 +1,12 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[Department]') AND type = 'U') +CREATE TABLE [HumanResources].[Department] +( + [DepartmentID] smallint NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [GroupName] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Department_DepartmentID] PRIMARY KEY CLUSTERED ([DepartmentID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Department]') AND name = 'AK_Department_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Department_Name] ON [HumanResources].[Department]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Employee.sql b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Employee.sql new file mode 100644 index 0000000..ff4ecd4 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Employee.sql @@ -0,0 +1,45 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND type = 'U') +CREATE TABLE [HumanResources].[Employee] +( + [BusinessEntityID] int NOT NULL, + [NationalIDNumber] nvarchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [LoginID] nvarchar(256) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [OrganizationNode] hierarchyid NULL, + [OrganizationLevel] AS ([OrganizationNode].[GetLevel]()), + [JobTitle] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [BirthDate] date NOT NULL, + [MaritalStatus] nchar(1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Gender] nchar(1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [HireDate] date NOT NULL, + [SalariedFlag] Flag NOT NULL DEFAULT((1)), + [VacationHours] smallint NOT NULL DEFAULT((0)), + [SickLeaveHours] smallint NOT NULL DEFAULT((0)), + [CurrentFlag] Flag NOT NULL DEFAULT((1)), + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Employee_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_Employee_Person_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[HumanResources].[Employee]')) +BEGIN + ALTER TABLE [HumanResources].[Employee] WITH CHECK ADD CONSTRAINT [FK_Employee_Person_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[Person] ([BusinessEntityID]) + ALTER TABLE [HumanResources].[Employee] CHECK CONSTRAINT [FK_Employee_Person_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'IX_Employee_OrganizationNode') +CREATE NONCLUSTERED INDEX [IX_Employee_OrganizationNode] ON [HumanResources].[Employee]([OrganizationNode] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'IX_Employee_OrganizationLevel_OrganizationNode') +CREATE NONCLUSTERED INDEX [IX_Employee_OrganizationLevel_OrganizationNode] ON [HumanResources].[Employee]( + [OrganizationLevel] ASC, + [OrganizationNode] ASC +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'AK_Employee_LoginID') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_LoginID] ON [HumanResources].[Employee]([LoginID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'AK_Employee_NationalIDNumber') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_NationalIDNumber] ON [HumanResources].[Employee]([NationalIDNumber] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'AK_Employee_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_rowguid] ON [HumanResources].[Employee]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql new file mode 100644 index 0000000..4c901b2 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql @@ -0,0 +1,41 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]') AND type = 'U') +CREATE TABLE [HumanResources].[EmployeeDepartmentHistory] +( + [BusinessEntityID] int NOT NULL, + [DepartmentID] smallint NOT NULL, + [ShiftID] tinyint NOT NULL, + [StartDate] date NOT NULL, + [EndDate] date NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_EmployeeDepartmentHistory_BusinessEntityID_StartDate_DepartmentID] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [StartDate] ASC, + [DepartmentID] ASC, + [ShiftID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_EmployeeDepartmentHistory_Shift_ShiftID]') AND parent_object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]')) +BEGIN + ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] WITH CHECK ADD CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID] FOREIGN KEY ([ShiftID]) REFERENCES [HumanResources].[Shift] ([ShiftID]) + ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_EmployeeDepartmentHistory_Department_DepartmentID]') AND parent_object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]')) +BEGIN + ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] WITH CHECK ADD CONSTRAINT [FK_EmployeeDepartmentHistory_Department_DepartmentID] FOREIGN KEY ([DepartmentID]) REFERENCES [HumanResources].[Department] ([DepartmentID]) + ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Department_DepartmentID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_EmployeeDepartmentHistory_Employee_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]')) +BEGIN + ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] WITH CHECK ADD CONSTRAINT [FK_EmployeeDepartmentHistory_Employee_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) + ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Employee_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]') AND name = 'IX_EmployeeDepartmentHistory_DepartmentID') +CREATE NONCLUSTERED INDEX [IX_EmployeeDepartmentHistory_DepartmentID] ON [HumanResources].[EmployeeDepartmentHistory]([DepartmentID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]') AND name = 'IX_EmployeeDepartmentHistory_ShiftID') +CREATE NONCLUSTERED INDEX [IX_EmployeeDepartmentHistory_ShiftID] ON [HumanResources].[EmployeeDepartmentHistory]([ShiftID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeePayHistory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeePayHistory.sql new file mode 100644 index 0000000..13782ff --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeePayHistory.sql @@ -0,0 +1,20 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[EmployeePayHistory]') AND type = 'U') +CREATE TABLE [HumanResources].[EmployeePayHistory] +( + [BusinessEntityID] int NOT NULL, + [RateChangeDate] datetime NOT NULL, + [Rate] money NOT NULL, + [PayFrequency] tinyint NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_EmployeePayHistory_BusinessEntityID_RateChangeDate] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [RateChangeDate] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_EmployeePayHistory_Employee_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[HumanResources].[EmployeePayHistory]')) +BEGIN + ALTER TABLE [HumanResources].[EmployeePayHistory] WITH CHECK ADD CONSTRAINT [FK_EmployeePayHistory_Employee_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) + ALTER TABLE [HumanResources].[EmployeePayHistory] CHECK CONSTRAINT [FK_EmployeePayHistory_Employee_BusinessEntityID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.JobCandidate.sql b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.JobCandidate.sql new file mode 100644 index 0000000..7a140e1 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.JobCandidate.sql @@ -0,0 +1,18 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[JobCandidate]') AND type = 'U') +CREATE TABLE [HumanResources].[JobCandidate] +( + [JobCandidateID] int NOT NULL IDENTITY(1, 1), + [BusinessEntityID] int NULL, + [Resume] xml NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_JobCandidate_JobCandidateID] PRIMARY KEY CLUSTERED ([JobCandidateID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_JobCandidate_Employee_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[HumanResources].[JobCandidate]')) +BEGIN + ALTER TABLE [HumanResources].[JobCandidate] WITH CHECK ADD CONSTRAINT [FK_JobCandidate_Employee_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) + ALTER TABLE [HumanResources].[JobCandidate] CHECK CONSTRAINT [FK_JobCandidate_Employee_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[JobCandidate]') AND name = 'IX_JobCandidate_BusinessEntityID') +CREATE NONCLUSTERED INDEX [IX_JobCandidate_BusinessEntityID] ON [HumanResources].[JobCandidate]([BusinessEntityID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Shift.sql b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Shift.sql new file mode 100644 index 0000000..79b2f6e --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Shift.sql @@ -0,0 +1,19 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[Shift]') AND type = 'U') +CREATE TABLE [HumanResources].[Shift] +( + [ShiftID] tinyint NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [StartTime] time NOT NULL, + [EndTime] time NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Shift_ShiftID] PRIMARY KEY CLUSTERED ([ShiftID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Shift]') AND name = 'AK_Shift_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Shift_Name] ON [HumanResources].[Shift]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Shift]') AND name = 'AK_Shift_StartTime_EndTime') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Shift_StartTime_EndTime] ON [HumanResources].[Shift]( + [StartTime] ASC, + [EndTime] ASC +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.Address.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.Address.sql new file mode 100644 index 0000000..690dc60 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.Address.sql @@ -0,0 +1,35 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[Address]') AND type = 'U') +CREATE TABLE [Person].[Address] +( + [AddressID] int NOT NULL IDENTITY(1, 1), + [AddressLine1] nvarchar(60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [AddressLine2] nvarchar(60) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [City] nvarchar(30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [StateProvinceID] int NOT NULL, + [PostalCode] nvarchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [SpatialLocation] geography NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Address_AddressID] PRIMARY KEY CLUSTERED ([AddressID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_Address_StateProvince_StateProvinceID]') AND parent_object_id = OBJECT_ID('[Person].[Address]')) +BEGIN + ALTER TABLE [Person].[Address] WITH CHECK ADD CONSTRAINT [FK_Address_StateProvince_StateProvinceID] FOREIGN KEY ([StateProvinceID]) REFERENCES [Person].[StateProvince] ([StateProvinceID]) + ALTER TABLE [Person].[Address] CHECK CONSTRAINT [FK_Address_StateProvince_StateProvinceID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[Address]') AND name = 'AK_Address_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Address_rowguid] ON [Person].[Address]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[Address]') AND name = 'IX_Address_AddressLine1_AddressLine2_City_StateProvinceID_PostalCode') +CREATE UNIQUE NONCLUSTERED INDEX [IX_Address_AddressLine1_AddressLine2_City_StateProvinceID_PostalCode] ON [Person].[Address]( + [AddressLine1] ASC, + [AddressLine2] ASC, + [City] ASC, + [StateProvinceID] ASC, + [PostalCode] ASC +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[Address]') AND name = 'IX_Address_StateProvinceID') +CREATE NONCLUSTERED INDEX [IX_Address_StateProvinceID] ON [Person].[Address]([StateProvinceID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.AddressType.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.AddressType.sql new file mode 100644 index 0000000..0e4b53d --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.AddressType.sql @@ -0,0 +1,15 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[AddressType]') AND type = 'U') +CREATE TABLE [Person].[AddressType] +( + [AddressTypeID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_AddressType_AddressTypeID] PRIMARY KEY CLUSTERED ([AddressTypeID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[AddressType]') AND name = 'AK_AddressType_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_AddressType_rowguid] ON [Person].[AddressType]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[AddressType]') AND name = 'AK_AddressType_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_AddressType_Name] ON [Person].[AddressType]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntity.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntity.sql new file mode 100644 index 0000000..98aa196 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntity.sql @@ -0,0 +1,11 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[BusinessEntity]') AND type = 'U') +CREATE TABLE [Person].[BusinessEntity] +( + [BusinessEntityID] int NOT NULL IDENTITY(1, 1), + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_BusinessEntity_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntity]') AND name = 'AK_BusinessEntity_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_BusinessEntity_rowguid] ON [Person].[BusinessEntity]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityAddress.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityAddress.sql new file mode 100644 index 0000000..0d54e09 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityAddress.sql @@ -0,0 +1,42 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[BusinessEntityAddress]') AND type = 'U') +CREATE TABLE [Person].[BusinessEntityAddress] +( + [BusinessEntityID] int NOT NULL, + [AddressID] int NOT NULL, + [AddressTypeID] int NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_BusinessEntityAddress_BusinessEntityID_AddressID_AddressTypeID] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [AddressID] ASC, + [AddressTypeID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityAddress_Address_AddressID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityAddress]')) +BEGIN + ALTER TABLE [Person].[BusinessEntityAddress] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityAddress_Address_AddressID] FOREIGN KEY ([AddressID]) REFERENCES [Person].[Address] ([AddressID]) + ALTER TABLE [Person].[BusinessEntityAddress] CHECK CONSTRAINT [FK_BusinessEntityAddress_Address_AddressID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityAddress_AddressType_AddressTypeID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityAddress]')) +BEGIN + ALTER TABLE [Person].[BusinessEntityAddress] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityAddress_AddressType_AddressTypeID] FOREIGN KEY ([AddressTypeID]) REFERENCES [Person].[AddressType] ([AddressTypeID]) + ALTER TABLE [Person].[BusinessEntityAddress] CHECK CONSTRAINT [FK_BusinessEntityAddress_AddressType_AddressTypeID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityAddress_BusinessEntity_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityAddress]')) +BEGIN + ALTER TABLE [Person].[BusinessEntityAddress] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityAddress_BusinessEntity_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[BusinessEntity] ([BusinessEntityID]) + ALTER TABLE [Person].[BusinessEntityAddress] CHECK CONSTRAINT [FK_BusinessEntityAddress_BusinessEntity_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityAddress]') AND name = 'AK_BusinessEntityAddress_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_BusinessEntityAddress_rowguid] ON [Person].[BusinessEntityAddress]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityAddress]') AND name = 'IX_BusinessEntityAddress_AddressID') +CREATE NONCLUSTERED INDEX [IX_BusinessEntityAddress_AddressID] ON [Person].[BusinessEntityAddress]([AddressID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityAddress]') AND name = 'IX_BusinessEntityAddress_AddressTypeID') +CREATE NONCLUSTERED INDEX [IX_BusinessEntityAddress_AddressTypeID] ON [Person].[BusinessEntityAddress]([AddressTypeID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityContact.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityContact.sql new file mode 100644 index 0000000..d107ca7 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityContact.sql @@ -0,0 +1,42 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[BusinessEntityContact]') AND type = 'U') +CREATE TABLE [Person].[BusinessEntityContact] +( + [BusinessEntityID] int NOT NULL, + [PersonID] int NOT NULL, + [ContactTypeID] int NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_BusinessEntityContact_BusinessEntityID_PersonID_ContactTypeID] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [PersonID] ASC, + [ContactTypeID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityContact_Person_PersonID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityContact]')) +BEGIN + ALTER TABLE [Person].[BusinessEntityContact] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityContact_Person_PersonID] FOREIGN KEY ([PersonID]) REFERENCES [Person].[Person] ([BusinessEntityID]) + ALTER TABLE [Person].[BusinessEntityContact] CHECK CONSTRAINT [FK_BusinessEntityContact_Person_PersonID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityContact_BusinessEntity_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityContact]')) +BEGIN + ALTER TABLE [Person].[BusinessEntityContact] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityContact_BusinessEntity_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[BusinessEntity] ([BusinessEntityID]) + ALTER TABLE [Person].[BusinessEntityContact] CHECK CONSTRAINT [FK_BusinessEntityContact_BusinessEntity_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityContact_ContactType_ContactTypeID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityContact]')) +BEGIN + ALTER TABLE [Person].[BusinessEntityContact] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityContact_ContactType_ContactTypeID] FOREIGN KEY ([ContactTypeID]) REFERENCES [Person].[ContactType] ([ContactTypeID]) + ALTER TABLE [Person].[BusinessEntityContact] CHECK CONSTRAINT [FK_BusinessEntityContact_ContactType_ContactTypeID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityContact]') AND name = 'AK_BusinessEntityContact_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_BusinessEntityContact_rowguid] ON [Person].[BusinessEntityContact]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityContact]') AND name = 'IX_BusinessEntityContact_PersonID') +CREATE NONCLUSTERED INDEX [IX_BusinessEntityContact_PersonID] ON [Person].[BusinessEntityContact]([PersonID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityContact]') AND name = 'IX_BusinessEntityContact_ContactTypeID') +CREATE NONCLUSTERED INDEX [IX_BusinessEntityContact_ContactTypeID] ON [Person].[BusinessEntityContact]([ContactTypeID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.ContactType.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.ContactType.sql new file mode 100644 index 0000000..405b993 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.ContactType.sql @@ -0,0 +1,11 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[ContactType]') AND type = 'U') +CREATE TABLE [Person].[ContactType] +( + [ContactTypeID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ContactType_ContactTypeID] PRIMARY KEY CLUSTERED ([ContactTypeID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[ContactType]') AND name = 'AK_ContactType_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ContactType_Name] ON [Person].[ContactType]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.CountryRegion.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.CountryRegion.sql new file mode 100644 index 0000000..ebe2601 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.CountryRegion.sql @@ -0,0 +1,11 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[CountryRegion]') AND type = 'U') +CREATE TABLE [Person].[CountryRegion] +( + [CountryRegionCode] nvarchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Name] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_CountryRegion_CountryRegionCode] PRIMARY KEY CLUSTERED ([CountryRegionCode] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[CountryRegion]') AND name = 'AK_CountryRegion_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_CountryRegion_Name] ON [Person].[CountryRegion]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.EmailAddress.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.EmailAddress.sql new file mode 100644 index 0000000..0686e34 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.EmailAddress.sql @@ -0,0 +1,23 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[EmailAddress]') AND type = 'U') +CREATE TABLE [Person].[EmailAddress] +( + [BusinessEntityID] int NOT NULL, + [EmailAddressID] int NOT NULL IDENTITY(1, 1), + [EmailAddress] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_EmailAddress_BusinessEntityID_EmailAddressID] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [EmailAddressID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_EmailAddress_Person_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Person].[EmailAddress]')) +BEGIN + ALTER TABLE [Person].[EmailAddress] WITH CHECK ADD CONSTRAINT [FK_EmailAddress_Person_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[Person] ([BusinessEntityID]) + ALTER TABLE [Person].[EmailAddress] CHECK CONSTRAINT [FK_EmailAddress_Person_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[EmailAddress]') AND name = 'IX_EmailAddress_EmailAddress') +CREATE NONCLUSTERED INDEX [IX_EmailAddress_EmailAddress] ON [Person].[EmailAddress]([EmailAddress] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.Password.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.Password.sql new file mode 100644 index 0000000..ae52518 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.Password.sql @@ -0,0 +1,16 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[Password]') AND type = 'U') +CREATE TABLE [Person].[Password] +( + [BusinessEntityID] int NOT NULL, + [PasswordHash] varchar(128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [PasswordSalt] varchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Password_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_Password_Person_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Person].[Password]')) +BEGIN + ALTER TABLE [Person].[Password] WITH CHECK ADD CONSTRAINT [FK_Password_Person_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[Person] ([BusinessEntityID]) + ALTER TABLE [Person].[Password] CHECK CONSTRAINT [FK_Password_Person_BusinessEntityID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.Person.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.Person.sql new file mode 100644 index 0000000..2ce2085 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.Person.sql @@ -0,0 +1,34 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[Person]') AND type = 'U') +CREATE TABLE [Person].[Person] +( + [BusinessEntityID] int NOT NULL, + [PersonType] nchar(2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [NameStyle] NameStyle NOT NULL DEFAULT((0)), + [Title] nvarchar(8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [FirstName] Name NOT NULL, + [MiddleName] Name NULL, + [LastName] Name NOT NULL, + [Suffix] nvarchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [EmailPromotion] int NOT NULL DEFAULT((0)), + [AdditionalContactInfo] xml NULL, + [Demographics] xml NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Person_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_Person_BusinessEntity_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Person].[Person]')) +BEGIN + ALTER TABLE [Person].[Person] WITH CHECK ADD CONSTRAINT [FK_Person_BusinessEntity_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[BusinessEntity] ([BusinessEntityID]) + ALTER TABLE [Person].[Person] CHECK CONSTRAINT [FK_Person_BusinessEntity_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[Person]') AND name = 'IX_Person_LastName_FirstName_MiddleName') +CREATE NONCLUSTERED INDEX [IX_Person_LastName_FirstName_MiddleName] ON [Person].[Person]( + [LastName] ASC, + [FirstName] ASC, + [MiddleName] ASC +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[Person]') AND name = 'AK_Person_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Person_rowguid] ON [Person].[Person]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.PersonPhone.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.PersonPhone.sql new file mode 100644 index 0000000..7957b15 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.PersonPhone.sql @@ -0,0 +1,29 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[PersonPhone]') AND type = 'U') +CREATE TABLE [Person].[PersonPhone] +( + [BusinessEntityID] int NOT NULL, + [PhoneNumber] Phone NOT NULL, + [PhoneNumberTypeID] int NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_PersonPhone_BusinessEntityID_PhoneNumber_PhoneNumberTypeID] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [PhoneNumber] ASC, + [PhoneNumberTypeID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_PersonPhone_Person_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Person].[PersonPhone]')) +BEGIN + ALTER TABLE [Person].[PersonPhone] WITH CHECK ADD CONSTRAINT [FK_PersonPhone_Person_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[Person] ([BusinessEntityID]) + ALTER TABLE [Person].[PersonPhone] CHECK CONSTRAINT [FK_PersonPhone_Person_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_PersonPhone_PhoneNumberType_PhoneNumberTypeID]') AND parent_object_id = OBJECT_ID('[Person].[PersonPhone]')) +BEGIN + ALTER TABLE [Person].[PersonPhone] WITH CHECK ADD CONSTRAINT [FK_PersonPhone_PhoneNumberType_PhoneNumberTypeID] FOREIGN KEY ([PhoneNumberTypeID]) REFERENCES [Person].[PhoneNumberType] ([PhoneNumberTypeID]) + ALTER TABLE [Person].[PersonPhone] CHECK CONSTRAINT [FK_PersonPhone_PhoneNumberType_PhoneNumberTypeID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[PersonPhone]') AND name = 'IX_PersonPhone_PhoneNumber') +CREATE NONCLUSTERED INDEX [IX_PersonPhone_PhoneNumber] ON [Person].[PersonPhone]([PhoneNumber] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.PhoneNumberType.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.PhoneNumberType.sql new file mode 100644 index 0000000..1109a8c --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.PhoneNumberType.sql @@ -0,0 +1,8 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[PhoneNumberType]') AND type = 'U') +CREATE TABLE [Person].[PhoneNumberType] +( + [PhoneNumberTypeID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_PhoneNumberType_PhoneNumberTypeID] PRIMARY KEY CLUSTERED ([PhoneNumberTypeID] ASC) +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.StateProvince.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.StateProvince.sql new file mode 100644 index 0000000..904a2b6 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.StateProvince.sql @@ -0,0 +1,37 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[StateProvince]') AND type = 'U') +CREATE TABLE [Person].[StateProvince] +( + [StateProvinceID] int NOT NULL IDENTITY(1, 1), + [StateProvinceCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [CountryRegionCode] nvarchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [IsOnlyStateProvinceFlag] Flag NOT NULL DEFAULT((1)), + [Name] Name NOT NULL, + [TerritoryID] int NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_StateProvince_StateProvinceID] PRIMARY KEY CLUSTERED ([StateProvinceID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_StateProvince_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Person].[StateProvince]')) +BEGIN + ALTER TABLE [Person].[StateProvince] WITH CHECK ADD CONSTRAINT [FK_StateProvince_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Person].[StateProvince] CHECK CONSTRAINT [FK_StateProvince_SalesTerritory_TerritoryID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_StateProvince_CountryRegion_CountryRegionCode]') AND parent_object_id = OBJECT_ID('[Person].[StateProvince]')) +BEGIN + ALTER TABLE [Person].[StateProvince] WITH CHECK ADD CONSTRAINT [FK_StateProvince_CountryRegion_CountryRegionCode] FOREIGN KEY ([CountryRegionCode]) REFERENCES [Person].[CountryRegion] ([CountryRegionCode]) + ALTER TABLE [Person].[StateProvince] CHECK CONSTRAINT [FK_StateProvince_CountryRegion_CountryRegionCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[StateProvince]') AND name = 'AK_StateProvince_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_StateProvince_Name] ON [Person].[StateProvince]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[StateProvince]') AND name = 'AK_StateProvince_StateProvinceCode_CountryRegionCode') +CREATE UNIQUE NONCLUSTERED INDEX [AK_StateProvince_StateProvinceCode_CountryRegionCode] ON [Person].[StateProvince]( + [StateProvinceCode] ASC, + [CountryRegionCode] ASC +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[StateProvince]') AND name = 'AK_StateProvince_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_StateProvince_rowguid] ON [Person].[StateProvince]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.BillOfMaterials.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.BillOfMaterials.sql new file mode 100644 index 0000000..2c2953a --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.BillOfMaterials.sql @@ -0,0 +1,42 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[BillOfMaterials]') AND type = 'U') +CREATE TABLE [Production].[BillOfMaterials] +( + [BillOfMaterialsID] int NOT NULL IDENTITY(1, 1), + [ProductAssemblyID] int NULL, + [ComponentID] int NOT NULL, + [StartDate] datetime NOT NULL DEFAULT(getdate()), + [EndDate] datetime NULL, + [UnitMeasureCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [BOMLevel] smallint NOT NULL, + [PerAssemblyQty] decimal(8, 2) NOT NULL DEFAULT((1.00)), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_BillOfMaterials_BillOfMaterialsID] PRIMARY KEY NONCLUSTERED ([BillOfMaterialsID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_BillOfMaterials_Product_ProductAssemblyID]') AND parent_object_id = OBJECT_ID('[Production].[BillOfMaterials]')) +BEGIN + ALTER TABLE [Production].[BillOfMaterials] WITH CHECK ADD CONSTRAINT [FK_BillOfMaterials_Product_ProductAssemblyID] FOREIGN KEY ([ProductAssemblyID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[BillOfMaterials] CHECK CONSTRAINT [FK_BillOfMaterials_Product_ProductAssemblyID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_BillOfMaterials_Product_ComponentID]') AND parent_object_id = OBJECT_ID('[Production].[BillOfMaterials]')) +BEGIN + ALTER TABLE [Production].[BillOfMaterials] WITH CHECK ADD CONSTRAINT [FK_BillOfMaterials_Product_ComponentID] FOREIGN KEY ([ComponentID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[BillOfMaterials] CHECK CONSTRAINT [FK_BillOfMaterials_Product_ComponentID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_BillOfMaterials_UnitMeasure_UnitMeasureCode]') AND parent_object_id = OBJECT_ID('[Production].[BillOfMaterials]')) +BEGIN + ALTER TABLE [Production].[BillOfMaterials] WITH CHECK ADD CONSTRAINT [FK_BillOfMaterials_UnitMeasure_UnitMeasureCode] FOREIGN KEY ([UnitMeasureCode]) REFERENCES [Production].[UnitMeasure] ([UnitMeasureCode]) + ALTER TABLE [Production].[BillOfMaterials] CHECK CONSTRAINT [FK_BillOfMaterials_UnitMeasure_UnitMeasureCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[BillOfMaterials]') AND name = 'AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate') +CREATE UNIQUE CLUSTERED INDEX [AK_BillOfMaterials_ProductAssemblyID_ComponentID_StartDate] ON [Production].[BillOfMaterials]( + [ProductAssemblyID] ASC, + [ComponentID] ASC, + [StartDate] ASC +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[BillOfMaterials]') AND name = 'IX_BillOfMaterials_UnitMeasureCode') +CREATE NONCLUSTERED INDEX [IX_BillOfMaterials_UnitMeasureCode] ON [Production].[BillOfMaterials]([UnitMeasureCode] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Culture.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Culture.sql new file mode 100644 index 0000000..cbedfbd --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Culture.sql @@ -0,0 +1,11 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[Culture]') AND type = 'U') +CREATE TABLE [Production].[Culture] +( + [CultureID] nchar(6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Name] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Culture_CultureID] PRIMARY KEY CLUSTERED ([CultureID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Culture]') AND name = 'AK_Culture_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Culture_Name] ON [Production].[Culture]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Document.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Document.sql new file mode 100644 index 0000000..414e745 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Document.sql @@ -0,0 +1,43 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[Document]') AND type = 'U') +CREATE TABLE [Production].[Document] +( + [DocumentNode] hierarchyid NOT NULL, + [DocumentLevel] AS ([DocumentNode].[GetLevel]()), + [Title] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Owner] int NOT NULL, + [FolderFlag] bit NOT NULL DEFAULT((0)), + [FileName] nvarchar(400) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [FileExtension] nvarchar(8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Revision] nchar(5) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [ChangeNumber] int NOT NULL DEFAULT((0)), + [Status] tinyint NOT NULL, + [DocumentSummary] nvarchar(max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [Document] varbinary(max) NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Document_DocumentNode] PRIMARY KEY CLUSTERED ([DocumentNode] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Document_Employee_Owner]') AND parent_object_id = OBJECT_ID('[Production].[Document]')) +BEGIN + ALTER TABLE [Production].[Document] WITH CHECK ADD CONSTRAINT [FK_Document_Employee_Owner] FOREIGN KEY ([Owner]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) + ALTER TABLE [Production].[Document] CHECK CONSTRAINT [FK_Document_Employee_Owner] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Document]') AND name = 'AK_Document_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Document_rowguid] ON [Production].[Document]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Document]') AND name = 'IX_Document_FileName_Revision') +CREATE NONCLUSTERED INDEX [IX_Document_FileName_Revision] ON [Production].[Document]( + [FileName] ASC, + [Revision] ASC +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Document]') AND name = 'UQ__Document__F73921F7C5112C2E') +CREATE UNIQUE NONCLUSTERED INDEX [UQ__Document__F73921F7C5112C2E] ON [Production].[Document]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Document]') AND name = 'AK_Document_DocumentLevel_DocumentNode') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Document_DocumentLevel_DocumentNode] ON [Production].[Document]( + [DocumentLevel] ASC, + [DocumentNode] ASC +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Illustration.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Illustration.sql new file mode 100644 index 0000000..60f6e84 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Illustration.sql @@ -0,0 +1,8 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[Illustration]') AND type = 'U') +CREATE TABLE [Production].[Illustration] +( + [IllustrationID] int NOT NULL IDENTITY(1, 1), + [Diagram] xml NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Illustration_IllustrationID] PRIMARY KEY CLUSTERED ([IllustrationID] ASC) +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Location.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Location.sql new file mode 100644 index 0000000..c7fe1ff --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Location.sql @@ -0,0 +1,13 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[Location]') AND type = 'U') +CREATE TABLE [Production].[Location] +( + [LocationID] smallint NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [CostRate] smallmoney NOT NULL DEFAULT((0.00)), + [Availability] decimal(8, 2) NOT NULL DEFAULT((0.00)), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Location_LocationID] PRIMARY KEY CLUSTERED ([LocationID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Location]') AND name = 'AK_Location_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Location_Name] ON [Production].[Location]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Product.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Product.sql new file mode 100644 index 0000000..dbc9cca --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Product.sql @@ -0,0 +1,63 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[Product]') AND type = 'U') +CREATE TABLE [Production].[Product] +( + [ProductID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [ProductNumber] nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [MakeFlag] Flag NOT NULL DEFAULT((1)), + [FinishedGoodsFlag] Flag NOT NULL DEFAULT((1)), + [Color] nvarchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [SafetyStockLevel] smallint NOT NULL, + [ReorderPoint] smallint NOT NULL, + [StandardCost] money NOT NULL, + [ListPrice] money NOT NULL, + [Size] nvarchar(5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [SizeUnitMeasureCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [WeightUnitMeasureCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [Weight] decimal(8, 2) NULL, + [DaysToManufacture] int NOT NULL, + [ProductLine] nchar(2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [Class] nchar(2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [Style] nchar(2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [ProductSubcategoryID] int NULL, + [ProductModelID] int NULL, + [SellStartDate] datetime NOT NULL, + [SellEndDate] datetime NULL, + [DiscontinuedDate] datetime NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Product_ProductID] PRIMARY KEY CLUSTERED ([ProductID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_ProductModel_ProductModelID]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) +BEGIN + ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [Production].[ProductModel] ([ProductModelID]) + ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_ProductModel_ProductModelID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_ProductSubcategory_ProductSubcategoryID]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) +BEGIN + ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_ProductSubcategory_ProductSubcategoryID] FOREIGN KEY ([ProductSubcategoryID]) REFERENCES [Production].[ProductSubcategory] ([ProductSubcategoryID]) + ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_ProductSubcategory_ProductSubcategoryID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_UnitMeasure_SizeUnitMeasureCode]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) +BEGIN + ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_UnitMeasure_SizeUnitMeasureCode] FOREIGN KEY ([SizeUnitMeasureCode]) REFERENCES [Production].[UnitMeasure] ([UnitMeasureCode]) + ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_UnitMeasure_SizeUnitMeasureCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_UnitMeasure_WeightUnitMeasureCode]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) +BEGIN + ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_UnitMeasure_WeightUnitMeasureCode] FOREIGN KEY ([WeightUnitMeasureCode]) REFERENCES [Production].[UnitMeasure] ([UnitMeasureCode]) + ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_UnitMeasure_WeightUnitMeasureCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Product]') AND name = 'AK_Product_ProductNumber') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Product_ProductNumber] ON [Production].[Product]([ProductNumber] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Product]') AND name = 'AK_Product_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Product_Name] ON [Production].[Product]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Product]') AND name = 'AK_Product_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Product_rowguid] ON [Production].[Product]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductCategory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductCategory.sql new file mode 100644 index 0000000..f554f41 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductCategory.sql @@ -0,0 +1,15 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductCategory]') AND type = 'U') +CREATE TABLE [Production].[ProductCategory] +( + [ProductCategoryID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductCategory_ProductCategoryID] PRIMARY KEY CLUSTERED ([ProductCategoryID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ProductCategory]') AND name = 'AK_ProductCategory_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ProductCategory_Name] ON [Production].[ProductCategory]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ProductCategory]') AND name = 'AK_ProductCategory_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ProductCategory_rowguid] ON [Production].[ProductCategory]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductCostHistory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductCostHistory.sql new file mode 100644 index 0000000..a7cf6ec --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductCostHistory.sql @@ -0,0 +1,20 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductCostHistory]') AND type = 'U') +CREATE TABLE [Production].[ProductCostHistory] +( + [ProductID] int NOT NULL, + [StartDate] datetime NOT NULL, + [EndDate] datetime NULL, + [StandardCost] money NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductCostHistory_ProductID_StartDate] PRIMARY KEY CLUSTERED + ( + [ProductID] ASC, + [StartDate] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductCostHistory_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Production].[ProductCostHistory]')) +BEGIN + ALTER TABLE [Production].[ProductCostHistory] WITH CHECK ADD CONSTRAINT [FK_ProductCostHistory_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[ProductCostHistory] CHECK CONSTRAINT [FK_ProductCostHistory_Product_ProductID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductDescription.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductDescription.sql new file mode 100644 index 0000000..f151649 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductDescription.sql @@ -0,0 +1,12 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductDescription]') AND type = 'U') +CREATE TABLE [Production].[ProductDescription] +( + [ProductDescriptionID] int NOT NULL IDENTITY(1, 1), + [Description] nvarchar(400) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductDescription_ProductDescriptionID] PRIMARY KEY CLUSTERED ([ProductDescriptionID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ProductDescription]') AND name = 'AK_ProductDescription_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ProductDescription_rowguid] ON [Production].[ProductDescription]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductDocument.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductDocument.sql new file mode 100644 index 0000000..c837f36 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductDocument.sql @@ -0,0 +1,24 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductDocument]') AND type = 'U') +CREATE TABLE [Production].[ProductDocument] +( + [ProductID] int NOT NULL, + [DocumentNode] hierarchyid NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductDocument_ProductID_DocumentNode] PRIMARY KEY CLUSTERED + ( + [ProductID] ASC, + [DocumentNode] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductDocument_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Production].[ProductDocument]')) +BEGIN + ALTER TABLE [Production].[ProductDocument] WITH CHECK ADD CONSTRAINT [FK_ProductDocument_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[ProductDocument] CHECK CONSTRAINT [FK_ProductDocument_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductDocument_Document_DocumentNode]') AND parent_object_id = OBJECT_ID('[Production].[ProductDocument]')) +BEGIN + ALTER TABLE [Production].[ProductDocument] WITH CHECK ADD CONSTRAINT [FK_ProductDocument_Document_DocumentNode] FOREIGN KEY ([DocumentNode]) REFERENCES [Production].[Document] ([DocumentNode]) + ALTER TABLE [Production].[ProductDocument] CHECK CONSTRAINT [FK_ProductDocument_Document_DocumentNode] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductInventory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductInventory.sql new file mode 100644 index 0000000..8c83e22 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductInventory.sql @@ -0,0 +1,28 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductInventory]') AND type = 'U') +CREATE TABLE [Production].[ProductInventory] +( + [ProductID] int NOT NULL, + [LocationID] smallint NOT NULL, + [Shelf] nvarchar(10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Bin] tinyint NOT NULL, + [Quantity] smallint NOT NULL DEFAULT((0)), + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductInventory_ProductID_LocationID] PRIMARY KEY CLUSTERED + ( + [ProductID] ASC, + [LocationID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductInventory_Location_LocationID]') AND parent_object_id = OBJECT_ID('[Production].[ProductInventory]')) +BEGIN + ALTER TABLE [Production].[ProductInventory] WITH CHECK ADD CONSTRAINT [FK_ProductInventory_Location_LocationID] FOREIGN KEY ([LocationID]) REFERENCES [Production].[Location] ([LocationID]) + ALTER TABLE [Production].[ProductInventory] CHECK CONSTRAINT [FK_ProductInventory_Location_LocationID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductInventory_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Production].[ProductInventory]')) +BEGIN + ALTER TABLE [Production].[ProductInventory] WITH CHECK ADD CONSTRAINT [FK_ProductInventory_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[ProductInventory] CHECK CONSTRAINT [FK_ProductInventory_Product_ProductID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductListPriceHistory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductListPriceHistory.sql new file mode 100644 index 0000000..897b62a --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductListPriceHistory.sql @@ -0,0 +1,20 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductListPriceHistory]') AND type = 'U') +CREATE TABLE [Production].[ProductListPriceHistory] +( + [ProductID] int NOT NULL, + [StartDate] datetime NOT NULL, + [EndDate] datetime NULL, + [ListPrice] money NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductListPriceHistory_ProductID_StartDate] PRIMARY KEY CLUSTERED + ( + [ProductID] ASC, + [StartDate] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductListPriceHistory_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Production].[ProductListPriceHistory]')) +BEGIN + ALTER TABLE [Production].[ProductListPriceHistory] WITH CHECK ADD CONSTRAINT [FK_ProductListPriceHistory_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[ProductListPriceHistory] CHECK CONSTRAINT [FK_ProductListPriceHistory_Product_ProductID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModel.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModel.sql new file mode 100644 index 0000000..1dfecc2 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModel.sql @@ -0,0 +1,17 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductModel]') AND type = 'U') +CREATE TABLE [Production].[ProductModel] +( + [ProductModelID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [CatalogDescription] xml NULL, + [Instructions] xml NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductModel_ProductModelID] PRIMARY KEY CLUSTERED ([ProductModelID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ProductModel]') AND name = 'AK_ProductModel_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ProductModel_Name] ON [Production].[ProductModel]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ProductModel]') AND name = 'AK_ProductModel_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ProductModel_rowguid] ON [Production].[ProductModel]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelIllustration.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelIllustration.sql new file mode 100644 index 0000000..2a082a2 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelIllustration.sql @@ -0,0 +1,24 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductModelIllustration]') AND type = 'U') +CREATE TABLE [Production].[ProductModelIllustration] +( + [ProductModelID] int NOT NULL, + [IllustrationID] int NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductModelIllustration_ProductModelID_IllustrationID] PRIMARY KEY CLUSTERED + ( + [ProductModelID] ASC, + [IllustrationID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelIllustration_Illustration_IllustrationID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelIllustration]')) +BEGIN + ALTER TABLE [Production].[ProductModelIllustration] WITH CHECK ADD CONSTRAINT [FK_ProductModelIllustration_Illustration_IllustrationID] FOREIGN KEY ([IllustrationID]) REFERENCES [Production].[Illustration] ([IllustrationID]) + ALTER TABLE [Production].[ProductModelIllustration] CHECK CONSTRAINT [FK_ProductModelIllustration_Illustration_IllustrationID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelIllustration_ProductModel_ProductModelID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelIllustration]')) +BEGIN + ALTER TABLE [Production].[ProductModelIllustration] WITH CHECK ADD CONSTRAINT [FK_ProductModelIllustration_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [Production].[ProductModel] ([ProductModelID]) + ALTER TABLE [Production].[ProductModelIllustration] CHECK CONSTRAINT [FK_ProductModelIllustration_ProductModel_ProductModelID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql new file mode 100644 index 0000000..a5c5b62 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql @@ -0,0 +1,32 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductModelProductDescriptionCulture]') AND type = 'U') +CREATE TABLE [Production].[ProductModelProductDescriptionCulture] +( + [ProductModelID] int NOT NULL, + [ProductDescriptionID] int NOT NULL, + [CultureID] nchar(6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductModelProductDescriptionCulture_ProductModelID_ProductDescriptionID_CultureID] PRIMARY KEY CLUSTERED + ( + [ProductModelID] ASC, + [ProductDescriptionID] ASC, + [CultureID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelProductDescriptionCulture]')) +BEGIN + ALTER TABLE [Production].[ProductModelProductDescriptionCulture] WITH CHECK ADD CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionID] FOREIGN KEY ([ProductDescriptionID]) REFERENCES [Production].[ProductDescription] ([ProductDescriptionID]) + ALTER TABLE [Production].[ProductModelProductDescriptionCulture] CHECK CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelProductDescriptionCulture]')) +BEGIN + ALTER TABLE [Production].[ProductModelProductDescriptionCulture] WITH CHECK ADD CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [Production].[ProductModel] ([ProductModelID]) + ALTER TABLE [Production].[ProductModelProductDescriptionCulture] CHECK CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelProductDescriptionCulture_Culture_CultureID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelProductDescriptionCulture]')) +BEGIN + ALTER TABLE [Production].[ProductModelProductDescriptionCulture] WITH CHECK ADD CONSTRAINT [FK_ProductModelProductDescriptionCulture_Culture_CultureID] FOREIGN KEY ([CultureID]) REFERENCES [Production].[Culture] ([CultureID]) + ALTER TABLE [Production].[ProductModelProductDescriptionCulture] CHECK CONSTRAINT [FK_ProductModelProductDescriptionCulture_Culture_CultureID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductPhoto.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductPhoto.sql new file mode 100644 index 0000000..4644678 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductPhoto.sql @@ -0,0 +1,11 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductPhoto]') AND type = 'U') +CREATE TABLE [Production].[ProductPhoto] +( + [ProductPhotoID] int NOT NULL IDENTITY(1, 1), + [ThumbNailPhoto] varbinary(max) NULL, + [ThumbnailPhotoFileName] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [LargePhoto] varbinary(max) NULL, + [LargePhotoFileName] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductPhoto_ProductPhotoID] PRIMARY KEY CLUSTERED ([ProductPhotoID] ASC) +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductProductPhoto.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductProductPhoto.sql new file mode 100644 index 0000000..d38b0dc --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductProductPhoto.sql @@ -0,0 +1,25 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductProductPhoto]') AND type = 'U') +CREATE TABLE [Production].[ProductProductPhoto] +( + [ProductID] int NOT NULL, + [ProductPhotoID] int NOT NULL, + [Primary] Flag NOT NULL DEFAULT((0)), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductProductPhoto_ProductID_ProductPhotoID] PRIMARY KEY NONCLUSTERED + ( + [ProductID] ASC, + [ProductPhotoID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductProductPhoto_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Production].[ProductProductPhoto]')) +BEGIN + ALTER TABLE [Production].[ProductProductPhoto] WITH CHECK ADD CONSTRAINT [FK_ProductProductPhoto_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[ProductProductPhoto] CHECK CONSTRAINT [FK_ProductProductPhoto_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductProductPhoto_ProductPhoto_ProductPhotoID]') AND parent_object_id = OBJECT_ID('[Production].[ProductProductPhoto]')) +BEGIN + ALTER TABLE [Production].[ProductProductPhoto] WITH CHECK ADD CONSTRAINT [FK_ProductProductPhoto_ProductPhoto_ProductPhotoID] FOREIGN KEY ([ProductPhotoID]) REFERENCES [Production].[ProductPhoto] ([ProductPhotoID]) + ALTER TABLE [Production].[ProductProductPhoto] CHECK CONSTRAINT [FK_ProductProductPhoto_ProductPhoto_ProductPhotoID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductReview.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductReview.sql new file mode 100644 index 0000000..a009731 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductReview.sql @@ -0,0 +1,25 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductReview]') AND type = 'U') +CREATE TABLE [Production].[ProductReview] +( + [ProductReviewID] int NOT NULL IDENTITY(1, 1), + [ProductID] int NOT NULL, + [ReviewerName] Name NOT NULL, + [ReviewDate] datetime NOT NULL DEFAULT(getdate()), + [EmailAddress] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Rating] int NOT NULL, + [Comments] nvarchar(3850) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductReview_ProductReviewID] PRIMARY KEY CLUSTERED ([ProductReviewID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductReview_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Production].[ProductReview]')) +BEGIN + ALTER TABLE [Production].[ProductReview] WITH CHECK ADD CONSTRAINT [FK_ProductReview_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[ProductReview] CHECK CONSTRAINT [FK_ProductReview_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ProductReview]') AND name = 'IX_ProductReview_ProductID_Name') +CREATE NONCLUSTERED INDEX [IX_ProductReview_ProductID_Name] ON [Production].[ProductReview]( + [ProductID] ASC, + [ReviewerName] ASC +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductSubcategory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductSubcategory.sql new file mode 100644 index 0000000..2195751 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductSubcategory.sql @@ -0,0 +1,22 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ProductSubcategory]') AND type = 'U') +CREATE TABLE [Production].[ProductSubcategory] +( + [ProductSubcategoryID] int NOT NULL IDENTITY(1, 1), + [ProductCategoryID] int NOT NULL, + [Name] Name NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductSubcategory_ProductSubcategoryID] PRIMARY KEY CLUSTERED ([ProductSubcategoryID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductSubcategory_ProductCategory_ProductCategoryID]') AND parent_object_id = OBJECT_ID('[Production].[ProductSubcategory]')) +BEGIN + ALTER TABLE [Production].[ProductSubcategory] WITH CHECK ADD CONSTRAINT [FK_ProductSubcategory_ProductCategory_ProductCategoryID] FOREIGN KEY ([ProductCategoryID]) REFERENCES [Production].[ProductCategory] ([ProductCategoryID]) + ALTER TABLE [Production].[ProductSubcategory] CHECK CONSTRAINT [FK_ProductSubcategory_ProductCategory_ProductCategoryID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ProductSubcategory]') AND name = 'AK_ProductSubcategory_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ProductSubcategory_Name] ON [Production].[ProductSubcategory]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ProductSubcategory]') AND name = 'AK_ProductSubcategory_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ProductSubcategory_rowguid] ON [Production].[ProductSubcategory]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ScrapReason.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ScrapReason.sql new file mode 100644 index 0000000..3b58cc2 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ScrapReason.sql @@ -0,0 +1,11 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[ScrapReason]') AND type = 'U') +CREATE TABLE [Production].[ScrapReason] +( + [ScrapReasonID] smallint NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ScrapReason_ScrapReasonID] PRIMARY KEY CLUSTERED ([ScrapReasonID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[ScrapReason]') AND name = 'AK_ScrapReason_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ScrapReason_Name] ON [Production].[ScrapReason]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.TransactionHistory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.TransactionHistory.sql new file mode 100644 index 0000000..82d6b3a --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.TransactionHistory.sql @@ -0,0 +1,29 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[TransactionHistory]') AND type = 'U') +CREATE TABLE [Production].[TransactionHistory] +( + [TransactionID] int NOT NULL IDENTITY(100000, 1), + [ProductID] int NOT NULL, + [ReferenceOrderID] int NOT NULL, + [ReferenceOrderLineID] int NOT NULL DEFAULT((0)), + [TransactionDate] datetime NOT NULL DEFAULT(getdate()), + [TransactionType] nchar(1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Quantity] int NOT NULL, + [ActualCost] money NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_TransactionHistory_TransactionID] PRIMARY KEY CLUSTERED ([TransactionID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_TransactionHistory_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Production].[TransactionHistory]')) +BEGIN + ALTER TABLE [Production].[TransactionHistory] WITH CHECK ADD CONSTRAINT [FK_TransactionHistory_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[TransactionHistory] CHECK CONSTRAINT [FK_TransactionHistory_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[TransactionHistory]') AND name = 'IX_TransactionHistory_ProductID') +CREATE NONCLUSTERED INDEX [IX_TransactionHistory_ProductID] ON [Production].[TransactionHistory]([ProductID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[TransactionHistory]') AND name = 'IX_TransactionHistory_ReferenceOrderID_ReferenceOrderLineID') +CREATE NONCLUSTERED INDEX [IX_TransactionHistory_ReferenceOrderID_ReferenceOrderLineID] ON [Production].[TransactionHistory]( + [ReferenceOrderID] ASC, + [ReferenceOrderLineID] ASC +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.TransactionHistoryArchive.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.TransactionHistoryArchive.sql new file mode 100644 index 0000000..2034e83 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.TransactionHistoryArchive.sql @@ -0,0 +1,23 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[TransactionHistoryArchive]') AND type = 'U') +CREATE TABLE [Production].[TransactionHistoryArchive] +( + [TransactionID] int NOT NULL, + [ProductID] int NOT NULL, + [ReferenceOrderID] int NOT NULL, + [ReferenceOrderLineID] int NOT NULL DEFAULT((0)), + [TransactionDate] datetime NOT NULL DEFAULT(getdate()), + [TransactionType] nchar(1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Quantity] int NOT NULL, + [ActualCost] money NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_TransactionHistoryArchive_TransactionID] PRIMARY KEY CLUSTERED ([TransactionID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[TransactionHistoryArchive]') AND name = 'IX_TransactionHistoryArchive_ProductID') +CREATE NONCLUSTERED INDEX [IX_TransactionHistoryArchive_ProductID] ON [Production].[TransactionHistoryArchive]([ProductID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[TransactionHistoryArchive]') AND name = 'IX_TransactionHistoryArchive_ReferenceOrderID_ReferenceOrderLineID') +CREATE NONCLUSTERED INDEX [IX_TransactionHistoryArchive_ReferenceOrderID_ReferenceOrderLineID] ON [Production].[TransactionHistoryArchive]( + [ReferenceOrderID] ASC, + [ReferenceOrderLineID] ASC +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.UnitMeasure.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.UnitMeasure.sql new file mode 100644 index 0000000..184be57 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.UnitMeasure.sql @@ -0,0 +1,11 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[UnitMeasure]') AND type = 'U') +CREATE TABLE [Production].[UnitMeasure] +( + [UnitMeasureCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Name] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_UnitMeasure_UnitMeasureCode] PRIMARY KEY CLUSTERED ([UnitMeasureCode] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[UnitMeasure]') AND name = 'AK_UnitMeasure_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_UnitMeasure_Name] ON [Production].[UnitMeasure]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrder.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrder.sql new file mode 100644 index 0000000..b47daa5 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrder.sql @@ -0,0 +1,33 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[WorkOrder]') AND type = 'U') +CREATE TABLE [Production].[WorkOrder] +( + [WorkOrderID] int NOT NULL IDENTITY(1, 1), + [ProductID] int NOT NULL, + [OrderQty] int NOT NULL, + [StockedQty] AS (isnull([OrderQty]-[ScrappedQty],(0))), + [ScrappedQty] smallint NOT NULL, + [StartDate] datetime NOT NULL, + [EndDate] datetime NULL, + [DueDate] datetime NOT NULL, + [ScrapReasonID] smallint NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_WorkOrder_WorkOrderID] PRIMARY KEY CLUSTERED ([WorkOrderID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_WorkOrder_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Production].[WorkOrder]')) +BEGIN + ALTER TABLE [Production].[WorkOrder] WITH CHECK ADD CONSTRAINT [FK_WorkOrder_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Production].[WorkOrder] CHECK CONSTRAINT [FK_WorkOrder_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_WorkOrder_ScrapReason_ScrapReasonID]') AND parent_object_id = OBJECT_ID('[Production].[WorkOrder]')) +BEGIN + ALTER TABLE [Production].[WorkOrder] WITH CHECK ADD CONSTRAINT [FK_WorkOrder_ScrapReason_ScrapReasonID] FOREIGN KEY ([ScrapReasonID]) REFERENCES [Production].[ScrapReason] ([ScrapReasonID]) + ALTER TABLE [Production].[WorkOrder] CHECK CONSTRAINT [FK_WorkOrder_ScrapReason_ScrapReasonID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[WorkOrder]') AND name = 'IX_WorkOrder_ScrapReasonID') +CREATE NONCLUSTERED INDEX [IX_WorkOrder_ScrapReasonID] ON [Production].[WorkOrder]([ScrapReasonID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[WorkOrder]') AND name = 'IX_WorkOrder_ProductID') +CREATE NONCLUSTERED INDEX [IX_WorkOrder_ProductID] ON [Production].[WorkOrder]([ProductID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrderRouting.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrderRouting.sql new file mode 100644 index 0000000..d276ab5 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrderRouting.sql @@ -0,0 +1,37 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[WorkOrderRouting]') AND type = 'U') +CREATE TABLE [Production].[WorkOrderRouting] +( + [WorkOrderID] int NOT NULL, + [ProductID] int NOT NULL, + [OperationSequence] smallint NOT NULL, + [LocationID] smallint NOT NULL, + [ScheduledStartDate] datetime NOT NULL, + [ScheduledEndDate] datetime NOT NULL, + [ActualStartDate] datetime NULL, + [ActualEndDate] datetime NULL, + [ActualResourceHrs] decimal(9, 4) NULL, + [PlannedCost] money NOT NULL, + [ActualCost] money NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_WorkOrderRouting_WorkOrderID_ProductID_OperationSequence] PRIMARY KEY CLUSTERED + ( + [WorkOrderID] ASC, + [ProductID] ASC, + [OperationSequence] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_WorkOrderRouting_Location_LocationID]') AND parent_object_id = OBJECT_ID('[Production].[WorkOrderRouting]')) +BEGIN + ALTER TABLE [Production].[WorkOrderRouting] WITH CHECK ADD CONSTRAINT [FK_WorkOrderRouting_Location_LocationID] FOREIGN KEY ([LocationID]) REFERENCES [Production].[Location] ([LocationID]) + ALTER TABLE [Production].[WorkOrderRouting] CHECK CONSTRAINT [FK_WorkOrderRouting_Location_LocationID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_WorkOrderRouting_WorkOrder_WorkOrderID]') AND parent_object_id = OBJECT_ID('[Production].[WorkOrderRouting]')) +BEGIN + ALTER TABLE [Production].[WorkOrderRouting] WITH CHECK ADD CONSTRAINT [FK_WorkOrderRouting_WorkOrder_WorkOrderID] FOREIGN KEY ([WorkOrderID]) REFERENCES [Production].[WorkOrder] ([WorkOrderID]) + ALTER TABLE [Production].[WorkOrderRouting] CHECK CONSTRAINT [FK_WorkOrderRouting_WorkOrder_WorkOrderID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[WorkOrderRouting]') AND name = 'IX_WorkOrderRouting_ProductID') +CREATE NONCLUSTERED INDEX [IX_WorkOrderRouting_ProductID] ON [Production].[WorkOrderRouting]([ProductID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ProductVendor.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ProductVendor.sql new file mode 100644 index 0000000..0f323bd --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ProductVendor.sql @@ -0,0 +1,44 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[ProductVendor]') AND type = 'U') +CREATE TABLE [Purchasing].[ProductVendor] +( + [ProductID] int NOT NULL, + [BusinessEntityID] int NOT NULL, + [AverageLeadTime] int NOT NULL, + [StandardPrice] money NOT NULL, + [LastReceiptCost] money NULL, + [LastReceiptDate] datetime NULL, + [MinOrderQty] int NOT NULL, + [MaxOrderQty] int NOT NULL, + [OnOrderQty] int NULL, + [UnitMeasureCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ProductVendor_ProductID_BusinessEntityID] PRIMARY KEY CLUSTERED + ( + [ProductID] ASC, + [BusinessEntityID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_ProductVendor_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Purchasing].[ProductVendor]')) +BEGIN + ALTER TABLE [Purchasing].[ProductVendor] WITH CHECK ADD CONSTRAINT [FK_ProductVendor_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Purchasing].[ProductVendor] CHECK CONSTRAINT [FK_ProductVendor_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_ProductVendor_UnitMeasure_UnitMeasureCode]') AND parent_object_id = OBJECT_ID('[Purchasing].[ProductVendor]')) +BEGIN + ALTER TABLE [Purchasing].[ProductVendor] WITH CHECK ADD CONSTRAINT [FK_ProductVendor_UnitMeasure_UnitMeasureCode] FOREIGN KEY ([UnitMeasureCode]) REFERENCES [Production].[UnitMeasure] ([UnitMeasureCode]) + ALTER TABLE [Purchasing].[ProductVendor] CHECK CONSTRAINT [FK_ProductVendor_UnitMeasure_UnitMeasureCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_ProductVendor_Vendor_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Purchasing].[ProductVendor]')) +BEGIN + ALTER TABLE [Purchasing].[ProductVendor] WITH CHECK ADD CONSTRAINT [FK_ProductVendor_Vendor_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Purchasing].[Vendor] ([BusinessEntityID]) + ALTER TABLE [Purchasing].[ProductVendor] CHECK CONSTRAINT [FK_ProductVendor_Vendor_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[ProductVendor]') AND name = 'IX_ProductVendor_UnitMeasureCode') +CREATE NONCLUSTERED INDEX [IX_ProductVendor_UnitMeasureCode] ON [Purchasing].[ProductVendor]([UnitMeasureCode] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[ProductVendor]') AND name = 'IX_ProductVendor_BusinessEntityID') +CREATE NONCLUSTERED INDEX [IX_ProductVendor_BusinessEntityID] ON [Purchasing].[ProductVendor]([BusinessEntityID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderDetail.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderDetail.sql new file mode 100644 index 0000000..d76f756 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderDetail.sql @@ -0,0 +1,35 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[PurchaseOrderDetail]') AND type = 'U') +CREATE TABLE [Purchasing].[PurchaseOrderDetail] +( + [PurchaseOrderID] int NOT NULL, + [PurchaseOrderDetailID] int NOT NULL IDENTITY(1, 1), + [DueDate] datetime NOT NULL, + [OrderQty] smallint NOT NULL, + [ProductID] int NOT NULL, + [UnitPrice] money NOT NULL, + [LineTotal] AS (isnull([OrderQty]*[UnitPrice],(0.00))), + [ReceivedQty] decimal(8, 2) NOT NULL, + [RejectedQty] decimal(8, 2) NOT NULL, + [StockedQty] AS (isnull([ReceivedQty]-[RejectedQty],(0.00))), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_PurchaseOrderDetail_PurchaseOrderID_PurchaseOrderDetailID] PRIMARY KEY CLUSTERED + ( + [PurchaseOrderID] ASC, + [PurchaseOrderDetailID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderDetail_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderDetail]')) +BEGIN + ALTER TABLE [Purchasing].[PurchaseOrderDetail] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderDetail_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Purchasing].[PurchaseOrderDetail] CHECK CONSTRAINT [FK_PurchaseOrderDetail_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderDetail]')) +BEGIN + ALTER TABLE [Purchasing].[PurchaseOrderDetail] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderID] FOREIGN KEY ([PurchaseOrderID]) REFERENCES [Purchasing].[PurchaseOrderHeader] ([PurchaseOrderID]) + ALTER TABLE [Purchasing].[PurchaseOrderDetail] CHECK CONSTRAINT [FK_PurchaseOrderDetail_PurchaseOrderHeader_PurchaseOrderID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[PurchaseOrderDetail]') AND name = 'IX_PurchaseOrderDetail_ProductID') +CREATE NONCLUSTERED INDEX [IX_PurchaseOrderDetail_ProductID] ON [Purchasing].[PurchaseOrderDetail]([ProductID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderHeader.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderHeader.sql new file mode 100644 index 0000000..4d1d3d0 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderHeader.sql @@ -0,0 +1,42 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]') AND type = 'U') +CREATE TABLE [Purchasing].[PurchaseOrderHeader] +( + [PurchaseOrderID] int NOT NULL IDENTITY(1, 1), + [RevisionNumber] tinyint NOT NULL DEFAULT((0)), + [Status] tinyint NOT NULL DEFAULT((1)), + [EmployeeID] int NOT NULL, + [VendorID] int NOT NULL, + [ShipMethodID] int NOT NULL, + [OrderDate] datetime NOT NULL DEFAULT(getdate()), + [ShipDate] datetime NULL, + [SubTotal] money NOT NULL DEFAULT((0.00)), + [TaxAmt] money NOT NULL DEFAULT((0.00)), + [Freight] money NOT NULL DEFAULT((0.00)), + [TotalDue] AS (isnull(([SubTotal]+[TaxAmt])+[Freight],(0))) PERSISTED NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_PurchaseOrderHeader_PurchaseOrderID] PRIMARY KEY CLUSTERED ([PurchaseOrderID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderHeader_ShipMethod_ShipMethodID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]')) +BEGIN + ALTER TABLE [Purchasing].[PurchaseOrderHeader] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY ([ShipMethodID]) REFERENCES [Purchasing].[ShipMethod] ([ShipMethodID]) + ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_ShipMethod_ShipMethodID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderHeader_Vendor_VendorID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]')) +BEGIN + ALTER TABLE [Purchasing].[PurchaseOrderHeader] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderHeader_Vendor_VendorID] FOREIGN KEY ([VendorID]) REFERENCES [Purchasing].[Vendor] ([BusinessEntityID]) + ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_Vendor_VendorID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderHeader_Employee_EmployeeID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]')) +BEGIN + ALTER TABLE [Purchasing].[PurchaseOrderHeader] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderHeader_Employee_EmployeeID] FOREIGN KEY ([EmployeeID]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) + ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_Employee_EmployeeID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]') AND name = 'IX_PurchaseOrderHeader_VendorID') +CREATE NONCLUSTERED INDEX [IX_PurchaseOrderHeader_VendorID] ON [Purchasing].[PurchaseOrderHeader]([VendorID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]') AND name = 'IX_PurchaseOrderHeader_EmployeeID') +CREATE NONCLUSTERED INDEX [IX_PurchaseOrderHeader_EmployeeID] ON [Purchasing].[PurchaseOrderHeader]([EmployeeID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ShipMethod.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ShipMethod.sql new file mode 100644 index 0000000..2e0502f --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ShipMethod.sql @@ -0,0 +1,17 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[ShipMethod]') AND type = 'U') +CREATE TABLE [Purchasing].[ShipMethod] +( + [ShipMethodID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [ShipBase] money NOT NULL DEFAULT((0.00)), + [ShipRate] money NOT NULL DEFAULT((0.00)), + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ShipMethod_ShipMethodID] PRIMARY KEY CLUSTERED ([ShipMethodID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[ShipMethod]') AND name = 'AK_ShipMethod_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ShipMethod_Name] ON [Purchasing].[ShipMethod]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[ShipMethod]') AND name = 'AK_ShipMethod_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_ShipMethod_rowguid] ON [Purchasing].[ShipMethod]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.Vendor.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.Vendor.sql new file mode 100644 index 0000000..38c6570 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.Vendor.sql @@ -0,0 +1,22 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[Vendor]') AND type = 'U') +CREATE TABLE [Purchasing].[Vendor] +( + [BusinessEntityID] int NOT NULL, + [AccountNumber] AccountNumber NOT NULL, + [Name] Name NOT NULL, + [CreditRating] tinyint NOT NULL, + [PreferredVendorStatus] Flag NOT NULL DEFAULT((1)), + [ActiveFlag] Flag NOT NULL DEFAULT((1)), + [PurchasingWebServiceURL] nvarchar(1024) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Vendor_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_Vendor_BusinessEntity_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Purchasing].[Vendor]')) +BEGIN + ALTER TABLE [Purchasing].[Vendor] WITH CHECK ADD CONSTRAINT [FK_Vendor_BusinessEntity_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[BusinessEntity] ([BusinessEntityID]) + ALTER TABLE [Purchasing].[Vendor] CHECK CONSTRAINT [FK_Vendor_BusinessEntity_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[Vendor]') AND name = 'AK_Vendor_AccountNumber') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Vendor_AccountNumber] ON [Purchasing].[Vendor]([AccountNumber] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CountryRegionCurrency.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CountryRegionCurrency.sql new file mode 100644 index 0000000..ac56c9f --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CountryRegionCurrency.sql @@ -0,0 +1,27 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[CountryRegionCurrency]') AND type = 'U') +CREATE TABLE [Sales].[CountryRegionCurrency] +( + [CountryRegionCode] nvarchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [CurrencyCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_CountryRegionCurrency_CountryRegionCode_CurrencyCode] PRIMARY KEY CLUSTERED + ( + [CountryRegionCode] ASC, + [CurrencyCode] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_CountryRegionCurrency_CountryRegion_CountryRegionCode]') AND parent_object_id = OBJECT_ID('[Sales].[CountryRegionCurrency]')) +BEGIN + ALTER TABLE [Sales].[CountryRegionCurrency] WITH CHECK ADD CONSTRAINT [FK_CountryRegionCurrency_CountryRegion_CountryRegionCode] FOREIGN KEY ([CountryRegionCode]) REFERENCES [Person].[CountryRegion] ([CountryRegionCode]) + ALTER TABLE [Sales].[CountryRegionCurrency] CHECK CONSTRAINT [FK_CountryRegionCurrency_CountryRegion_CountryRegionCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_CountryRegionCurrency_Currency_CurrencyCode]') AND parent_object_id = OBJECT_ID('[Sales].[CountryRegionCurrency]')) +BEGIN + ALTER TABLE [Sales].[CountryRegionCurrency] WITH CHECK ADD CONSTRAINT [FK_CountryRegionCurrency_Currency_CurrencyCode] FOREIGN KEY ([CurrencyCode]) REFERENCES [Sales].[Currency] ([CurrencyCode]) + ALTER TABLE [Sales].[CountryRegionCurrency] CHECK CONSTRAINT [FK_CountryRegionCurrency_Currency_CurrencyCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[CountryRegionCurrency]') AND name = 'IX_CountryRegionCurrency_CurrencyCode') +CREATE NONCLUSTERED INDEX [IX_CountryRegionCurrency_CurrencyCode] ON [Sales].[CountryRegionCurrency]([CurrencyCode] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CreditCard.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CreditCard.sql new file mode 100644 index 0000000..9292a53 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CreditCard.sql @@ -0,0 +1,14 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[CreditCard]') AND type = 'U') +CREATE TABLE [Sales].[CreditCard] +( + [CreditCardID] int NOT NULL IDENTITY(1, 1), + [CardType] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [CardNumber] nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [ExpMonth] tinyint NOT NULL, + [ExpYear] smallint NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_CreditCard_CreditCardID] PRIMARY KEY CLUSTERED ([CreditCardID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[CreditCard]') AND name = 'AK_CreditCard_CardNumber') +CREATE UNIQUE NONCLUSTERED INDEX [AK_CreditCard_CardNumber] ON [Sales].[CreditCard]([CardNumber] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Currency.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Currency.sql new file mode 100644 index 0000000..1c873e7 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Currency.sql @@ -0,0 +1,11 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[Currency]') AND type = 'U') +CREATE TABLE [Sales].[Currency] +( + [CurrencyCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Name] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Currency_CurrencyCode] PRIMARY KEY CLUSTERED ([CurrencyCode] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Currency]') AND name = 'AK_Currency_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Currency_Name] ON [Sales].[Currency]([Name] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CurrencyRate.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CurrencyRate.sql new file mode 100644 index 0000000..fdbebfd --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.CurrencyRate.sql @@ -0,0 +1,31 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[CurrencyRate]') AND type = 'U') +CREATE TABLE [Sales].[CurrencyRate] +( + [CurrencyRateID] int NOT NULL IDENTITY(1, 1), + [CurrencyRateDate] datetime NOT NULL, + [FromCurrencyCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [ToCurrencyCode] nchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [AverageRate] money NOT NULL, + [EndOfDayRate] money NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_CurrencyRate_CurrencyRateID] PRIMARY KEY CLUSTERED ([CurrencyRateID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_CurrencyRate_Currency_FromCurrencyCode]') AND parent_object_id = OBJECT_ID('[Sales].[CurrencyRate]')) +BEGIN + ALTER TABLE [Sales].[CurrencyRate] WITH CHECK ADD CONSTRAINT [FK_CurrencyRate_Currency_FromCurrencyCode] FOREIGN KEY ([FromCurrencyCode]) REFERENCES [Sales].[Currency] ([CurrencyCode]) + ALTER TABLE [Sales].[CurrencyRate] CHECK CONSTRAINT [FK_CurrencyRate_Currency_FromCurrencyCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_CurrencyRate_Currency_ToCurrencyCode]') AND parent_object_id = OBJECT_ID('[Sales].[CurrencyRate]')) +BEGIN + ALTER TABLE [Sales].[CurrencyRate] WITH CHECK ADD CONSTRAINT [FK_CurrencyRate_Currency_ToCurrencyCode] FOREIGN KEY ([ToCurrencyCode]) REFERENCES [Sales].[Currency] ([CurrencyCode]) + ALTER TABLE [Sales].[CurrencyRate] CHECK CONSTRAINT [FK_CurrencyRate_Currency_ToCurrencyCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[CurrencyRate]') AND name = 'AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode') +CREATE UNIQUE NONCLUSTERED INDEX [AK_CurrencyRate_CurrencyRateDate_FromCurrencyCode_ToCurrencyCode] ON [Sales].[CurrencyRate]( + [CurrencyRateDate] ASC, + [FromCurrencyCode] ASC, + [ToCurrencyCode] ASC +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Customer.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Customer.sql new file mode 100644 index 0000000..731858e --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Customer.sql @@ -0,0 +1,39 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[Customer]') AND type = 'U') +CREATE TABLE [Sales].[Customer] +( + [CustomerID] int NOT NULL IDENTITY(1, 1), + [PersonID] int NULL, + [StoreID] int NULL, + [TerritoryID] int NULL, + [AccountNumber] AS (isnull('AW'+[dbo].[ufnLeadingZeros]([CustomerID]),'')), + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Customer_CustomerID] PRIMARY KEY CLUSTERED ([CustomerID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Customer_Person_PersonID]') AND parent_object_id = OBJECT_ID('[Sales].[Customer]')) +BEGIN + ALTER TABLE [Sales].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_Person_PersonID] FOREIGN KEY ([PersonID]) REFERENCES [Person].[Person] ([BusinessEntityID]) + ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_Person_PersonID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Customer_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[Customer]')) +BEGIN + ALTER TABLE [Sales].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Customer_Store_StoreID]') AND parent_object_id = OBJECT_ID('[Sales].[Customer]')) +BEGIN + ALTER TABLE [Sales].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_Store_StoreID] FOREIGN KEY ([StoreID]) REFERENCES [Sales].[Store] ([BusinessEntityID]) + ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_Store_StoreID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Customer]') AND name = 'AK_Customer_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Customer_rowguid] ON [Sales].[Customer]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Customer]') AND name = 'AK_Customer_AccountNumber') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Customer_AccountNumber] ON [Sales].[Customer]([AccountNumber] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Customer]') AND name = 'IX_Customer_TerritoryID') +CREATE NONCLUSTERED INDEX [IX_Customer_TerritoryID] ON [Sales].[Customer]([TerritoryID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.PersonCreditCard.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.PersonCreditCard.sql new file mode 100644 index 0000000..b248120 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.PersonCreditCard.sql @@ -0,0 +1,24 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[PersonCreditCard]') AND type = 'U') +CREATE TABLE [Sales].[PersonCreditCard] +( + [BusinessEntityID] int NOT NULL, + [CreditCardID] int NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_PersonCreditCard_BusinessEntityID_CreditCardID] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [CreditCardID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_PersonCreditCard_Person_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Sales].[PersonCreditCard]')) +BEGIN + ALTER TABLE [Sales].[PersonCreditCard] WITH CHECK ADD CONSTRAINT [FK_PersonCreditCard_Person_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[Person] ([BusinessEntityID]) + ALTER TABLE [Sales].[PersonCreditCard] CHECK CONSTRAINT [FK_PersonCreditCard_Person_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_PersonCreditCard_CreditCard_CreditCardID]') AND parent_object_id = OBJECT_ID('[Sales].[PersonCreditCard]')) +BEGIN + ALTER TABLE [Sales].[PersonCreditCard] WITH CHECK ADD CONSTRAINT [FK_PersonCreditCard_CreditCard_CreditCardID] FOREIGN KEY ([CreditCardID]) REFERENCES [Sales].[CreditCard] ([CreditCardID]) + ALTER TABLE [Sales].[PersonCreditCard] CHECK CONSTRAINT [FK_PersonCreditCard_CreditCard_CreditCardID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderDetail.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderDetail.sql new file mode 100644 index 0000000..ac65785 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderDetail.sql @@ -0,0 +1,44 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesOrderDetail]') AND type = 'U') +CREATE TABLE [Sales].[SalesOrderDetail] +( + [SalesOrderID] int NOT NULL, + [SalesOrderDetailID] int NOT NULL IDENTITY(1, 1), + [CarrierTrackingNumber] nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [OrderQty] smallint NOT NULL, + [ProductID] int NOT NULL, + [SpecialOfferID] int NOT NULL, + [UnitPrice] money NOT NULL, + [UnitPriceDiscount] money NOT NULL DEFAULT((0.0)), + [LineTotal] AS (isnull(([UnitPrice]*((1.0)-[UnitPriceDiscount]))*[OrderQty],(0.0))), + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesOrderDetail_SalesOrderID_SalesOrderDetailID] PRIMARY KEY CLUSTERED + ( + [SalesOrderID] ASC, + [SalesOrderDetailID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderDetail]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderDetail] WITH CHECK ADD CONSTRAINT [FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID] FOREIGN KEY ([SpecialOfferID]) REFERENCES [Sales].[SpecialOfferProduct] ([SpecialOfferID]) + ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderDetail]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderDetail] WITH CHECK ADD CONSTRAINT [FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID] FOREIGN KEY ([ProductID]) REFERENCES [Sales].[SpecialOfferProduct] ([ProductID]) + ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderDetail]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderDetail] WITH CHECK ADD CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID] FOREIGN KEY ([SalesOrderID]) REFERENCES [Sales].[SalesOrderHeader] ([SalesOrderID]) ON DELETE CASCADE + ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesOrderDetail]') AND name = 'AK_SalesOrderDetail_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesOrderDetail_rowguid] ON [Sales].[SalesOrderDetail]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesOrderDetail]') AND name = 'IX_SalesOrderDetail_ProductID') +CREATE NONCLUSTERED INDEX [IX_SalesOrderDetail_ProductID] ON [Sales].[SalesOrderDetail]([ProductID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeader.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeader.sql new file mode 100644 index 0000000..6307348 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeader.sql @@ -0,0 +1,91 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesOrderHeader]') AND type = 'U') +CREATE TABLE [Sales].[SalesOrderHeader] +( + [SalesOrderID] int NOT NULL IDENTITY(1, 1), + [RevisionNumber] tinyint NOT NULL DEFAULT((0)), + [OrderDate] datetime NOT NULL DEFAULT(getdate()), + [DueDate] datetime NOT NULL, + [ShipDate] datetime NULL, + [Status] tinyint NOT NULL DEFAULT((1)), + [OnlineOrderFlag] Flag NOT NULL DEFAULT((1)), + [SalesOrderNumber] AS (isnull(N'SO'+CONVERT([nvarchar](23),[SalesOrderID]),N'*** ERROR ***')), + [PurchaseOrderNumber] OrderNumber NULL, + [AccountNumber] AccountNumber NULL, + [CustomerID] int NOT NULL, + [SalesPersonID] int NULL, + [TerritoryID] int NULL, + [BillToAddressID] int NOT NULL, + [ShipToAddressID] int NOT NULL, + [ShipMethodID] int NOT NULL, + [CreditCardID] int NULL, + [CreditCardApprovalCode] varchar(15) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [CurrencyRateID] int NULL, + [SubTotal] money NOT NULL DEFAULT((0.00)), + [TaxAmt] money NOT NULL DEFAULT((0.00)), + [Freight] money NOT NULL DEFAULT((0.00)), + [TotalDue] AS (isnull(([SubTotal]+[TaxAmt])+[Freight],(0))), + [Comment] nvarchar(128) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesOrderHeader_SalesOrderID] PRIMARY KEY CLUSTERED ([SalesOrderID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_SalesPerson_SalesPersonID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] FOREIGN KEY ([SalesPersonID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_ShipMethod_ShipMethodID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY ([ShipMethodID]) REFERENCES [Purchasing].[ShipMethod] ([ShipMethodID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_Address_BillToAddressID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID] FOREIGN KEY ([BillToAddressID]) REFERENCES [Person].[Address] ([AddressID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_Address_ShipToAddressID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_Address_ShipToAddressID] FOREIGN KEY ([ShipToAddressID]) REFERENCES [Person].[Address] ([AddressID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Address_ShipToAddressID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_CreditCard_CreditCardID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_CreditCard_CreditCardID] FOREIGN KEY ([CreditCardID]) REFERENCES [Sales].[CreditCard] ([CreditCardID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_CreditCard_CreditCardID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_CurrencyRate_CurrencyRateID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_CurrencyRate_CurrencyRateID] FOREIGN KEY ([CurrencyRateID]) REFERENCES [Sales].[CurrencyRate] ([CurrencyRateID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_CurrencyRate_CurrencyRateID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_Customer_CustomerID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_Customer_CustomerID] FOREIGN KEY ([CustomerID]) REFERENCES [Sales].[Customer] ([CustomerID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Customer_CustomerID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesOrderHeader]') AND name = 'AK_SalesOrderHeader_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesOrderHeader_rowguid] ON [Sales].[SalesOrderHeader]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesOrderHeader]') AND name = 'AK_SalesOrderHeader_SalesOrderNumber') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesOrderHeader_SalesOrderNumber] ON [Sales].[SalesOrderHeader]([SalesOrderNumber] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesOrderHeader]') AND name = 'IX_SalesOrderHeader_CustomerID') +CREATE NONCLUSTERED INDEX [IX_SalesOrderHeader_CustomerID] ON [Sales].[SalesOrderHeader]([CustomerID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesOrderHeader]') AND name = 'IX_SalesOrderHeader_SalesPersonID') +CREATE NONCLUSTERED INDEX [IX_SalesOrderHeader_SalesPersonID] ON [Sales].[SalesOrderHeader]([SalesPersonID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeaderSalesReason.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeaderSalesReason.sql new file mode 100644 index 0000000..c9a1b64 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeaderSalesReason.sql @@ -0,0 +1,24 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesOrderHeaderSalesReason]') AND type = 'U') +CREATE TABLE [Sales].[SalesOrderHeaderSalesReason] +( + [SalesOrderID] int NOT NULL, + [SalesReasonID] int NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesOrderHeaderSalesReason_SalesOrderID_SalesReasonID] PRIMARY KEY CLUSTERED + ( + [SalesOrderID] ASC, + [SalesReasonID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeaderSalesReason]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeaderSalesReason] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID] FOREIGN KEY ([SalesReasonID]) REFERENCES [Sales].[SalesReason] ([SalesReasonID]) + ALTER TABLE [Sales].[SalesOrderHeaderSalesReason] CHECK CONSTRAINT [FK_SalesOrderHeaderSalesReason_SalesReason_SalesReasonID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeaderSalesReason]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeaderSalesReason] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID] FOREIGN KEY ([SalesOrderID]) REFERENCES [Sales].[SalesOrderHeader] ([SalesOrderID]) ON DELETE CASCADE + ALTER TABLE [Sales].[SalesOrderHeaderSalesReason] CHECK CONSTRAINT [FK_SalesOrderHeaderSalesReason_SalesOrderHeader_SalesOrderID] +END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPerson.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPerson.sql new file mode 100644 index 0000000..2e6b54d --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPerson.sql @@ -0,0 +1,29 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesPerson]') AND type = 'U') +CREATE TABLE [Sales].[SalesPerson] +( + [BusinessEntityID] int NOT NULL, + [TerritoryID] int NULL, + [SalesQuota] money NULL, + [Bonus] money NOT NULL DEFAULT((0.00)), + [CommissionPct] smallmoney NOT NULL DEFAULT((0.00)), + [SalesYTD] money NOT NULL DEFAULT((0.00)), + [SalesLastYear] money NOT NULL DEFAULT((0.00)), + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesPerson_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesPerson_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesPerson]')) +BEGIN + ALTER TABLE [Sales].[SalesPerson] WITH CHECK ADD CONSTRAINT [FK_SalesPerson_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Sales].[SalesPerson] CHECK CONSTRAINT [FK_SalesPerson_SalesTerritory_TerritoryID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesPerson_Employee_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesPerson]')) +BEGIN + ALTER TABLE [Sales].[SalesPerson] WITH CHECK ADD CONSTRAINT [FK_SalesPerson_Employee_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) + ALTER TABLE [Sales].[SalesPerson] CHECK CONSTRAINT [FK_SalesPerson_Employee_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesPerson]') AND name = 'AK_SalesPerson_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesPerson_rowguid] ON [Sales].[SalesPerson]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPersonQuotaHistory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPersonQuotaHistory.sql new file mode 100644 index 0000000..f53acf8 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPersonQuotaHistory.sql @@ -0,0 +1,23 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesPersonQuotaHistory]') AND type = 'U') +CREATE TABLE [Sales].[SalesPersonQuotaHistory] +( + [BusinessEntityID] int NOT NULL, + [QuotaDate] datetime NOT NULL, + [SalesQuota] money NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesPersonQuotaHistory_BusinessEntityID_QuotaDate] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [QuotaDate] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesPersonQuotaHistory_SalesPerson_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesPersonQuotaHistory]')) +BEGIN + ALTER TABLE [Sales].[SalesPersonQuotaHistory] WITH CHECK ADD CONSTRAINT [FK_SalesPersonQuotaHistory_SalesPerson_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID]) + ALTER TABLE [Sales].[SalesPersonQuotaHistory] CHECK CONSTRAINT [FK_SalesPersonQuotaHistory_SalesPerson_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesPersonQuotaHistory]') AND name = 'AK_SalesPersonQuotaHistory_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesPersonQuotaHistory_rowguid] ON [Sales].[SalesPersonQuotaHistory]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesReason.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesReason.sql new file mode 100644 index 0000000..9d87f27 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesReason.sql @@ -0,0 +1,9 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesReason]') AND type = 'U') +CREATE TABLE [Sales].[SalesReason] +( + [SalesReasonID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [ReasonType] Name NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesReason_SalesReasonID] PRIMARY KEY CLUSTERED ([SalesReasonID] ASC) +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTaxRate.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTaxRate.sql new file mode 100644 index 0000000..f20d78e --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTaxRate.sql @@ -0,0 +1,27 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesTaxRate]') AND type = 'U') +CREATE TABLE [Sales].[SalesTaxRate] +( + [SalesTaxRateID] int NOT NULL IDENTITY(1, 1), + [StateProvinceID] int NOT NULL, + [TaxType] tinyint NOT NULL, + [TaxRate] smallmoney NOT NULL DEFAULT((0.00)), + [Name] Name NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesTaxRate_SalesTaxRateID] PRIMARY KEY CLUSTERED ([SalesTaxRateID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesTaxRate_StateProvince_StateProvinceID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesTaxRate]')) +BEGIN + ALTER TABLE [Sales].[SalesTaxRate] WITH CHECK ADD CONSTRAINT [FK_SalesTaxRate_StateProvince_StateProvinceID] FOREIGN KEY ([StateProvinceID]) REFERENCES [Person].[StateProvince] ([StateProvinceID]) + ALTER TABLE [Sales].[SalesTaxRate] CHECK CONSTRAINT [FK_SalesTaxRate_StateProvince_StateProvinceID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesTaxRate]') AND name = 'AK_SalesTaxRate_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesTaxRate_rowguid] ON [Sales].[SalesTaxRate]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesTaxRate]') AND name = 'AK_SalesTaxRate_StateProvinceID_TaxType') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesTaxRate_StateProvinceID_TaxType] ON [Sales].[SalesTaxRate]( + [StateProvinceID] ASC, + [TaxType] ASC +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTerritory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTerritory.sql new file mode 100644 index 0000000..27d4cfe --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTerritory.sql @@ -0,0 +1,27 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesTerritory]') AND type = 'U') +CREATE TABLE [Sales].[SalesTerritory] +( + [TerritoryID] int NOT NULL IDENTITY(1, 1), + [Name] Name NOT NULL, + [CountryRegionCode] nvarchar(3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Group] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [SalesYTD] money NOT NULL DEFAULT((0.00)), + [SalesLastYear] money NOT NULL DEFAULT((0.00)), + [CostYTD] money NOT NULL DEFAULT((0.00)), + [CostLastYear] money NOT NULL DEFAULT((0.00)), + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesTerritory_TerritoryID] PRIMARY KEY CLUSTERED ([TerritoryID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesTerritory_CountryRegion_CountryRegionCode]') AND parent_object_id = OBJECT_ID('[Sales].[SalesTerritory]')) +BEGIN + ALTER TABLE [Sales].[SalesTerritory] WITH CHECK ADD CONSTRAINT [FK_SalesTerritory_CountryRegion_CountryRegionCode] FOREIGN KEY ([CountryRegionCode]) REFERENCES [Person].[CountryRegion] ([CountryRegionCode]) + ALTER TABLE [Sales].[SalesTerritory] CHECK CONSTRAINT [FK_SalesTerritory_CountryRegion_CountryRegionCode] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesTerritory]') AND name = 'AK_SalesTerritory_Name') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesTerritory_Name] ON [Sales].[SalesTerritory]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesTerritory]') AND name = 'AK_SalesTerritory_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesTerritory_rowguid] ON [Sales].[SalesTerritory]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTerritoryHistory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTerritoryHistory.sql new file mode 100644 index 0000000..9a54d7d --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesTerritoryHistory.sql @@ -0,0 +1,31 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SalesTerritoryHistory]') AND type = 'U') +CREATE TABLE [Sales].[SalesTerritoryHistory] +( + [BusinessEntityID] int NOT NULL, + [TerritoryID] int NOT NULL, + [StartDate] datetime NOT NULL, + [EndDate] datetime NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SalesTerritoryHistory_BusinessEntityID_StartDate_TerritoryID] PRIMARY KEY CLUSTERED + ( + [BusinessEntityID] ASC, + [StartDate] ASC, + [TerritoryID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesTerritoryHistory]')) +BEGIN + ALTER TABLE [Sales].[SalesTerritoryHistory] WITH CHECK ADD CONSTRAINT [FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID]) + ALTER TABLE [Sales].[SalesTerritoryHistory] CHECK CONSTRAINT [FK_SalesTerritoryHistory_SalesPerson_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesTerritoryHistory_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesTerritoryHistory]')) +BEGIN + ALTER TABLE [Sales].[SalesTerritoryHistory] WITH CHECK ADD CONSTRAINT [FK_SalesTerritoryHistory_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Sales].[SalesTerritoryHistory] CHECK CONSTRAINT [FK_SalesTerritoryHistory_SalesTerritory_TerritoryID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesTerritoryHistory]') AND name = 'AK_SalesTerritoryHistory_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesTerritoryHistory_rowguid] ON [Sales].[SalesTerritoryHistory]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.ShoppingCartItem.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.ShoppingCartItem.sql new file mode 100644 index 0000000..c2feba7 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.ShoppingCartItem.sql @@ -0,0 +1,23 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[ShoppingCartItem]') AND type = 'U') +CREATE TABLE [Sales].[ShoppingCartItem] +( + [ShoppingCartItemID] int NOT NULL IDENTITY(1, 1), + [ShoppingCartID] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Quantity] int NOT NULL DEFAULT((1)), + [ProductID] int NOT NULL, + [DateCreated] datetime NOT NULL DEFAULT(getdate()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_ShoppingCartItem_ShoppingCartItemID] PRIMARY KEY CLUSTERED ([ShoppingCartItemID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_ShoppingCartItem_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Sales].[ShoppingCartItem]')) +BEGIN + ALTER TABLE [Sales].[ShoppingCartItem] WITH CHECK ADD CONSTRAINT [FK_ShoppingCartItem_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Sales].[ShoppingCartItem] CHECK CONSTRAINT [FK_ShoppingCartItem_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[ShoppingCartItem]') AND name = 'IX_ShoppingCartItem_ShoppingCartID_ProductID') +CREATE NONCLUSTERED INDEX [IX_ShoppingCartItem_ShoppingCartID_ProductID] ON [Sales].[ShoppingCartItem]( + [ShoppingCartID] ASC, + [ProductID] ASC +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SpecialOffer.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SpecialOffer.sql new file mode 100644 index 0000000..874b7f7 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SpecialOffer.sql @@ -0,0 +1,19 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SpecialOffer]') AND type = 'U') +CREATE TABLE [Sales].[SpecialOffer] +( + [SpecialOfferID] int NOT NULL IDENTITY(1, 1), + [Description] nvarchar(255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [DiscountPct] smallmoney NOT NULL DEFAULT((0.00)), + [Type] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Category] nvarchar(50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [StartDate] datetime NOT NULL, + [EndDate] datetime NOT NULL, + [MinQty] int NOT NULL DEFAULT((0)), + [MaxQty] int NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SpecialOffer_SpecialOfferID] PRIMARY KEY CLUSTERED ([SpecialOfferID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SpecialOffer]') AND name = 'AK_SpecialOffer_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SpecialOffer_rowguid] ON [Sales].[SpecialOffer]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SpecialOfferProduct.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SpecialOfferProduct.sql new file mode 100644 index 0000000..665f67b --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SpecialOfferProduct.sql @@ -0,0 +1,31 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[SpecialOfferProduct]') AND type = 'U') +CREATE TABLE [Sales].[SpecialOfferProduct] +( + [SpecialOfferID] int NOT NULL, + [ProductID] int NOT NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_SpecialOfferProduct_SpecialOfferID_ProductID] PRIMARY KEY CLUSTERED + ( + [SpecialOfferID] ASC, + [ProductID] ASC + ) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SpecialOfferProduct_Product_ProductID]') AND parent_object_id = OBJECT_ID('[Sales].[SpecialOfferProduct]')) +BEGIN + ALTER TABLE [Sales].[SpecialOfferProduct] WITH CHECK ADD CONSTRAINT [FK_SpecialOfferProduct_Product_ProductID] FOREIGN KEY ([ProductID]) REFERENCES [Production].[Product] ([ProductID]) + ALTER TABLE [Sales].[SpecialOfferProduct] CHECK CONSTRAINT [FK_SpecialOfferProduct_Product_ProductID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SpecialOfferProduct_SpecialOffer_SpecialOfferID]') AND parent_object_id = OBJECT_ID('[Sales].[SpecialOfferProduct]')) +BEGIN + ALTER TABLE [Sales].[SpecialOfferProduct] WITH CHECK ADD CONSTRAINT [FK_SpecialOfferProduct_SpecialOffer_SpecialOfferID] FOREIGN KEY ([SpecialOfferID]) REFERENCES [Sales].[SpecialOffer] ([SpecialOfferID]) + ALTER TABLE [Sales].[SpecialOfferProduct] CHECK CONSTRAINT [FK_SpecialOfferProduct_SpecialOffer_SpecialOfferID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SpecialOfferProduct]') AND name = 'AK_SpecialOfferProduct_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_SpecialOfferProduct_rowguid] ON [Sales].[SpecialOfferProduct]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SpecialOfferProduct]') AND name = 'IX_SpecialOfferProduct_ProductID') +CREATE NONCLUSTERED INDEX [IX_SpecialOfferProduct_ProductID] ON [Sales].[SpecialOfferProduct]([ProductID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Store.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Store.sql new file mode 100644 index 0000000..0f71487 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Store.sql @@ -0,0 +1,29 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[Store]') AND type = 'U') +CREATE TABLE [Sales].[Store] +( + [BusinessEntityID] int NOT NULL, + [Name] Name NOT NULL, + [SalesPersonID] int NULL, + [Demographics] xml NULL, + [rowguid] uniqueidentifier NOT NULL DEFAULT(newid()), + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_Store_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) +) + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Store_SalesPerson_SalesPersonID]') AND parent_object_id = OBJECT_ID('[Sales].[Store]')) +BEGIN + ALTER TABLE [Sales].[Store] WITH CHECK ADD CONSTRAINT [FK_Store_SalesPerson_SalesPersonID] FOREIGN KEY ([SalesPersonID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID]) + ALTER TABLE [Sales].[Store] CHECK CONSTRAINT [FK_Store_SalesPerson_SalesPersonID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Store_BusinessEntity_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Sales].[Store]')) +BEGIN + ALTER TABLE [Sales].[Store] WITH CHECK ADD CONSTRAINT [FK_Store_BusinessEntity_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[BusinessEntity] ([BusinessEntityID]) + ALTER TABLE [Sales].[Store] CHECK CONSTRAINT [FK_Store_BusinessEntity_BusinessEntityID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Store]') AND name = 'AK_Store_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Store_rowguid] ON [Sales].[Store]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Store]') AND name = 'IX_Store_SalesPersonID') +CREATE NONCLUSTERED INDEX [IX_Store_SalesPersonID] ON [Sales].[Store]([SalesPersonID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/dbo.AWBuildVersion.sql b/snapshots/AdventureWorks2017/_sql-database/tables/dbo.AWBuildVersion.sql new file mode 100644 index 0000000..8034009 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/dbo.AWBuildVersion.sql @@ -0,0 +1,9 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[AWBuildVersion]') AND type = 'U') +CREATE TABLE [dbo].[AWBuildVersion] +( + [SystemInformationID] tinyint NOT NULL IDENTITY(1, 1), + [Database Version] nvarchar(25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [VersionDate] datetime NOT NULL, + [ModifiedDate] datetime NOT NULL DEFAULT(getdate()), + CONSTRAINT [PK_AWBuildVersion_SystemInformationID] PRIMARY KEY CLUSTERED ([SystemInformationID] ASC) +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/dbo.DatabaseLog.sql b/snapshots/AdventureWorks2017/_sql-database/tables/dbo.DatabaseLog.sql new file mode 100644 index 0000000..3a008f1 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/dbo.DatabaseLog.sql @@ -0,0 +1,13 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[DatabaseLog]') AND type = 'U') +CREATE TABLE [dbo].[DatabaseLog] +( + [DatabaseLogID] int NOT NULL IDENTITY(1, 1), + [PostTime] datetime NOT NULL, + [DatabaseUser] sysname COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Event] sysname COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [Schema] sysname COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [Object] sysname COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [TSQL] nvarchar(max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [XmlEvent] xml NOT NULL, + CONSTRAINT [PK_DatabaseLog_DatabaseLogID] PRIMARY KEY NONCLUSTERED ([DatabaseLogID] ASC) +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/dbo.ErrorLog.sql b/snapshots/AdventureWorks2017/_sql-database/tables/dbo.ErrorLog.sql new file mode 100644 index 0000000..0226888 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/tables/dbo.ErrorLog.sql @@ -0,0 +1,14 @@ +IF NOT EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[dbo].[ErrorLog]') AND type = 'U') +CREATE TABLE [dbo].[ErrorLog] +( + [ErrorLogID] int NOT NULL IDENTITY(1, 1), + [ErrorTime] datetime NOT NULL DEFAULT(getdate()), + [UserName] sysname COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + [ErrorNumber] int NOT NULL, + [ErrorSeverity] int NULL, + [ErrorState] int NULL, + [ErrorProcedure] nvarchar(126) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, + [ErrorLine] int NULL, + [ErrorMessage] nvarchar(4000) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, + CONSTRAINT [PK_ErrorLog_ErrorLogID] PRIMARY KEY CLUSTERED ([ErrorLogID] ASC) +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/HumanResources.dEmployee.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/HumanResources.dEmployee.sql new file mode 100644 index 0000000..b85b40b --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/HumanResources.dEmployee.sql @@ -0,0 +1,28 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[dEmployee]') AND type = 'TR') +DROP TRIGGER [HumanResources].[dEmployee] +GO + +CREATE TRIGGER [HumanResources].[dEmployee] ON [HumanResources].[Employee] +INSTEAD OF DELETE NOT FOR REPLICATION AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN + RAISERROR + (N'Employees cannot be deleted. They can only be marked as not current.', -- Message + 10, -- Severity. + 1); -- State. + + -- Rollback any active or uncommittable transactions + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + END; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Person.iuPerson.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Person.iuPerson.sql new file mode 100644 index 0000000..a35dd80 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Person.iuPerson.sql @@ -0,0 +1,38 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[iuPerson]') AND type = 'TR') +DROP TRIGGER [Person].[iuPerson] +GO + +CREATE TRIGGER [Person].[iuPerson] ON [Person].[Person] +AFTER INSERT, UPDATE NOT FOR REPLICATION AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + IF UPDATE([BusinessEntityID]) OR UPDATE([Demographics]) + BEGIN + UPDATE [Person].[Person] + SET [Person].[Person].[Demographics] = N' + 0.00 + ' + FROM inserted + WHERE [Person].[Person].[BusinessEntityID] = inserted.[BusinessEntityID] + AND inserted.[Demographics] IS NULL; + + UPDATE [Person].[Person] + SET [Demographics].modify(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + insert 0.00 + as first + into (/IndividualSurvey)[1]') + FROM inserted + WHERE [Person].[Person].[BusinessEntityID] = inserted.[BusinessEntityID] + AND inserted.[Demographics] IS NOT NULL + AND inserted.[Demographics].exist(N'declare default element namespace + "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + /IndividualSurvey/TotalPurchaseYTD') <> 1; + END; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Production.iWorkOrder.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Production.iWorkOrder.sql new file mode 100644 index 0000000..a569fb6 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Production.iWorkOrder.sql @@ -0,0 +1,45 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[iWorkOrder]') AND type = 'TR') +DROP TRIGGER [Production].[iWorkOrder] +GO + +CREATE TRIGGER [Production].[iWorkOrder] ON [Production].[WorkOrder] +AFTER INSERT AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN TRY + INSERT INTO [Production].[TransactionHistory]( + [ProductID] + ,[ReferenceOrderID] + ,[TransactionType] + ,[TransactionDate] + ,[Quantity] + ,[ActualCost]) + SELECT + inserted.[ProductID] + ,inserted.[WorkOrderID] + ,'W' + ,GETDATE() + ,inserted.[OrderQty] + ,0 + FROM inserted; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspPrintError]; + + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Production.uWorkOrder.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Production.uWorkOrder.sql new file mode 100644 index 0000000..345b9b0 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Production.uWorkOrder.sql @@ -0,0 +1,46 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[uWorkOrder]') AND type = 'TR') +DROP TRIGGER [Production].[uWorkOrder] +GO + +CREATE TRIGGER [Production].[uWorkOrder] ON [Production].[WorkOrder] +AFTER UPDATE AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN TRY + IF UPDATE([ProductID]) OR UPDATE([OrderQty]) + BEGIN + INSERT INTO [Production].[TransactionHistory]( + [ProductID] + ,[ReferenceOrderID] + ,[TransactionType] + ,[TransactionDate] + ,[Quantity]) + SELECT + inserted.[ProductID] + ,inserted.[WorkOrderID] + ,'W' + ,GETDATE() + ,inserted.[OrderQty] + FROM inserted; + END; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspPrintError]; + + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.dVendor.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.dVendor.sql new file mode 100644 index 0000000..2a04b27 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.dVendor.sql @@ -0,0 +1,46 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[dVendor]') AND type = 'TR') +DROP TRIGGER [Purchasing].[dVendor] +GO + +CREATE TRIGGER [Purchasing].[dVendor] ON [Purchasing].[Vendor] +INSTEAD OF DELETE NOT FOR REPLICATION AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN TRY + DECLARE @DeleteCount int; + + SELECT @DeleteCount = COUNT(*) FROM deleted; + IF @DeleteCount > 0 + BEGIN + RAISERROR + (N'Vendors cannot be deleted. They can only be marked as not active.', -- Message + 10, -- Severity. + 1); -- State. + + -- Rollback any active or uncommittable transactions + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + END; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspPrintError]; + + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.iPurchaseOrderDetail.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.iPurchaseOrderDetail.sql new file mode 100644 index 0000000..29aff28 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.iPurchaseOrderDetail.sql @@ -0,0 +1,58 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[iPurchaseOrderDetail]') AND type = 'TR') +DROP TRIGGER [Purchasing].[iPurchaseOrderDetail] +GO + +CREATE TRIGGER [Purchasing].[iPurchaseOrderDetail] ON [Purchasing].[PurchaseOrderDetail] +AFTER INSERT AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN TRY + INSERT INTO [Production].[TransactionHistory] + ([ProductID] + ,[ReferenceOrderID] + ,[ReferenceOrderLineID] + ,[TransactionType] + ,[TransactionDate] + ,[Quantity] + ,[ActualCost]) + SELECT + inserted.[ProductID] + ,inserted.[PurchaseOrderID] + ,inserted.[PurchaseOrderDetailID] + ,'P' + ,GETDATE() + ,inserted.[OrderQty] + ,inserted.[UnitPrice] + FROM inserted + INNER JOIN [Purchasing].[PurchaseOrderHeader] + ON inserted.[PurchaseOrderID] = [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID]; + + -- Update SubTotal in PurchaseOrderHeader record. Note that this causes the + -- PurchaseOrderHeader trigger to fire which will update the RevisionNumber. + UPDATE [Purchasing].[PurchaseOrderHeader] + SET [Purchasing].[PurchaseOrderHeader].[SubTotal] = + (SELECT SUM([Purchasing].[PurchaseOrderDetail].[LineTotal]) + FROM [Purchasing].[PurchaseOrderDetail] + WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderID]) + WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] IN (SELECT inserted.[PurchaseOrderID] FROM inserted); + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspPrintError]; + + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.uPurchaseOrderDetail.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.uPurchaseOrderDetail.sql new file mode 100644 index 0000000..3b08883 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.uPurchaseOrderDetail.sql @@ -0,0 +1,70 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[uPurchaseOrderDetail]') AND type = 'TR') +DROP TRIGGER [Purchasing].[uPurchaseOrderDetail] +GO + +CREATE TRIGGER [Purchasing].[uPurchaseOrderDetail] ON [Purchasing].[PurchaseOrderDetail] +AFTER UPDATE AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN TRY + IF UPDATE([ProductID]) OR UPDATE([OrderQty]) OR UPDATE([UnitPrice]) + -- Insert record into TransactionHistory + BEGIN + INSERT INTO [Production].[TransactionHistory] + ([ProductID] + ,[ReferenceOrderID] + ,[ReferenceOrderLineID] + ,[TransactionType] + ,[TransactionDate] + ,[Quantity] + ,[ActualCost]) + SELECT + inserted.[ProductID] + ,inserted.[PurchaseOrderID] + ,inserted.[PurchaseOrderDetailID] + ,'P' + ,GETDATE() + ,inserted.[OrderQty] + ,inserted.[UnitPrice] + FROM inserted + INNER JOIN [Purchasing].[PurchaseOrderDetail] + ON inserted.[PurchaseOrderID] = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderID]; + + -- Update SubTotal in PurchaseOrderHeader record. Note that this causes the + -- PurchaseOrderHeader trigger to fire which will update the RevisionNumber. + UPDATE [Purchasing].[PurchaseOrderHeader] + SET [Purchasing].[PurchaseOrderHeader].[SubTotal] = + (SELECT SUM([Purchasing].[PurchaseOrderDetail].[LineTotal]) + FROM [Purchasing].[PurchaseOrderDetail] + WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] + = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderID]) + WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] + IN (SELECT inserted.[PurchaseOrderID] FROM inserted); + + UPDATE [Purchasing].[PurchaseOrderDetail] + SET [Purchasing].[PurchaseOrderDetail].[ModifiedDate] = GETDATE() + FROM inserted + WHERE inserted.[PurchaseOrderID] = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderID] + AND inserted.[PurchaseOrderDetailID] = [Purchasing].[PurchaseOrderDetail].[PurchaseOrderDetailID]; + END; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspPrintError]; + + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.uPurchaseOrderHeader.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.uPurchaseOrderHeader.sql new file mode 100644 index 0000000..0198476 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Purchasing.uPurchaseOrderHeader.sql @@ -0,0 +1,39 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[uPurchaseOrderHeader]') AND type = 'TR') +DROP TRIGGER [Purchasing].[uPurchaseOrderHeader] +GO + +CREATE TRIGGER [Purchasing].[uPurchaseOrderHeader] ON [Purchasing].[PurchaseOrderHeader] +AFTER UPDATE AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN TRY + -- Update RevisionNumber for modification of any field EXCEPT the Status. + IF NOT UPDATE([Status]) + BEGIN + UPDATE [Purchasing].[PurchaseOrderHeader] + SET [Purchasing].[PurchaseOrderHeader].[RevisionNumber] = + [Purchasing].[PurchaseOrderHeader].[RevisionNumber] + 1 + WHERE [Purchasing].[PurchaseOrderHeader].[PurchaseOrderID] IN + (SELECT inserted.[PurchaseOrderID] FROM inserted); + END; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspPrintError]; + + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Sales.iduSalesOrderDetail.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Sales.iduSalesOrderDetail.sql new file mode 100644 index 0000000..959c20d --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Sales.iduSalesOrderDetail.sql @@ -0,0 +1,87 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[iduSalesOrderDetail]') AND type = 'TR') +DROP TRIGGER [Sales].[iduSalesOrderDetail] +GO + +CREATE TRIGGER [Sales].[iduSalesOrderDetail] ON [Sales].[SalesOrderDetail] +AFTER INSERT, DELETE, UPDATE AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN TRY + -- If inserting or updating these columns + IF UPDATE([ProductID]) OR UPDATE([OrderQty]) OR UPDATE([UnitPrice]) OR UPDATE([UnitPriceDiscount]) + -- Insert record into TransactionHistory + BEGIN + INSERT INTO [Production].[TransactionHistory] + ([ProductID] + ,[ReferenceOrderID] + ,[ReferenceOrderLineID] + ,[TransactionType] + ,[TransactionDate] + ,[Quantity] + ,[ActualCost]) + SELECT + inserted.[ProductID] + ,inserted.[SalesOrderID] + ,inserted.[SalesOrderDetailID] + ,'S' + ,GETDATE() + ,inserted.[OrderQty] + ,inserted.[UnitPrice] + FROM inserted + INNER JOIN [Sales].[SalesOrderHeader] + ON inserted.[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID]; + + UPDATE [Person].[Person] + SET [Demographics].modify('declare default element namespace + "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + replace value of (/IndividualSurvey/TotalPurchaseYTD)[1] + with data(/IndividualSurvey/TotalPurchaseYTD)[1] + sql:column ("inserted.LineTotal")') + FROM inserted + INNER JOIN [Sales].[SalesOrderHeader] AS SOH + ON inserted.[SalesOrderID] = SOH.[SalesOrderID] + INNER JOIN [Sales].[Customer] AS C + ON SOH.[CustomerID] = C.[CustomerID] + WHERE C.[PersonID] = [Person].[Person].[BusinessEntityID]; + END; + + -- Update SubTotal in SalesOrderHeader record. Note that this causes the + -- SalesOrderHeader trigger to fire which will update the RevisionNumber. + UPDATE [Sales].[SalesOrderHeader] + SET [Sales].[SalesOrderHeader].[SubTotal] = + (SELECT SUM([Sales].[SalesOrderDetail].[LineTotal]) + FROM [Sales].[SalesOrderDetail] + WHERE [Sales].[SalesOrderHeader].[SalesOrderID] = [Sales].[SalesOrderDetail].[SalesOrderID]) + WHERE [Sales].[SalesOrderHeader].[SalesOrderID] IN (SELECT inserted.[SalesOrderID] FROM inserted); + + UPDATE [Person].[Person] + SET [Demographics].modify('declare default element namespace + "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + replace value of (/IndividualSurvey/TotalPurchaseYTD)[1] + with data(/IndividualSurvey/TotalPurchaseYTD)[1] - sql:column("deleted.LineTotal")') + FROM deleted + INNER JOIN [Sales].[SalesOrderHeader] + ON deleted.[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID] + INNER JOIN [Sales].[Customer] + ON [Sales].[Customer].[CustomerID] = [Sales].[SalesOrderHeader].[CustomerID] + WHERE [Sales].[Customer].[PersonID] = [Person].[Person].[BusinessEntityID]; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspPrintError]; + + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/triggers/Sales.uSalesOrderHeader.sql b/snapshots/AdventureWorks2017/_sql-database/triggers/Sales.uSalesOrderHeader.sql new file mode 100644 index 0000000..4402d6a --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/triggers/Sales.uSalesOrderHeader.sql @@ -0,0 +1,72 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[uSalesOrderHeader]') AND type = 'TR') +DROP TRIGGER [Sales].[uSalesOrderHeader] +GO + +CREATE TRIGGER [Sales].[uSalesOrderHeader] ON [Sales].[SalesOrderHeader] +AFTER UPDATE NOT FOR REPLICATION AS +BEGIN + DECLARE @Count int; + + SET @Count = @@ROWCOUNT; + IF @Count = 0 + RETURN; + + SET NOCOUNT ON; + + BEGIN TRY + -- Update RevisionNumber for modification of any field EXCEPT the Status. + IF NOT UPDATE([Status]) + BEGIN + UPDATE [Sales].[SalesOrderHeader] + SET [Sales].[SalesOrderHeader].[RevisionNumber] = + [Sales].[SalesOrderHeader].[RevisionNumber] + 1 + WHERE [Sales].[SalesOrderHeader].[SalesOrderID] IN + (SELECT inserted.[SalesOrderID] FROM inserted); + END; + + -- Update the SalesPerson SalesYTD when SubTotal is updated + IF UPDATE([SubTotal]) + BEGIN + DECLARE @StartDate datetime, + @EndDate datetime + + SET @StartDate = [dbo].[ufnGetAccountingStartDate](); + SET @EndDate = [dbo].[ufnGetAccountingEndDate](); + + UPDATE [Sales].[SalesPerson] + SET [Sales].[SalesPerson].[SalesYTD] = + (SELECT SUM([Sales].[SalesOrderHeader].[SubTotal]) + FROM [Sales].[SalesOrderHeader] + WHERE [Sales].[SalesPerson].[BusinessEntityID] = [Sales].[SalesOrderHeader].[SalesPersonID] + AND ([Sales].[SalesOrderHeader].[Status] = 5) -- Shipped + AND [Sales].[SalesOrderHeader].[OrderDate] BETWEEN @StartDate AND @EndDate) + WHERE [Sales].[SalesPerson].[BusinessEntityID] + IN (SELECT DISTINCT inserted.[SalesPersonID] FROM inserted + WHERE inserted.[OrderDate] BETWEEN @StartDate AND @EndDate); + + -- Update the SalesTerritory SalesYTD when SubTotal is updated + UPDATE [Sales].[SalesTerritory] + SET [Sales].[SalesTerritory].[SalesYTD] = + (SELECT SUM([Sales].[SalesOrderHeader].[SubTotal]) + FROM [Sales].[SalesOrderHeader] + WHERE [Sales].[SalesTerritory].[TerritoryID] = [Sales].[SalesOrderHeader].[TerritoryID] + AND ([Sales].[SalesOrderHeader].[Status] = 5) -- Shipped + AND [Sales].[SalesOrderHeader].[OrderDate] BETWEEN @StartDate AND @EndDate) + WHERE [Sales].[SalesTerritory].[TerritoryID] + IN (SELECT DISTINCT inserted.[TerritoryID] FROM inserted + WHERE inserted.[OrderDate] BETWEEN @StartDate AND @EndDate); + END; + END TRY + BEGIN CATCH + EXECUTE [dbo].[uspPrintError]; + + -- Rollback any active or uncommittable transactions before + -- inserting information in the ErrorLog + IF @@TRANCOUNT > 0 + BEGIN + ROLLBACK TRANSACTION; + END + + EXECUTE [dbo].[uspLogError]; + END CATCH; +END; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/types/dbo.AccountNumber.sql b/snapshots/AdventureWorks2017/_sql-database/types/dbo.AccountNumber.sql new file mode 100644 index 0000000..0422668 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/types/dbo.AccountNumber.sql @@ -0,0 +1,7 @@ +IF NOT EXISTS ( + SELECT 1 FROM sys.types AS t + JOIN sys.schemas s ON t.schema_id = s.schema_id + WHERE t.name = 'AccountNumber' AND s.name = 'dbo' +) +CREATE TYPE [dbo].[AccountNumber] +FROM NVARCHAR(30) NULL \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/types/dbo.Flag.sql b/snapshots/AdventureWorks2017/_sql-database/types/dbo.Flag.sql new file mode 100644 index 0000000..e6e4389 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/types/dbo.Flag.sql @@ -0,0 +1,7 @@ +IF NOT EXISTS ( + SELECT 1 FROM sys.types AS t + JOIN sys.schemas s ON t.schema_id = s.schema_id + WHERE t.name = 'Flag' AND s.name = 'dbo' +) +CREATE TYPE [dbo].[Flag] +FROM BIT NOT NULL \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/types/dbo.Name.sql b/snapshots/AdventureWorks2017/_sql-database/types/dbo.Name.sql new file mode 100644 index 0000000..202e246 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/types/dbo.Name.sql @@ -0,0 +1,7 @@ +IF NOT EXISTS ( + SELECT 1 FROM sys.types AS t + JOIN sys.schemas s ON t.schema_id = s.schema_id + WHERE t.name = 'Name' AND s.name = 'dbo' +) +CREATE TYPE [dbo].[Name] +FROM NVARCHAR(100) NULL \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/types/dbo.NameStyle.sql b/snapshots/AdventureWorks2017/_sql-database/types/dbo.NameStyle.sql new file mode 100644 index 0000000..2f6235a --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/types/dbo.NameStyle.sql @@ -0,0 +1,7 @@ +IF NOT EXISTS ( + SELECT 1 FROM sys.types AS t + JOIN sys.schemas s ON t.schema_id = s.schema_id + WHERE t.name = 'NameStyle' AND s.name = 'dbo' +) +CREATE TYPE [dbo].[NameStyle] +FROM BIT NOT NULL \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/types/dbo.OrderNumber.sql b/snapshots/AdventureWorks2017/_sql-database/types/dbo.OrderNumber.sql new file mode 100644 index 0000000..ce87954 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/types/dbo.OrderNumber.sql @@ -0,0 +1,7 @@ +IF NOT EXISTS ( + SELECT 1 FROM sys.types AS t + JOIN sys.schemas s ON t.schema_id = s.schema_id + WHERE t.name = 'OrderNumber' AND s.name = 'dbo' +) +CREATE TYPE [dbo].[OrderNumber] +FROM NVARCHAR(50) NULL \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/types/dbo.Phone.sql b/snapshots/AdventureWorks2017/_sql-database/types/dbo.Phone.sql new file mode 100644 index 0000000..8b7977b --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/types/dbo.Phone.sql @@ -0,0 +1,7 @@ +IF NOT EXISTS ( + SELECT 1 FROM sys.types AS t + JOIN sys.schemas s ON t.schema_id = s.schema_id + WHERE t.name = 'Phone' AND s.name = 'dbo' +) +CREATE TYPE [dbo].[Phone] +FROM NVARCHAR(50) NULL \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployee.sql b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployee.sql new file mode 100644 index 0000000..a37b98d --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployee.sql @@ -0,0 +1,42 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[vEmployee]') AND type = 'V') +DROP VIEW [HumanResources].[vEmployee] +GO + +CREATE VIEW [HumanResources].[vEmployee] +AS +SELECT + e.[BusinessEntityID] + ,p.[Title] + ,p.[FirstName] + ,p.[MiddleName] + ,p.[LastName] + ,p.[Suffix] + ,e.[JobTitle] + ,pp.[PhoneNumber] + ,pnt.[Name] AS [PhoneNumberType] + ,ea.[EmailAddress] + ,p.[EmailPromotion] + ,a.[AddressLine1] + ,a.[AddressLine2] + ,a.[City] + ,sp.[Name] AS [StateProvinceName] + ,a.[PostalCode] + ,cr.[Name] AS [CountryRegionName] + ,p.[AdditionalContactInfo] +FROM [HumanResources].[Employee] e + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + INNER JOIN [Person].[BusinessEntityAddress] bea + ON bea.[BusinessEntityID] = e.[BusinessEntityID] + INNER JOIN [Person].[Address] a + ON a.[AddressID] = bea.[AddressID] + INNER JOIN [Person].[StateProvince] sp + ON sp.[StateProvinceID] = a.[StateProvinceID] + INNER JOIN [Person].[CountryRegion] cr + ON cr.[CountryRegionCode] = sp.[CountryRegionCode] + LEFT OUTER JOIN [Person].[PersonPhone] pp + ON pp.BusinessEntityID = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PhoneNumberType] pnt + ON pp.[PhoneNumberTypeID] = pnt.[PhoneNumberTypeID] + LEFT OUTER JOIN [Person].[EmailAddress] ea + ON p.[BusinessEntityID] = ea.[BusinessEntityID]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployeeDepartment.sql b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployeeDepartment.sql new file mode 100644 index 0000000..64fd0e6 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployeeDepartment.sql @@ -0,0 +1,25 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[vEmployeeDepartment]') AND type = 'V') +DROP VIEW [HumanResources].[vEmployeeDepartment] +GO + +CREATE VIEW [HumanResources].[vEmployeeDepartment] +AS +SELECT + e.[BusinessEntityID] + ,p.[Title] + ,p.[FirstName] + ,p.[MiddleName] + ,p.[LastName] + ,p.[Suffix] + ,e.[JobTitle] + ,d.[Name] AS [Department] + ,d.[GroupName] + ,edh.[StartDate] +FROM [HumanResources].[Employee] e + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + INNER JOIN [HumanResources].[EmployeeDepartmentHistory] edh + ON e.[BusinessEntityID] = edh.[BusinessEntityID] + INNER JOIN [HumanResources].[Department] d + ON edh.[DepartmentID] = d.[DepartmentID] +WHERE edh.EndDate IS NULL \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployeeDepartmentHistory.sql b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployeeDepartmentHistory.sql new file mode 100644 index 0000000..f8cc0f3 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vEmployeeDepartmentHistory.sql @@ -0,0 +1,27 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[vEmployeeDepartmentHistory]') AND type = 'V') +DROP VIEW [HumanResources].[vEmployeeDepartmentHistory] +GO + +CREATE VIEW [HumanResources].[vEmployeeDepartmentHistory] +AS +SELECT + e.[BusinessEntityID] + ,p.[Title] + ,p.[FirstName] + ,p.[MiddleName] + ,p.[LastName] + ,p.[Suffix] + ,s.[Name] AS [Shift] + ,d.[Name] AS [Department] + ,d.[GroupName] + ,edh.[StartDate] + ,edh.[EndDate] +FROM [HumanResources].[Employee] e + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = e.[BusinessEntityID] + INNER JOIN [HumanResources].[EmployeeDepartmentHistory] edh + ON e.[BusinessEntityID] = edh.[BusinessEntityID] + INNER JOIN [HumanResources].[Department] d + ON edh.[DepartmentID] = d.[DepartmentID] + INNER JOIN [HumanResources].[Shift] s + ON s.[ShiftID] = edh.[ShiftID]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidate.sql b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidate.sql new file mode 100644 index 0000000..8a1a162 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidate.sql @@ -0,0 +1,39 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[vJobCandidate]') AND type = 'V') +DROP VIEW [HumanResources].[vJobCandidate] +GO + +CREATE VIEW [HumanResources].[vJobCandidate] +AS +SELECT + jc.[JobCandidateID] + ,jc.[BusinessEntityID] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (/Resume/Name/Name.Prefix)[1]', 'nvarchar(30)') AS [Name.Prefix] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (/Resume/Name/Name.First)[1]', 'nvarchar(30)') AS [Name.First] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (/Resume/Name/Name.Middle)[1]', 'nvarchar(30)') AS [Name.Middle] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (/Resume/Name/Name.Last)[1]', 'nvarchar(30)') AS [Name.Last] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (/Resume/Name/Name.Suffix)[1]', 'nvarchar(30)') AS [Name.Suffix] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (/Resume/Skills)[1]', 'nvarchar(max)') AS [Skills] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Address/Addr.Type)[1]', 'nvarchar(30)') AS [Addr.Type] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Address/Addr.Location/Location/Loc.CountryRegion)[1]', 'nvarchar(100)') AS [Addr.Loc.CountryRegion] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Address/Addr.Location/Location/Loc.State)[1]', 'nvarchar(100)') AS [Addr.Loc.State] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Address/Addr.Location/Location/Loc.City)[1]', 'nvarchar(100)') AS [Addr.Loc.City] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Address/Addr.PostalCode)[1]', 'nvarchar(20)') AS [Addr.PostalCode] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (/Resume/EMail)[1]', 'nvarchar(max)') AS [EMail] + ,[Resume].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (/Resume/WebSite)[1]', 'nvarchar(max)') AS [WebSite] + ,jc.[ModifiedDate] +FROM [HumanResources].[JobCandidate] jc +CROSS APPLY jc.[Resume].nodes(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + /Resume') AS Resume(ref); \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidateEducation.sql b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidateEducation.sql new file mode 100644 index 0000000..7279a97 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidateEducation.sql @@ -0,0 +1,35 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[vJobCandidateEducation]') AND type = 'V') +DROP VIEW [HumanResources].[vJobCandidateEducation] +GO + +CREATE VIEW [HumanResources].[vJobCandidateEducation] +AS +SELECT + jc.[JobCandidateID] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.Level)[1]', 'nvarchar(max)') AS [Edu.Level] + ,CONVERT(datetime, REPLACE([Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.StartDate)[1]', 'nvarchar(20)') ,'Z', ''), 101) AS [Edu.StartDate] + ,CONVERT(datetime, REPLACE([Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.EndDate)[1]', 'nvarchar(20)') ,'Z', ''), 101) AS [Edu.EndDate] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.Degree)[1]', 'nvarchar(50)') AS [Edu.Degree] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.Major)[1]', 'nvarchar(50)') AS [Edu.Major] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.Minor)[1]', 'nvarchar(50)') AS [Edu.Minor] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.GPA)[1]', 'nvarchar(5)') AS [Edu.GPA] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.GPAScale)[1]', 'nvarchar(5)') AS [Edu.GPAScale] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.School)[1]', 'nvarchar(100)') AS [Edu.School] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.Location/Location/Loc.CountryRegion)[1]', 'nvarchar(100)') AS [Edu.Loc.CountryRegion] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.Location/Location/Loc.State)[1]', 'nvarchar(100)') AS [Edu.Loc.State] + ,[Education].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Edu.Location/Location/Loc.City)[1]', 'nvarchar(100)') AS [Edu.Loc.City] +FROM [HumanResources].[JobCandidate] jc +CROSS APPLY jc.[Resume].nodes(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + /Resume/Education') AS [Education](ref); \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidateEmployment.sql b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidateEmployment.sql new file mode 100644 index 0000000..2f421ae --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/HumanResources.vJobCandidateEmployment.sql @@ -0,0 +1,31 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[HumanResources].[vJobCandidateEmployment]') AND type = 'V') +DROP VIEW [HumanResources].[vJobCandidateEmployment] +GO + +CREATE VIEW [HumanResources].[vJobCandidateEmployment] +AS +SELECT + jc.[JobCandidateID] + ,CONVERT(datetime, REPLACE([Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.StartDate)[1]', 'nvarchar(20)') ,'Z', ''), 101) AS [Emp.StartDate] + ,CONVERT(datetime, REPLACE([Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.EndDate)[1]', 'nvarchar(20)') ,'Z', ''), 101) AS [Emp.EndDate] + ,[Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.OrgName)[1]', 'nvarchar(100)') AS [Emp.OrgName] + ,[Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.JobTitle)[1]', 'nvarchar(100)') AS [Emp.JobTitle] + ,[Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.Responsibility)[1]', 'nvarchar(max)') AS [Emp.Responsibility] + ,[Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.FunctionCategory)[1]', 'nvarchar(max)') AS [Emp.FunctionCategory] + ,[Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.IndustryCategory)[1]', 'nvarchar(max)') AS [Emp.IndustryCategory] + ,[Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.Location/Location/Loc.CountryRegion)[1]', 'nvarchar(max)') AS [Emp.Loc.CountryRegion] + ,[Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.Location/Location/Loc.State)[1]', 'nvarchar(max)') AS [Emp.Loc.State] + ,[Employment].ref.value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + (Emp.Location/Location/Loc.City)[1]', 'nvarchar(max)') AS [Emp.Loc.City] +FROM [HumanResources].[JobCandidate] jc +CROSS APPLY jc.[Resume].nodes(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/Resume"; + /Resume/Employment') AS Employment(ref); \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Person.vAdditionalContactInfo.sql b/snapshots/AdventureWorks2017/_sql-database/views/Person.vAdditionalContactInfo.sql new file mode 100644 index 0000000..a43b3f1 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Person.vAdditionalContactInfo.sql @@ -0,0 +1,51 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[vAdditionalContactInfo]') AND type = 'V') +DROP VIEW [Person].[vAdditionalContactInfo] +GO + +CREATE VIEW [Person].[vAdditionalContactInfo] +AS +SELECT + [BusinessEntityID] + ,[FirstName] + ,[MiddleName] + ,[LastName] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:telephoneNumber)[1]/act:number', 'nvarchar(50)') AS [TelephoneNumber] + ,LTRIM(RTRIM([ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:telephoneNumber/act:SpecialInstructions/text())[1]', 'nvarchar(max)'))) AS [TelephoneSpecialInstructions] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:homePostalAddress/act:Street)[1]', 'nvarchar(50)') AS [Street] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:homePostalAddress/act:City)[1]', 'nvarchar(50)') AS [City] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:homePostalAddress/act:StateProvince)[1]', 'nvarchar(50)') AS [StateProvince] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:homePostalAddress/act:PostalCode)[1]', 'nvarchar(50)') AS [PostalCode] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:homePostalAddress/act:CountryRegion)[1]', 'nvarchar(50)') AS [CountryRegion] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:homePostalAddress/act:SpecialInstructions/text())[1]', 'nvarchar(max)') AS [HomeAddressSpecialInstructions] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:eMail/act:eMailAddress)[1]', 'nvarchar(128)') AS [EMailAddress] + ,LTRIM(RTRIM([ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:eMail/act:SpecialInstructions/text())[1]', 'nvarchar(max)'))) AS [EMailSpecialInstructions] + ,[ContactInfo].ref.value(N'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + declare namespace act="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes"; + (act:eMail/act:SpecialInstructions/act:telephoneNumber/act:number)[1]', 'nvarchar(50)') AS [EMailTelephoneNumber] + ,[rowguid] + ,[ModifiedDate] +FROM [Person].[Person] +OUTER APPLY [AdditionalContactInfo].nodes( + 'declare namespace ci="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo"; + /ci:AdditionalContactInfo') AS ContactInfo(ref) +WHERE [AdditionalContactInfo] IS NOT NULL; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Person.vStateProvinceCountryRegion.sql b/snapshots/AdventureWorks2017/_sql-database/views/Person.vStateProvinceCountryRegion.sql new file mode 100644 index 0000000..635450b --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Person.vStateProvinceCountryRegion.sql @@ -0,0 +1,18 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Person].[vStateProvinceCountryRegion]') AND type = 'V') +DROP VIEW [Person].[vStateProvinceCountryRegion] +GO + +CREATE VIEW [Person].[vStateProvinceCountryRegion] +WITH SCHEMABINDING +AS +SELECT + sp.[StateProvinceID] + ,sp.[StateProvinceCode] + ,sp.[IsOnlyStateProvinceFlag] + ,sp.[Name] AS [StateProvinceName] + ,sp.[TerritoryID] + ,cr.[CountryRegionCode] + ,cr.[Name] AS [CountryRegionName] +FROM [Person].[StateProvince] sp + INNER JOIN [Person].[CountryRegion] cr + ON sp.[CountryRegionCode] = cr.[CountryRegionCode]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductAndDescription.sql b/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductAndDescription.sql new file mode 100644 index 0000000..b3ac854 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductAndDescription.sql @@ -0,0 +1,21 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[vProductAndDescription]') AND type = 'V') +DROP VIEW [Production].[vProductAndDescription] +GO + +CREATE VIEW [Production].[vProductAndDescription] +WITH SCHEMABINDING +AS +-- View (indexed or standard) to display products and product descriptions by language. +SELECT + p.[ProductID] + ,p.[Name] + ,pm.[Name] AS [ProductModel] + ,pmx.[CultureID] + ,pd.[Description] +FROM [Production].[Product] p + INNER JOIN [Production].[ProductModel] pm + ON p.[ProductModelID] = pm.[ProductModelID] + INNER JOIN [Production].[ProductModelProductDescriptionCulture] pmx + ON pm.[ProductModelID] = pmx.[ProductModelID] + INNER JOIN [Production].[ProductDescription] pd + ON pmx.[ProductDescriptionID] = pd.[ProductDescriptionID]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductModelCatalogDescription.sql b/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductModelCatalogDescription.sql new file mode 100644 index 0000000..9083a00 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductModelCatalogDescription.sql @@ -0,0 +1,65 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[vProductModelCatalogDescription]') AND type = 'V') +DROP VIEW [Production].[vProductModelCatalogDescription] +GO + +CREATE VIEW [Production].[vProductModelCatalogDescription] +AS +SELECT + [ProductModelID] + ,[Name] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace html="http://www.w3.org/1999/xhtml"; + (/p1:ProductDescription/p1:Summary/html:p)[1]', 'nvarchar(max)') AS [Summary] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Manufacturer/p1:Name)[1]', 'nvarchar(max)') AS [Manufacturer] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Manufacturer/p1:Copyright)[1]', 'nvarchar(30)') AS [Copyright] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Manufacturer/p1:ProductURL)[1]', 'nvarchar(256)') AS [ProductURL] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain"; + (/p1:ProductDescription/p1:Features/wm:Warranty/wm:WarrantyPeriod)[1]', 'nvarchar(256)') AS [WarrantyPeriod] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain"; + (/p1:ProductDescription/p1:Features/wm:Warranty/wm:Description)[1]', 'nvarchar(256)') AS [WarrantyDescription] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain"; + (/p1:ProductDescription/p1:Features/wm:Maintenance/wm:NoOfYears)[1]', 'nvarchar(256)') AS [NoOfYears] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wm="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelWarrAndMain"; + (/p1:ProductDescription/p1:Features/wm:Maintenance/wm:Description)[1]', 'nvarchar(256)') AS [MaintenanceDescription] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wf="http://www.adventure-works.com/schemas/OtherFeatures"; + (/p1:ProductDescription/p1:Features/wf:wheel)[1]', 'nvarchar(256)') AS [Wheel] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wf="http://www.adventure-works.com/schemas/OtherFeatures"; + (/p1:ProductDescription/p1:Features/wf:saddle)[1]', 'nvarchar(256)') AS [Saddle] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wf="http://www.adventure-works.com/schemas/OtherFeatures"; + (/p1:ProductDescription/p1:Features/wf:pedal)[1]', 'nvarchar(256)') AS [Pedal] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wf="http://www.adventure-works.com/schemas/OtherFeatures"; + (/p1:ProductDescription/p1:Features/wf:BikeFrame)[1]', 'nvarchar(max)') AS [BikeFrame] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + declare namespace wf="http://www.adventure-works.com/schemas/OtherFeatures"; + (/p1:ProductDescription/p1:Features/wf:crankset)[1]', 'nvarchar(256)') AS [Crankset] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Picture/p1:Angle)[1]', 'nvarchar(256)') AS [PictureAngle] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Picture/p1:Size)[1]', 'nvarchar(256)') AS [PictureSize] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Picture/p1:ProductPhotoID)[1]', 'nvarchar(256)') AS [ProductPhotoID] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Specifications/Material)[1]', 'nvarchar(256)') AS [Material] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Specifications/Color)[1]', 'nvarchar(256)') AS [Color] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Specifications/ProductLine)[1]', 'nvarchar(256)') AS [ProductLine] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Specifications/Style)[1]', 'nvarchar(256)') AS [Style] + ,[CatalogDescription].value(N'declare namespace p1="http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription"; + (/p1:ProductDescription/p1:Specifications/RiderExperience)[1]', 'nvarchar(1024)') AS [RiderExperience] + ,[rowguid] + ,[ModifiedDate] +FROM [Production].[ProductModel] +WHERE [CatalogDescription] IS NOT NULL; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductModelInstructions.sql b/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductModelInstructions.sql new file mode 100644 index 0000000..838506a --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Production.vProductModelInstructions.sql @@ -0,0 +1,24 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Production].[vProductModelInstructions]') AND type = 'V') +DROP VIEW [Production].[vProductModelInstructions] +GO + +CREATE VIEW [Production].[vProductModelInstructions] +AS +SELECT + [ProductModelID] + ,[Name] + ,[Instructions].value(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"; + (/root/text())[1]', 'nvarchar(max)') AS [Instructions] + ,[MfgInstructions].ref.value('@LocationID[1]', 'int') AS [LocationID] + ,[MfgInstructions].ref.value('@SetupHours[1]', 'decimal(9, 4)') AS [SetupHours] + ,[MfgInstructions].ref.value('@MachineHours[1]', 'decimal(9, 4)') AS [MachineHours] + ,[MfgInstructions].ref.value('@LaborHours[1]', 'decimal(9, 4)') AS [LaborHours] + ,[MfgInstructions].ref.value('@LotSize[1]', 'int') AS [LotSize] + ,[Steps].ref.value('string(.)[1]', 'nvarchar(1024)') AS [Step] + ,[rowguid] + ,[ModifiedDate] +FROM [Production].[ProductModel] +CROSS APPLY [Instructions].nodes(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"; + /root/Location') MfgInstructions(ref) +CROSS APPLY [MfgInstructions].ref.nodes('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelManuInstructions"; + step') Steps(ref); \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Purchasing.vVendorWithAddresses.sql b/snapshots/AdventureWorks2017/_sql-database/views/Purchasing.vVendorWithAddresses.sql new file mode 100644 index 0000000..90514ed --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Purchasing.vVendorWithAddresses.sql @@ -0,0 +1,26 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[vVendorWithAddresses]') AND type = 'V') +DROP VIEW [Purchasing].[vVendorWithAddresses] +GO + +CREATE VIEW [Purchasing].[vVendorWithAddresses] AS +SELECT + v.[BusinessEntityID] + ,v.[Name] + ,at.[Name] AS [AddressType] + ,a.[AddressLine1] + ,a.[AddressLine2] + ,a.[City] + ,sp.[Name] AS [StateProvinceName] + ,a.[PostalCode] + ,cr.[Name] AS [CountryRegionName] +FROM [Purchasing].[Vendor] v + INNER JOIN [Person].[BusinessEntityAddress] bea + ON bea.[BusinessEntityID] = v.[BusinessEntityID] + INNER JOIN [Person].[Address] a + ON a.[AddressID] = bea.[AddressID] + INNER JOIN [Person].[StateProvince] sp + ON sp.[StateProvinceID] = a.[StateProvinceID] + INNER JOIN [Person].[CountryRegion] cr + ON cr.[CountryRegionCode] = sp.[CountryRegionCode] + INNER JOIN [Person].[AddressType] at + ON at.[AddressTypeID] = bea.[AddressTypeID]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Purchasing.vVendorWithContacts.sql b/snapshots/AdventureWorks2017/_sql-database/views/Purchasing.vVendorWithContacts.sql new file mode 100644 index 0000000..437aca0 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Purchasing.vVendorWithContacts.sql @@ -0,0 +1,31 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Purchasing].[vVendorWithContacts]') AND type = 'V') +DROP VIEW [Purchasing].[vVendorWithContacts] +GO + +CREATE VIEW [Purchasing].[vVendorWithContacts] AS +SELECT + v.[BusinessEntityID] + ,v.[Name] + ,ct.[Name] AS [ContactType] + ,p.[Title] + ,p.[FirstName] + ,p.[MiddleName] + ,p.[LastName] + ,p.[Suffix] + ,pp.[PhoneNumber] + ,pnt.[Name] AS [PhoneNumberType] + ,ea.[EmailAddress] + ,p.[EmailPromotion] +FROM [Purchasing].[Vendor] v + INNER JOIN [Person].[BusinessEntityContact] bec + ON bec.[BusinessEntityID] = v.[BusinessEntityID] + INNER JOIN [Person].ContactType ct + ON ct.[ContactTypeID] = bec.[ContactTypeID] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = bec.[PersonID] + LEFT OUTER JOIN [Person].[EmailAddress] ea + ON ea.[BusinessEntityID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PersonPhone] pp + ON pp.[BusinessEntityID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PhoneNumberType] pnt + ON pnt.[PhoneNumberTypeID] = pp.[PhoneNumberTypeID]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Sales.vIndividualCustomer.sql b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vIndividualCustomer.sql new file mode 100644 index 0000000..4ab09f9 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vIndividualCustomer.sql @@ -0,0 +1,45 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[vIndividualCustomer]') AND type = 'V') +DROP VIEW [Sales].[vIndividualCustomer] +GO + +CREATE VIEW [Sales].[vIndividualCustomer] +AS +SELECT + p.[BusinessEntityID] + ,p.[Title] + ,p.[FirstName] + ,p.[MiddleName] + ,p.[LastName] + ,p.[Suffix] + ,pp.[PhoneNumber] + ,pnt.[Name] AS [PhoneNumberType] + ,ea.[EmailAddress] + ,p.[EmailPromotion] + ,at.[Name] AS [AddressType] + ,a.[AddressLine1] + ,a.[AddressLine2] + ,a.[City] + ,[StateProvinceName] = sp.[Name] + ,a.[PostalCode] + ,[CountryRegionName] = cr.[Name] + ,p.[Demographics] +FROM [Person].[Person] p + INNER JOIN [Person].[BusinessEntityAddress] bea + ON bea.[BusinessEntityID] = p.[BusinessEntityID] + INNER JOIN [Person].[Address] a + ON a.[AddressID] = bea.[AddressID] + INNER JOIN [Person].[StateProvince] sp + ON sp.[StateProvinceID] = a.[StateProvinceID] + INNER JOIN [Person].[CountryRegion] cr + ON cr.[CountryRegionCode] = sp.[CountryRegionCode] + INNER JOIN [Person].[AddressType] at + ON at.[AddressTypeID] = bea.[AddressTypeID] + INNER JOIN [Sales].[Customer] c + ON c.[PersonID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[EmailAddress] ea + ON ea.[BusinessEntityID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PersonPhone] pp + ON pp.[BusinessEntityID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PhoneNumberType] pnt + ON pnt.[PhoneNumberTypeID] = pp.[PhoneNumberTypeID] +WHERE c.StoreID IS NULL; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Sales.vPersonDemographics.sql b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vPersonDemographics.sql new file mode 100644 index 0000000..171c9d4 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vPersonDemographics.sql @@ -0,0 +1,36 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[vPersonDemographics]') AND type = 'V') +DROP VIEW [Sales].[vPersonDemographics] +GO + +CREATE VIEW [Sales].[vPersonDemographics] +AS +SELECT + p.[BusinessEntityID] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + TotalPurchaseYTD[1]', 'money') AS [TotalPurchaseYTD] + ,CONVERT(datetime, REPLACE([IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + DateFirstPurchase[1]', 'nvarchar(20)') ,'Z', ''), 101) AS [DateFirstPurchase] + ,CONVERT(datetime, REPLACE([IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + BirthDate[1]', 'nvarchar(20)') ,'Z', ''), 101) AS [BirthDate] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + MaritalStatus[1]', 'nvarchar(1)') AS [MaritalStatus] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + YearlyIncome[1]', 'nvarchar(30)') AS [YearlyIncome] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + Gender[1]', 'nvarchar(1)') AS [Gender] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + TotalChildren[1]', 'integer') AS [TotalChildren] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + NumberChildrenAtHome[1]', 'integer') AS [NumberChildrenAtHome] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + Education[1]', 'nvarchar(30)') AS [Education] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + Occupation[1]', 'nvarchar(30)') AS [Occupation] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + HomeOwnerFlag[1]', 'bit') AS [HomeOwnerFlag] + ,[IndividualSurvey].[ref].[value](N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + NumberCarsOwned[1]', 'integer') AS [NumberCarsOwned] +FROM [Person].[Person] p +CROSS APPLY p.[Demographics].nodes(N'declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/IndividualSurvey"; + /IndividualSurvey') AS [IndividualSurvey](ref) +WHERE [Demographics] IS NOT NULL; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Sales.vSalesPerson.sql b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vSalesPerson.sql new file mode 100644 index 0000000..dbbbfa5 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vSalesPerson.sql @@ -0,0 +1,50 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[vSalesPerson]') AND type = 'V') +DROP VIEW [Sales].[vSalesPerson] +GO + +CREATE VIEW [Sales].[vSalesPerson] +AS +SELECT + s.[BusinessEntityID] + ,p.[Title] + ,p.[FirstName] + ,p.[MiddleName] + ,p.[LastName] + ,p.[Suffix] + ,e.[JobTitle] + ,pp.[PhoneNumber] + ,pnt.[Name] AS [PhoneNumberType] + ,ea.[EmailAddress] + ,p.[EmailPromotion] + ,a.[AddressLine1] + ,a.[AddressLine2] + ,a.[City] + ,[StateProvinceName] = sp.[Name] + ,a.[PostalCode] + ,[CountryRegionName] = cr.[Name] + ,[TerritoryName] = st.[Name] + ,[TerritoryGroup] = st.[Group] + ,s.[SalesQuota] + ,s.[SalesYTD] + ,s.[SalesLastYear] +FROM [Sales].[SalesPerson] s + INNER JOIN [HumanResources].[Employee] e + ON e.[BusinessEntityID] = s.[BusinessEntityID] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = s.[BusinessEntityID] + INNER JOIN [Person].[BusinessEntityAddress] bea + ON bea.[BusinessEntityID] = s.[BusinessEntityID] + INNER JOIN [Person].[Address] a + ON a.[AddressID] = bea.[AddressID] + INNER JOIN [Person].[StateProvince] sp + ON sp.[StateProvinceID] = a.[StateProvinceID] + INNER JOIN [Person].[CountryRegion] cr + ON cr.[CountryRegionCode] = sp.[CountryRegionCode] + LEFT OUTER JOIN [Sales].[SalesTerritory] st + ON st.[TerritoryID] = s.[TerritoryID] + LEFT OUTER JOIN [Person].[EmailAddress] ea + ON ea.[BusinessEntityID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PersonPhone] pp + ON pp.[BusinessEntityID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PhoneNumberType] pnt + ON pnt.[PhoneNumberTypeID] = pp.[PhoneNumberTypeID]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Sales.vSalesPersonSalesByFiscalYears.sql b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vSalesPersonSalesByFiscalYears.sql new file mode 100644 index 0000000..333896f --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vSalesPersonSalesByFiscalYears.sql @@ -0,0 +1,37 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[vSalesPersonSalesByFiscalYears]') AND type = 'V') +DROP VIEW [Sales].[vSalesPersonSalesByFiscalYears] +GO + +CREATE VIEW [Sales].[vSalesPersonSalesByFiscalYears] +AS +SELECT + pvt.[SalesPersonID] + ,pvt.[FullName] + ,pvt.[JobTitle] + ,pvt.[SalesTerritory] + ,pvt.[2002] + ,pvt.[2003] + ,pvt.[2004] +FROM (SELECT + soh.[SalesPersonID] + ,p.[FirstName] + ' ' + COALESCE(p.[MiddleName], '') + ' ' + p.[LastName] AS [FullName] + ,e.[JobTitle] + ,st.[Name] AS [SalesTerritory] + ,soh.[SubTotal] + ,YEAR(DATEADD(m, 6, soh.[OrderDate])) AS [FiscalYear] + FROM [Sales].[SalesPerson] sp + INNER JOIN [Sales].[SalesOrderHeader] soh + ON sp.[BusinessEntityID] = soh.[SalesPersonID] + INNER JOIN [Sales].[SalesTerritory] st + ON sp.[TerritoryID] = st.[TerritoryID] + INNER JOIN [HumanResources].[Employee] e + ON soh.[SalesPersonID] = e.[BusinessEntityID] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = sp.[BusinessEntityID] + ) AS soh +PIVOT +( + SUM([SubTotal]) + FOR [FiscalYear] + IN ([2002], [2003], [2004]) +) AS pvt; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithAddresses.sql b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithAddresses.sql new file mode 100644 index 0000000..6f56ad5 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithAddresses.sql @@ -0,0 +1,26 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[vStoreWithAddresses]') AND type = 'V') +DROP VIEW [Sales].[vStoreWithAddresses] +GO + +CREATE VIEW [Sales].[vStoreWithAddresses] AS +SELECT + s.[BusinessEntityID] + ,s.[Name] + ,at.[Name] AS [AddressType] + ,a.[AddressLine1] + ,a.[AddressLine2] + ,a.[City] + ,sp.[Name] AS [StateProvinceName] + ,a.[PostalCode] + ,cr.[Name] AS [CountryRegionName] +FROM [Sales].[Store] s + INNER JOIN [Person].[BusinessEntityAddress] bea + ON bea.[BusinessEntityID] = s.[BusinessEntityID] + INNER JOIN [Person].[Address] a + ON a.[AddressID] = bea.[AddressID] + INNER JOIN [Person].[StateProvince] sp + ON sp.[StateProvinceID] = a.[StateProvinceID] + INNER JOIN [Person].[CountryRegion] cr + ON cr.[CountryRegionCode] = sp.[CountryRegionCode] + INNER JOIN [Person].[AddressType] at + ON at.[AddressTypeID] = bea.[AddressTypeID]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithContacts.sql b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithContacts.sql new file mode 100644 index 0000000..2fd49cb --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithContacts.sql @@ -0,0 +1,31 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[vStoreWithContacts]') AND type = 'V') +DROP VIEW [Sales].[vStoreWithContacts] +GO + +CREATE VIEW [Sales].[vStoreWithContacts] AS +SELECT + s.[BusinessEntityID] + ,s.[Name] + ,ct.[Name] AS [ContactType] + ,p.[Title] + ,p.[FirstName] + ,p.[MiddleName] + ,p.[LastName] + ,p.[Suffix] + ,pp.[PhoneNumber] + ,pnt.[Name] AS [PhoneNumberType] + ,ea.[EmailAddress] + ,p.[EmailPromotion] +FROM [Sales].[Store] s + INNER JOIN [Person].[BusinessEntityContact] bec + ON bec.[BusinessEntityID] = s.[BusinessEntityID] + INNER JOIN [Person].[ContactType] ct + ON ct.[ContactTypeID] = bec.[ContactTypeID] + INNER JOIN [Person].[Person] p + ON p.[BusinessEntityID] = bec.[PersonID] + LEFT OUTER JOIN [Person].[EmailAddress] ea + ON ea.[BusinessEntityID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PersonPhone] pp + ON pp.[BusinessEntityID] = p.[BusinessEntityID] + LEFT OUTER JOIN [Person].[PhoneNumberType] pnt + ON pnt.[PhoneNumberTypeID] = pp.[PhoneNumberTypeID]; \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithDemographics.sql b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithDemographics.sql new file mode 100644 index 0000000..28b7ec2 --- /dev/null +++ b/snapshots/AdventureWorks2017/_sql-database/views/Sales.vStoreWithDemographics.sql @@ -0,0 +1,29 @@ +IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID('[Sales].[vStoreWithDemographics]') AND type = 'V') +DROP VIEW [Sales].[vStoreWithDemographics] +GO + +CREATE VIEW [Sales].[vStoreWithDemographics] AS +SELECT + s.[BusinessEntityID] + ,s.[Name] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/AnnualSales)[1]', 'money') AS [AnnualSales] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/AnnualRevenue)[1]', 'money') AS [AnnualRevenue] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/BankName)[1]', 'nvarchar(50)') AS [BankName] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/BusinessType)[1]', 'nvarchar(5)') AS [BusinessType] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/YearOpened)[1]', 'integer') AS [YearOpened] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/Specialty)[1]', 'nvarchar(50)') AS [Specialty] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/SquareFeet)[1]', 'integer') AS [SquareFeet] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/Brands)[1]', 'nvarchar(30)') AS [Brands] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/Internet)[1]', 'nvarchar(30)') AS [Internet] + ,s.[Demographics].value('declare default element namespace "http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/StoreSurvey"; + (/StoreSurvey/NumberEmployees)[1]', 'integer') AS [NumberEmployees] +FROM [Sales].[Store] s; \ No newline at end of file From 439c7f746dea217c3412125c6810e84336d8c90b Mon Sep 17 00:00:00 2001 From: Marco von Ballmoos Date: Wed, 3 Feb 2021 06:42:10 +0100 Subject: [PATCH 2/5] Improve ordering for indexes, fks, and columns fixes #84 --- .../_sql-database/cache.json | 36 +++++++++---------- .../tables/HumanResources.Employee.sql | 20 +++++------ ...manResources.EmployeeDepartmentHistory.sql | 12 +++---- .../tables/Person.AddressType.sql | 8 ++--- .../tables/Person.BusinessEntityContact.sql | 20 +++++------ .../_sql-database/tables/Person.Person.sql | 8 ++--- .../tables/Person.StateProvince.sql | 20 +++++------ .../tables/Production.Document.sql | 14 ++++---- .../tables/Production.Product.sql | 28 +++++++-------- .../Production.ProductModelIllustration.sql | 12 +++---- ....ProductModelProductDescriptionCulture.sql | 12 +++---- .../tables/Production.WorkOrder.sql | 8 ++--- .../tables/Purchasing.ProductVendor.sql | 8 ++--- .../tables/Purchasing.PurchaseOrderHeader.sql | 20 +++++------ .../_sql-database/tables/Sales.Customer.sql | 16 ++++----- .../tables/Sales.SalesOrderDetail.sql | 12 +++---- .../tables/Sales.SalesOrderHeader.sql | 36 +++++++++---------- .../tables/Sales.SalesPerson.sql | 12 +++---- .../_sql-database/tables/Sales.Store.sql | 12 +++---- src/queries/mssql.ts | 8 +++-- 20 files changed, 163 insertions(+), 159 deletions(-) diff --git a/snapshots/AdventureWorks2017/_sql-database/cache.json b/snapshots/AdventureWorks2017/_sql-database/cache.json index f227909..51eb17d 100644 --- a/snapshots/AdventureWorks2017/_sql-database/cache.json +++ b/snapshots/AdventureWorks2017/_sql-database/cache.json @@ -61,30 +61,30 @@ "./_sql-database/tables/dbo.DatabaseLog.sql": "9b20616aecea60d1132431f20dce0fde9afb31de", "./_sql-database/tables/dbo.ErrorLog.sql": "6c739cf6b1b1aa3961fe170e7d0a0ae923231dc6", "./_sql-database/tables/HumanResources.Department.sql": "4bf0595e675d1c71d990a77fc33d68c396b0d241", - "./_sql-database/tables/HumanResources.Employee.sql": "efb72f408a7abffb1f530000d5dcf5a2ff975df6", - "./_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql": "ef90daec320d2041e876901451e2eb67b509e014", + "./_sql-database/tables/HumanResources.Employee.sql": "869fd1a890dac547e5ac415b394af65bf5c2056d", + "./_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql": "2bce1ecb28ad83ec8e2fde23d5f53d1532e422c2", "./_sql-database/tables/HumanResources.EmployeePayHistory.sql": "e678293368b54c34b83cfbdd5ed3dbedc44abbe8", "./_sql-database/tables/HumanResources.JobCandidate.sql": "dd7d9e12a1ae830f413c842bbde6722060272232", "./_sql-database/tables/HumanResources.Shift.sql": "5412bee432ceac402b6fd77c6ecf87aa625bb38f", "./_sql-database/tables/Person.Address.sql": "68680d701dff19b65fef954f220a8533b307404b", - "./_sql-database/tables/Person.AddressType.sql": "8e5a5bfbf1e131930b4140e13093f24def40241a", + "./_sql-database/tables/Person.AddressType.sql": "db20ad02fef4d29f269ee2ad8f0145e9afc2cc93", "./_sql-database/tables/Person.BusinessEntity.sql": "974a196e5c5b127d95e7f85f24ac45e04117684a", "./_sql-database/tables/Person.BusinessEntityAddress.sql": "b8f0dc95ff96356fd546f88027be3ec2549694a5", - "./_sql-database/tables/Person.BusinessEntityContact.sql": "db00db36a8c305369614ccc5b928e8597e3b1cc2", + "./_sql-database/tables/Person.BusinessEntityContact.sql": "037f5207e4d2e6492cc7db5cfdfd47787cce72b5", "./_sql-database/tables/Person.ContactType.sql": "ae76fd3b5a19761acd6957cc95ef81b23bbc0458", "./_sql-database/tables/Person.CountryRegion.sql": "6dcb67e6e55ec55854090e164562551a42eb0880", "./_sql-database/tables/Person.EmailAddress.sql": "e94818c21608b6c16059debc16f29a09befe0f99", "./_sql-database/tables/Person.Password.sql": "a41a0ec2d9436debe18d14814320d64039a6571f", - "./_sql-database/tables/Person.Person.sql": "adfd8437559df08805009a01a639406d7a06c614", + "./_sql-database/tables/Person.Person.sql": "99b4a04c751bcfec7865a1d09b0e79861d5e1302", "./_sql-database/tables/Person.PersonPhone.sql": "aa5de40c666f70eecfc40a3067bfe01de5c8e123", "./_sql-database/tables/Person.PhoneNumberType.sql": "b3f1927d41efef70d3163b872248fe10d59a2836", - "./_sql-database/tables/Person.StateProvince.sql": "7282919a39b919cf793bd7d5ddbc20a817aa418d", + "./_sql-database/tables/Person.StateProvince.sql": "2b39fed01f057f53f21b420e37d3f033d214bbd9", "./_sql-database/tables/Production.BillOfMaterials.sql": "7d64a3f1e814414b679f84a4dc68f33cdf3207c2", "./_sql-database/tables/Production.Culture.sql": "669198dedd761006eab9c95d4c2787b81af382e7", - "./_sql-database/tables/Production.Document.sql": "944cbdb6e94631a1b6a40f646b5b2dc8e19944a7", + "./_sql-database/tables/Production.Document.sql": "1fc68a7ae8d1786ef7d4686bbd6798ef38c39fd5", "./_sql-database/tables/Production.Illustration.sql": "b52688b6f9683af379664a18d369ec37aa0a876b", "./_sql-database/tables/Production.Location.sql": "3925e29b56e538ac8a809e628e10bf131e88c510", - "./_sql-database/tables/Production.Product.sql": "6772a934c8b90450de2593cff0cf08f29badd71f", + "./_sql-database/tables/Production.Product.sql": "faf32aa3aa164bb969326142d0f4681a12bde5cd", "./_sql-database/tables/Production.ProductCategory.sql": "fa70876299e8516c069f23fd487020382bb492dc", "./_sql-database/tables/Production.ProductCostHistory.sql": "2f000a5d847fd588eb0e2731959497c116fe1766", "./_sql-database/tables/Production.ProductDescription.sql": "53200ad11d1c00bb4c5aba33084a19f5d926610a", @@ -92,8 +92,8 @@ "./_sql-database/tables/Production.ProductInventory.sql": "7b7dd3eb81441b115f7dbd3653184b22d2884977", "./_sql-database/tables/Production.ProductListPriceHistory.sql": "43a187a7830aecc7cac2c66679f65b0408812bd7", "./_sql-database/tables/Production.ProductModel.sql": "45044e688a4df4b4145ef29b143ecacc0002d530", - "./_sql-database/tables/Production.ProductModelIllustration.sql": "a0fc4231412400c3778340c9bf591d3ef34bf9ad", - "./_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql": "f7a4713f2c77236a2791f26ecc9e0951fcd2679b", + "./_sql-database/tables/Production.ProductModelIllustration.sql": "35702a9bfabb60d049e1b459e52ebcef6bf9f0ba", + "./_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql": "18839f0e1271aaadfd042934b4c9b71355301eea", "./_sql-database/tables/Production.ProductPhoto.sql": "d7b72993e64484f44bb8932ed4e80a353cff329a", "./_sql-database/tables/Production.ProductProductPhoto.sql": "13698d2287e6db1afbd1bec573381e2227c6cadd", "./_sql-database/tables/Production.ProductReview.sql": "85ef51696acecab21e2d2944f3e9af874c916a90", @@ -102,23 +102,23 @@ "./_sql-database/tables/Production.TransactionHistory.sql": "9a09d00eb017ea790aea36dc2dabcb2f094ecf6f", "./_sql-database/tables/Production.TransactionHistoryArchive.sql": "bfc3780f6a06bccb1855e0f80e95528729a1452a", "./_sql-database/tables/Production.UnitMeasure.sql": "fa9d2d7d7f3765d3b4207f387a00da1017caa2c4", - "./_sql-database/tables/Production.WorkOrder.sql": "2bb7abe8a821dc1186acd6fb48089b7253d84cf5", + "./_sql-database/tables/Production.WorkOrder.sql": "32e16e3790fd167b5d3f95fb491d22f104df5217", "./_sql-database/tables/Production.WorkOrderRouting.sql": "e8bc4941b895aed4a22d72e164149c55a36c00f1", - "./_sql-database/tables/Purchasing.ProductVendor.sql": "5679232c7304bedb60db966e179f2ef2295d98e3", + "./_sql-database/tables/Purchasing.ProductVendor.sql": "9da691fd0de7987569c2b89bb6e50a9590f5a673", "./_sql-database/tables/Purchasing.PurchaseOrderDetail.sql": "82fe42908da1126989ce6ab95870717099922cac", - "./_sql-database/tables/Purchasing.PurchaseOrderHeader.sql": "77c76c3fdecbb4730a97a6d716eef6429478e2d5", + "./_sql-database/tables/Purchasing.PurchaseOrderHeader.sql": "613489231b1a0f1b3975c45a57269714107ccdbc", "./_sql-database/tables/Purchasing.ShipMethod.sql": "5394f2981ad744a8dbaee1a2c38ab71147341b51", "./_sql-database/tables/Purchasing.Vendor.sql": "ced603aa7c11d0fb9d08382789c418063b0e0edd", "./_sql-database/tables/Sales.CountryRegionCurrency.sql": "5622b3c4f006221a6f12a30c4939445e9d9493c6", "./_sql-database/tables/Sales.CreditCard.sql": "f4af312a986ea206311b2cfaa53594be33932cb1", "./_sql-database/tables/Sales.Currency.sql": "fabf07099843b49440dcd19d8ba9ed1076c8f388", "./_sql-database/tables/Sales.CurrencyRate.sql": "5d70f9ddae2217579f68385a51e87d383e22731f", - "./_sql-database/tables/Sales.Customer.sql": "05ef02be43fece57282fcbf4620ef784e77849f5", + "./_sql-database/tables/Sales.Customer.sql": "094a871031dca6359ee69d633e4650109e9fdc24", "./_sql-database/tables/Sales.PersonCreditCard.sql": "d7ad3c50573afa566eea8b81d82c5e3a4cf893d0", - "./_sql-database/tables/Sales.SalesOrderDetail.sql": "f49f8e7285180f1fcb72d62bcb06a220f87c461f", - "./_sql-database/tables/Sales.SalesOrderHeader.sql": "73f740194dbd318306739fa19a9e7f9b61d32268", + "./_sql-database/tables/Sales.SalesOrderDetail.sql": "224f2c8fad11bd509ac433f0f44bb78134951dc8", + "./_sql-database/tables/Sales.SalesOrderHeader.sql": "f4bc38c4b80a9f2a3ba596d2cd964e3aa5a2c9c7", "./_sql-database/tables/Sales.SalesOrderHeaderSalesReason.sql": "73ae5cd408599da33244513ad3b28b7e62c5c5e9", - "./_sql-database/tables/Sales.SalesPerson.sql": "eca6c6e1784db302f77ba4174d8309f1b531ab2f", + "./_sql-database/tables/Sales.SalesPerson.sql": "fa795cef613a61e4a054d97d52fe607bd9545d69", "./_sql-database/tables/Sales.SalesPersonQuotaHistory.sql": "ef550aaf480d195cad77ee64012550d84bfc32f5", "./_sql-database/tables/Sales.SalesReason.sql": "f96124a0f52cdd19f97c33c9509628910e3f7e04", "./_sql-database/tables/Sales.SalesTaxRate.sql": "90a84223ccf918555e12b41dc88206dd27f11398", @@ -127,7 +127,7 @@ "./_sql-database/tables/Sales.ShoppingCartItem.sql": "8206e8481d09d11bc70a9641da950455fe50e154", "./_sql-database/tables/Sales.SpecialOffer.sql": "6a4dd953f1199f84324869d412ddc76b3783e85d", "./_sql-database/tables/Sales.SpecialOfferProduct.sql": "d64c059bc3e4d7f6f5843f7c973d6d36f06100f9", - "./_sql-database/tables/Sales.Store.sql": "2df1f5fcafd6c96952bbebc30303810110c26d12", + "./_sql-database/tables/Sales.Store.sql": "e139180fa8ff7e7989842121398e4fd04405505b", "./_sql-database/types/dbo.AccountNumber.sql": "055ec65e54884c34ea6cb9e054cf550744e6ad97", "./_sql-database/types/dbo.Flag.sql": "79e7e65d23ae0f9c89855c28e7fa12e4ea58575e", "./_sql-database/types/dbo.NameStyle.sql": "f6c4f576d12ee8d600a657f5a803a58932b0d2d5", diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Employee.sql b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Employee.sql index ff4ecd4..0867c50 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Employee.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.Employee.sql @@ -26,15 +26,6 @@ BEGIN ALTER TABLE [HumanResources].[Employee] CHECK CONSTRAINT [FK_Employee_Person_BusinessEntityID] END -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'IX_Employee_OrganizationNode') -CREATE NONCLUSTERED INDEX [IX_Employee_OrganizationNode] ON [HumanResources].[Employee]([OrganizationNode] ASC) - -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'IX_Employee_OrganizationLevel_OrganizationNode') -CREATE NONCLUSTERED INDEX [IX_Employee_OrganizationLevel_OrganizationNode] ON [HumanResources].[Employee]( - [OrganizationLevel] ASC, - [OrganizationNode] ASC -) - IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'AK_Employee_LoginID') CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_LoginID] ON [HumanResources].[Employee]([LoginID] ASC) @@ -42,4 +33,13 @@ IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanReso CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_NationalIDNumber] ON [HumanResources].[Employee]([NationalIDNumber] ASC) IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'AK_Employee_rowguid') -CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_rowguid] ON [HumanResources].[Employee]([rowguid] ASC) \ No newline at end of file +CREATE UNIQUE NONCLUSTERED INDEX [AK_Employee_rowguid] ON [HumanResources].[Employee]([rowguid] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'IX_Employee_OrganizationLevel_OrganizationNode') +CREATE NONCLUSTERED INDEX [IX_Employee_OrganizationLevel_OrganizationNode] ON [HumanResources].[Employee]( + [OrganizationLevel] ASC, + [OrganizationNode] ASC +) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[Employee]') AND name = 'IX_Employee_OrganizationNode') +CREATE NONCLUSTERED INDEX [IX_Employee_OrganizationNode] ON [HumanResources].[Employee]([OrganizationNode] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql index 4c901b2..af1d08f 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql @@ -16,12 +16,6 @@ CREATE TABLE [HumanResources].[EmployeeDepartmentHistory] ) ) -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_EmployeeDepartmentHistory_Shift_ShiftID]') AND parent_object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]')) -BEGIN - ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] WITH CHECK ADD CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID] FOREIGN KEY ([ShiftID]) REFERENCES [HumanResources].[Shift] ([ShiftID]) - ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_EmployeeDepartmentHistory_Department_DepartmentID]') AND parent_object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]')) BEGIN ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] WITH CHECK ADD CONSTRAINT [FK_EmployeeDepartmentHistory_Department_DepartmentID] FOREIGN KEY ([DepartmentID]) REFERENCES [HumanResources].[Department] ([DepartmentID]) @@ -34,6 +28,12 @@ BEGIN ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Employee_BusinessEntityID] END +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[HumanResources].[FK_EmployeeDepartmentHistory_Shift_ShiftID]') AND parent_object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]')) +BEGIN + ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] WITH CHECK ADD CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID] FOREIGN KEY ([ShiftID]) REFERENCES [HumanResources].[Shift] ([ShiftID]) + ALTER TABLE [HumanResources].[EmployeeDepartmentHistory] CHECK CONSTRAINT [FK_EmployeeDepartmentHistory_Shift_ShiftID] +END + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[HumanResources].[EmployeeDepartmentHistory]') AND name = 'IX_EmployeeDepartmentHistory_DepartmentID') CREATE NONCLUSTERED INDEX [IX_EmployeeDepartmentHistory_DepartmentID] ON [HumanResources].[EmployeeDepartmentHistory]([DepartmentID] ASC) diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.AddressType.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.AddressType.sql index 0e4b53d..8f44f17 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Person.AddressType.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.AddressType.sql @@ -8,8 +8,8 @@ CREATE TABLE [Person].[AddressType] CONSTRAINT [PK_AddressType_AddressTypeID] PRIMARY KEY CLUSTERED ([AddressTypeID] ASC) ) -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[AddressType]') AND name = 'AK_AddressType_rowguid') -CREATE UNIQUE NONCLUSTERED INDEX [AK_AddressType_rowguid] ON [Person].[AddressType]([rowguid] ASC) - IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[AddressType]') AND name = 'AK_AddressType_Name') -CREATE UNIQUE NONCLUSTERED INDEX [AK_AddressType_Name] ON [Person].[AddressType]([Name] ASC) \ No newline at end of file +CREATE UNIQUE NONCLUSTERED INDEX [AK_AddressType_Name] ON [Person].[AddressType]([Name] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[AddressType]') AND name = 'AK_AddressType_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_AddressType_rowguid] ON [Person].[AddressType]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityContact.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityContact.sql index d107ca7..2e80209 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityContact.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.BusinessEntityContact.sql @@ -20,23 +20,23 @@ BEGIN ALTER TABLE [Person].[BusinessEntityContact] CHECK CONSTRAINT [FK_BusinessEntityContact_Person_PersonID] END -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityContact_BusinessEntity_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityContact]')) -BEGIN - ALTER TABLE [Person].[BusinessEntityContact] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityContact_BusinessEntity_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[BusinessEntity] ([BusinessEntityID]) - ALTER TABLE [Person].[BusinessEntityContact] CHECK CONSTRAINT [FK_BusinessEntityContact_BusinessEntity_BusinessEntityID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityContact_ContactType_ContactTypeID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityContact]')) BEGIN ALTER TABLE [Person].[BusinessEntityContact] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityContact_ContactType_ContactTypeID] FOREIGN KEY ([ContactTypeID]) REFERENCES [Person].[ContactType] ([ContactTypeID]) ALTER TABLE [Person].[BusinessEntityContact] CHECK CONSTRAINT [FK_BusinessEntityContact_ContactType_ContactTypeID] END +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_BusinessEntityContact_BusinessEntity_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Person].[BusinessEntityContact]')) +BEGIN + ALTER TABLE [Person].[BusinessEntityContact] WITH CHECK ADD CONSTRAINT [FK_BusinessEntityContact_BusinessEntity_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[BusinessEntity] ([BusinessEntityID]) + ALTER TABLE [Person].[BusinessEntityContact] CHECK CONSTRAINT [FK_BusinessEntityContact_BusinessEntity_BusinessEntityID] +END + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityContact]') AND name = 'AK_BusinessEntityContact_rowguid') CREATE UNIQUE NONCLUSTERED INDEX [AK_BusinessEntityContact_rowguid] ON [Person].[BusinessEntityContact]([rowguid] ASC) -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityContact]') AND name = 'IX_BusinessEntityContact_PersonID') -CREATE NONCLUSTERED INDEX [IX_BusinessEntityContact_PersonID] ON [Person].[BusinessEntityContact]([PersonID] ASC) - IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityContact]') AND name = 'IX_BusinessEntityContact_ContactTypeID') -CREATE NONCLUSTERED INDEX [IX_BusinessEntityContact_ContactTypeID] ON [Person].[BusinessEntityContact]([ContactTypeID] ASC) \ No newline at end of file +CREATE NONCLUSTERED INDEX [IX_BusinessEntityContact_ContactTypeID] ON [Person].[BusinessEntityContact]([ContactTypeID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[BusinessEntityContact]') AND name = 'IX_BusinessEntityContact_PersonID') +CREATE NONCLUSTERED INDEX [IX_BusinessEntityContact_PersonID] ON [Person].[BusinessEntityContact]([PersonID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.Person.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.Person.sql index 2ce2085..6534503 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Person.Person.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.Person.sql @@ -23,12 +23,12 @@ BEGIN ALTER TABLE [Person].[Person] CHECK CONSTRAINT [FK_Person_BusinessEntity_BusinessEntityID] END +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[Person]') AND name = 'AK_Person_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Person_rowguid] ON [Person].[Person]([rowguid] ASC) + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[Person]') AND name = 'IX_Person_LastName_FirstName_MiddleName') CREATE NONCLUSTERED INDEX [IX_Person_LastName_FirstName_MiddleName] ON [Person].[Person]( [LastName] ASC, [FirstName] ASC, [MiddleName] ASC -) - -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[Person]') AND name = 'AK_Person_rowguid') -CREATE UNIQUE NONCLUSTERED INDEX [AK_Person_rowguid] ON [Person].[Person]([rowguid] ASC) \ No newline at end of file +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Person.StateProvince.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Person.StateProvince.sql index 904a2b6..fa46305 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Person.StateProvince.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Person.StateProvince.sql @@ -12,26 +12,26 @@ CREATE TABLE [Person].[StateProvince] CONSTRAINT [PK_StateProvince_StateProvinceID] PRIMARY KEY CLUSTERED ([StateProvinceID] ASC) ) -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_StateProvince_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Person].[StateProvince]')) -BEGIN - ALTER TABLE [Person].[StateProvince] WITH CHECK ADD CONSTRAINT [FK_StateProvince_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) - ALTER TABLE [Person].[StateProvince] CHECK CONSTRAINT [FK_StateProvince_SalesTerritory_TerritoryID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_StateProvince_CountryRegion_CountryRegionCode]') AND parent_object_id = OBJECT_ID('[Person].[StateProvince]')) BEGIN ALTER TABLE [Person].[StateProvince] WITH CHECK ADD CONSTRAINT [FK_StateProvince_CountryRegion_CountryRegionCode] FOREIGN KEY ([CountryRegionCode]) REFERENCES [Person].[CountryRegion] ([CountryRegionCode]) ALTER TABLE [Person].[StateProvince] CHECK CONSTRAINT [FK_StateProvince_CountryRegion_CountryRegionCode] END +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Person].[FK_StateProvince_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Person].[StateProvince]')) +BEGIN + ALTER TABLE [Person].[StateProvince] WITH CHECK ADD CONSTRAINT [FK_StateProvince_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Person].[StateProvince] CHECK CONSTRAINT [FK_StateProvince_SalesTerritory_TerritoryID] +END + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[StateProvince]') AND name = 'AK_StateProvince_Name') CREATE UNIQUE NONCLUSTERED INDEX [AK_StateProvince_Name] ON [Person].[StateProvince]([Name] ASC) +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[StateProvince]') AND name = 'AK_StateProvince_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_StateProvince_rowguid] ON [Person].[StateProvince]([rowguid] ASC) + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[StateProvince]') AND name = 'AK_StateProvince_StateProvinceCode_CountryRegionCode') CREATE UNIQUE NONCLUSTERED INDEX [AK_StateProvince_StateProvinceCode_CountryRegionCode] ON [Person].[StateProvince]( [StateProvinceCode] ASC, [CountryRegionCode] ASC -) - -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Person].[StateProvince]') AND name = 'AK_StateProvince_rowguid') -CREATE UNIQUE NONCLUSTERED INDEX [AK_StateProvince_rowguid] ON [Person].[StateProvince]([rowguid] ASC) \ No newline at end of file +) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Document.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Document.sql index 414e745..26037c3 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Document.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Document.sql @@ -24,6 +24,12 @@ BEGIN ALTER TABLE [Production].[Document] CHECK CONSTRAINT [FK_Document_Employee_Owner] END +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Document]') AND name = 'AK_Document_DocumentLevel_DocumentNode') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Document_DocumentLevel_DocumentNode] ON [Production].[Document]( + [DocumentLevel] ASC, + [DocumentNode] ASC +) + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Document]') AND name = 'AK_Document_rowguid') CREATE UNIQUE NONCLUSTERED INDEX [AK_Document_rowguid] ON [Production].[Document]([rowguid] ASC) @@ -34,10 +40,4 @@ CREATE NONCLUSTERED INDEX [IX_Document_FileName_Revision] ON [Production].[Docum ) IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Document]') AND name = 'UQ__Document__F73921F7C5112C2E') -CREATE UNIQUE NONCLUSTERED INDEX [UQ__Document__F73921F7C5112C2E] ON [Production].[Document]([rowguid] ASC) - -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Document]') AND name = 'AK_Document_DocumentLevel_DocumentNode') -CREATE UNIQUE NONCLUSTERED INDEX [AK_Document_DocumentLevel_DocumentNode] ON [Production].[Document]( - [DocumentLevel] ASC, - [DocumentNode] ASC -) \ No newline at end of file +CREATE UNIQUE NONCLUSTERED INDEX [UQ__Document__F73921F7C5112C2E] ON [Production].[Document]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Product.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Product.sql index dbc9cca..aa10d6c 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Production.Product.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.Product.sql @@ -29,18 +29,6 @@ CREATE TABLE [Production].[Product] CONSTRAINT [PK_Product_ProductID] PRIMARY KEY CLUSTERED ([ProductID] ASC) ) -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_ProductModel_ProductModelID]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) -BEGIN - ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [Production].[ProductModel] ([ProductModelID]) - ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_ProductModel_ProductModelID] -END - -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_ProductSubcategory_ProductSubcategoryID]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) -BEGIN - ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_ProductSubcategory_ProductSubcategoryID] FOREIGN KEY ([ProductSubcategoryID]) REFERENCES [Production].[ProductSubcategory] ([ProductSubcategoryID]) - ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_ProductSubcategory_ProductSubcategoryID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_UnitMeasure_SizeUnitMeasureCode]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) BEGIN ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_UnitMeasure_SizeUnitMeasureCode] FOREIGN KEY ([SizeUnitMeasureCode]) REFERENCES [Production].[UnitMeasure] ([UnitMeasureCode]) @@ -53,11 +41,23 @@ BEGIN ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_UnitMeasure_WeightUnitMeasureCode] END -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Product]') AND name = 'AK_Product_ProductNumber') -CREATE UNIQUE NONCLUSTERED INDEX [AK_Product_ProductNumber] ON [Production].[Product]([ProductNumber] ASC) +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_ProductModel_ProductModelID]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) +BEGIN + ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [Production].[ProductModel] ([ProductModelID]) + ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_ProductModel_ProductModelID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_Product_ProductSubcategory_ProductSubcategoryID]') AND parent_object_id = OBJECT_ID('[Production].[Product]')) +BEGIN + ALTER TABLE [Production].[Product] WITH CHECK ADD CONSTRAINT [FK_Product_ProductSubcategory_ProductSubcategoryID] FOREIGN KEY ([ProductSubcategoryID]) REFERENCES [Production].[ProductSubcategory] ([ProductSubcategoryID]) + ALTER TABLE [Production].[Product] CHECK CONSTRAINT [FK_Product_ProductSubcategory_ProductSubcategoryID] +END IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Product]') AND name = 'AK_Product_Name') CREATE UNIQUE NONCLUSTERED INDEX [AK_Product_Name] ON [Production].[Product]([Name] ASC) +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Product]') AND name = 'AK_Product_ProductNumber') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Product_ProductNumber] ON [Production].[Product]([ProductNumber] ASC) + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[Product]') AND name = 'AK_Product_rowguid') CREATE UNIQUE NONCLUSTERED INDEX [AK_Product_rowguid] ON [Production].[Product]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelIllustration.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelIllustration.sql index 2a082a2..dd575ca 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelIllustration.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelIllustration.sql @@ -11,14 +11,14 @@ CREATE TABLE [Production].[ProductModelIllustration] ) ) -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelIllustration_Illustration_IllustrationID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelIllustration]')) -BEGIN - ALTER TABLE [Production].[ProductModelIllustration] WITH CHECK ADD CONSTRAINT [FK_ProductModelIllustration_Illustration_IllustrationID] FOREIGN KEY ([IllustrationID]) REFERENCES [Production].[Illustration] ([IllustrationID]) - ALTER TABLE [Production].[ProductModelIllustration] CHECK CONSTRAINT [FK_ProductModelIllustration_Illustration_IllustrationID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelIllustration_ProductModel_ProductModelID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelIllustration]')) BEGIN ALTER TABLE [Production].[ProductModelIllustration] WITH CHECK ADD CONSTRAINT [FK_ProductModelIllustration_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [Production].[ProductModel] ([ProductModelID]) ALTER TABLE [Production].[ProductModelIllustration] CHECK CONSTRAINT [FK_ProductModelIllustration_ProductModel_ProductModelID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelIllustration_Illustration_IllustrationID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelIllustration]')) +BEGIN + ALTER TABLE [Production].[ProductModelIllustration] WITH CHECK ADD CONSTRAINT [FK_ProductModelIllustration_Illustration_IllustrationID] FOREIGN KEY ([IllustrationID]) REFERENCES [Production].[Illustration] ([IllustrationID]) + ALTER TABLE [Production].[ProductModelIllustration] CHECK CONSTRAINT [FK_ProductModelIllustration_Illustration_IllustrationID] END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql index a5c5b62..a9d5189 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql @@ -19,14 +19,14 @@ BEGIN ALTER TABLE [Production].[ProductModelProductDescriptionCulture] CHECK CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductDescription_ProductDescriptionID] END -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelProductDescriptionCulture]')) -BEGIN - ALTER TABLE [Production].[ProductModelProductDescriptionCulture] WITH CHECK ADD CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [Production].[ProductModel] ([ProductModelID]) - ALTER TABLE [Production].[ProductModelProductDescriptionCulture] CHECK CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelProductDescriptionCulture_Culture_CultureID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelProductDescriptionCulture]')) BEGIN ALTER TABLE [Production].[ProductModelProductDescriptionCulture] WITH CHECK ADD CONSTRAINT [FK_ProductModelProductDescriptionCulture_Culture_CultureID] FOREIGN KEY ([CultureID]) REFERENCES [Production].[Culture] ([CultureID]) ALTER TABLE [Production].[ProductModelProductDescriptionCulture] CHECK CONSTRAINT [FK_ProductModelProductDescriptionCulture_Culture_CultureID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Production].[FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID]') AND parent_object_id = OBJECT_ID('[Production].[ProductModelProductDescriptionCulture]')) +BEGIN + ALTER TABLE [Production].[ProductModelProductDescriptionCulture] WITH CHECK ADD CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID] FOREIGN KEY ([ProductModelID]) REFERENCES [Production].[ProductModel] ([ProductModelID]) + ALTER TABLE [Production].[ProductModelProductDescriptionCulture] CHECK CONSTRAINT [FK_ProductModelProductDescriptionCulture_ProductModel_ProductModelID] END \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrder.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrder.sql index b47daa5..9d16195 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrder.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Production.WorkOrder.sql @@ -26,8 +26,8 @@ BEGIN ALTER TABLE [Production].[WorkOrder] CHECK CONSTRAINT [FK_WorkOrder_ScrapReason_ScrapReasonID] END -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[WorkOrder]') AND name = 'IX_WorkOrder_ScrapReasonID') -CREATE NONCLUSTERED INDEX [IX_WorkOrder_ScrapReasonID] ON [Production].[WorkOrder]([ScrapReasonID] ASC) - IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[WorkOrder]') AND name = 'IX_WorkOrder_ProductID') -CREATE NONCLUSTERED INDEX [IX_WorkOrder_ProductID] ON [Production].[WorkOrder]([ProductID] ASC) \ No newline at end of file +CREATE NONCLUSTERED INDEX [IX_WorkOrder_ProductID] ON [Production].[WorkOrder]([ProductID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Production].[WorkOrder]') AND name = 'IX_WorkOrder_ScrapReasonID') +CREATE NONCLUSTERED INDEX [IX_WorkOrder_ScrapReasonID] ON [Production].[WorkOrder]([ScrapReasonID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ProductVendor.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ProductVendor.sql index 0f323bd..17038c4 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ProductVendor.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.ProductVendor.sql @@ -37,8 +37,8 @@ BEGIN ALTER TABLE [Purchasing].[ProductVendor] CHECK CONSTRAINT [FK_ProductVendor_Vendor_BusinessEntityID] END -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[ProductVendor]') AND name = 'IX_ProductVendor_UnitMeasureCode') -CREATE NONCLUSTERED INDEX [IX_ProductVendor_UnitMeasureCode] ON [Purchasing].[ProductVendor]([UnitMeasureCode] ASC) - IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[ProductVendor]') AND name = 'IX_ProductVendor_BusinessEntityID') -CREATE NONCLUSTERED INDEX [IX_ProductVendor_BusinessEntityID] ON [Purchasing].[ProductVendor]([BusinessEntityID] ASC) \ No newline at end of file +CREATE NONCLUSTERED INDEX [IX_ProductVendor_BusinessEntityID] ON [Purchasing].[ProductVendor]([BusinessEntityID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[ProductVendor]') AND name = 'IX_ProductVendor_UnitMeasureCode') +CREATE NONCLUSTERED INDEX [IX_ProductVendor_UnitMeasureCode] ON [Purchasing].[ProductVendor]([UnitMeasureCode] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderHeader.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderHeader.sql index 4d1d3d0..cb24ed0 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderHeader.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Purchasing.PurchaseOrderHeader.sql @@ -17,10 +17,10 @@ CREATE TABLE [Purchasing].[PurchaseOrderHeader] CONSTRAINT [PK_PurchaseOrderHeader_PurchaseOrderID] PRIMARY KEY CLUSTERED ([PurchaseOrderID] ASC) ) -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderHeader_ShipMethod_ShipMethodID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]')) +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderHeader_Employee_EmployeeID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]')) BEGIN - ALTER TABLE [Purchasing].[PurchaseOrderHeader] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY ([ShipMethodID]) REFERENCES [Purchasing].[ShipMethod] ([ShipMethodID]) - ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_ShipMethod_ShipMethodID] + ALTER TABLE [Purchasing].[PurchaseOrderHeader] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderHeader_Employee_EmployeeID] FOREIGN KEY ([EmployeeID]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) + ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_Employee_EmployeeID] END IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderHeader_Vendor_VendorID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]')) @@ -29,14 +29,14 @@ BEGIN ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_Vendor_VendorID] END -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderHeader_Employee_EmployeeID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]')) +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Purchasing].[FK_PurchaseOrderHeader_ShipMethod_ShipMethodID]') AND parent_object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]')) BEGIN - ALTER TABLE [Purchasing].[PurchaseOrderHeader] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderHeader_Employee_EmployeeID] FOREIGN KEY ([EmployeeID]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) - ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_Employee_EmployeeID] + ALTER TABLE [Purchasing].[PurchaseOrderHeader] WITH CHECK ADD CONSTRAINT [FK_PurchaseOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY ([ShipMethodID]) REFERENCES [Purchasing].[ShipMethod] ([ShipMethodID]) + ALTER TABLE [Purchasing].[PurchaseOrderHeader] CHECK CONSTRAINT [FK_PurchaseOrderHeader_ShipMethod_ShipMethodID] END -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]') AND name = 'IX_PurchaseOrderHeader_VendorID') -CREATE NONCLUSTERED INDEX [IX_PurchaseOrderHeader_VendorID] ON [Purchasing].[PurchaseOrderHeader]([VendorID] ASC) - IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]') AND name = 'IX_PurchaseOrderHeader_EmployeeID') -CREATE NONCLUSTERED INDEX [IX_PurchaseOrderHeader_EmployeeID] ON [Purchasing].[PurchaseOrderHeader]([EmployeeID] ASC) \ No newline at end of file +CREATE NONCLUSTERED INDEX [IX_PurchaseOrderHeader_EmployeeID] ON [Purchasing].[PurchaseOrderHeader]([EmployeeID] ASC) + +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Purchasing].[PurchaseOrderHeader]') AND name = 'IX_PurchaseOrderHeader_VendorID') +CREATE NONCLUSTERED INDEX [IX_PurchaseOrderHeader_VendorID] ON [Purchasing].[PurchaseOrderHeader]([VendorID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Customer.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Customer.sql index 731858e..01b2fef 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Customer.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Customer.sql @@ -17,23 +17,23 @@ BEGIN ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_Person_PersonID] END -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Customer_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[Customer]')) -BEGIN - ALTER TABLE [Sales].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) - ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Customer_Store_StoreID]') AND parent_object_id = OBJECT_ID('[Sales].[Customer]')) BEGIN ALTER TABLE [Sales].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_Store_StoreID] FOREIGN KEY ([StoreID]) REFERENCES [Sales].[Store] ([BusinessEntityID]) ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_Store_StoreID] END -IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Customer]') AND name = 'AK_Customer_rowguid') -CREATE UNIQUE NONCLUSTERED INDEX [AK_Customer_rowguid] ON [Sales].[Customer]([rowguid] ASC) +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Customer_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[Customer]')) +BEGIN + ALTER TABLE [Sales].[Customer] WITH CHECK ADD CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Sales].[Customer] CHECK CONSTRAINT [FK_Customer_SalesTerritory_TerritoryID] +END IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Customer]') AND name = 'AK_Customer_AccountNumber') CREATE UNIQUE NONCLUSTERED INDEX [AK_Customer_AccountNumber] ON [Sales].[Customer]([AccountNumber] ASC) +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Customer]') AND name = 'AK_Customer_rowguid') +CREATE UNIQUE NONCLUSTERED INDEX [AK_Customer_rowguid] ON [Sales].[Customer]([rowguid] ASC) + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Customer]') AND name = 'IX_Customer_TerritoryID') CREATE NONCLUSTERED INDEX [IX_Customer_TerritoryID] ON [Sales].[Customer]([TerritoryID] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderDetail.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderDetail.sql index ac65785..ce1ddeb 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderDetail.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderDetail.sql @@ -19,6 +19,12 @@ CREATE TABLE [Sales].[SalesOrderDetail] ) ) +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderDetail]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderDetail] WITH CHECK ADD CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID] FOREIGN KEY ([SalesOrderID]) REFERENCES [Sales].[SalesOrderHeader] ([SalesOrderID]) ON DELETE CASCADE + ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID] +END + IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderDetail]')) BEGIN ALTER TABLE [Sales].[SalesOrderDetail] WITH CHECK ADD CONSTRAINT [FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID] FOREIGN KEY ([SpecialOfferID]) REFERENCES [Sales].[SpecialOfferProduct] ([SpecialOfferID]) @@ -31,12 +37,6 @@ BEGIN ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [FK_SalesOrderDetail_SpecialOfferProduct_SpecialOfferIDProductID] END -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderDetail]')) -BEGIN - ALTER TABLE [Sales].[SalesOrderDetail] WITH CHECK ADD CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID] FOREIGN KEY ([SalesOrderID]) REFERENCES [Sales].[SalesOrderHeader] ([SalesOrderID]) ON DELETE CASCADE - ALTER TABLE [Sales].[SalesOrderDetail] CHECK CONSTRAINT [FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID] -END - IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesOrderDetail]') AND name = 'AK_SalesOrderDetail_rowguid') CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesOrderDetail_rowguid] ON [Sales].[SalesOrderDetail]([rowguid] ASC) diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeader.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeader.sql index 6307348..b9de970 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeader.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesOrderHeader.sql @@ -30,24 +30,6 @@ CREATE TABLE [Sales].[SalesOrderHeader] CONSTRAINT [PK_SalesOrderHeader_SalesOrderID] PRIMARY KEY CLUSTERED ([SalesOrderID] ASC) ) -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_SalesPerson_SalesPersonID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) -BEGIN - ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] FOREIGN KEY ([SalesPersonID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID]) - ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] -END - -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) -BEGIN - ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) - ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] -END - -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_ShipMethod_ShipMethodID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) -BEGIN - ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY ([ShipMethodID]) REFERENCES [Purchasing].[ShipMethod] ([ShipMethodID]) - ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_Address_BillToAddressID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) BEGIN ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_Address_BillToAddressID] FOREIGN KEY ([BillToAddressID]) REFERENCES [Person].[Address] ([AddressID]) @@ -78,6 +60,24 @@ BEGIN ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_Customer_CustomerID] END +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_SalesPerson_SalesPersonID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] FOREIGN KEY ([SalesPersonID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_SalesPerson_SalesPersonID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_ShipMethod_ShipMethodID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] FOREIGN KEY ([ShipMethodID]) REFERENCES [Purchasing].[ShipMethod] ([ShipMethodID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_ShipMethod_ShipMethodID] +END + +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesOrderHeader_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesOrderHeader]')) +BEGIN + ALTER TABLE [Sales].[SalesOrderHeader] WITH CHECK ADD CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Sales].[SalesOrderHeader] CHECK CONSTRAINT [FK_SalesOrderHeader_SalesTerritory_TerritoryID] +END + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesOrderHeader]') AND name = 'AK_SalesOrderHeader_rowguid') CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesOrderHeader_rowguid] ON [Sales].[SalesOrderHeader]([rowguid] ASC) diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPerson.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPerson.sql index 2e6b54d..a59a458 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPerson.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.SalesPerson.sql @@ -13,17 +13,17 @@ CREATE TABLE [Sales].[SalesPerson] CONSTRAINT [PK_SalesPerson_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) ) -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesPerson_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesPerson]')) -BEGIN - ALTER TABLE [Sales].[SalesPerson] WITH CHECK ADD CONSTRAINT [FK_SalesPerson_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) - ALTER TABLE [Sales].[SalesPerson] CHECK CONSTRAINT [FK_SalesPerson_SalesTerritory_TerritoryID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesPerson_Employee_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesPerson]')) BEGIN ALTER TABLE [Sales].[SalesPerson] WITH CHECK ADD CONSTRAINT [FK_SalesPerson_Employee_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [HumanResources].[Employee] ([BusinessEntityID]) ALTER TABLE [Sales].[SalesPerson] CHECK CONSTRAINT [FK_SalesPerson_Employee_BusinessEntityID] END +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_SalesPerson_SalesTerritory_TerritoryID]') AND parent_object_id = OBJECT_ID('[Sales].[SalesPerson]')) +BEGIN + ALTER TABLE [Sales].[SalesPerson] WITH CHECK ADD CONSTRAINT [FK_SalesPerson_SalesTerritory_TerritoryID] FOREIGN KEY ([TerritoryID]) REFERENCES [Sales].[SalesTerritory] ([TerritoryID]) + ALTER TABLE [Sales].[SalesPerson] CHECK CONSTRAINT [FK_SalesPerson_SalesTerritory_TerritoryID] +END + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[SalesPerson]') AND name = 'AK_SalesPerson_rowguid') CREATE UNIQUE NONCLUSTERED INDEX [AK_SalesPerson_rowguid] ON [Sales].[SalesPerson]([rowguid] ASC) \ No newline at end of file diff --git a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Store.sql b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Store.sql index 0f71487..d75e0fd 100644 --- a/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Store.sql +++ b/snapshots/AdventureWorks2017/_sql-database/tables/Sales.Store.sql @@ -10,18 +10,18 @@ CREATE TABLE [Sales].[Store] CONSTRAINT [PK_Store_BusinessEntityID] PRIMARY KEY CLUSTERED ([BusinessEntityID] ASC) ) -IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Store_SalesPerson_SalesPersonID]') AND parent_object_id = OBJECT_ID('[Sales].[Store]')) -BEGIN - ALTER TABLE [Sales].[Store] WITH CHECK ADD CONSTRAINT [FK_Store_SalesPerson_SalesPersonID] FOREIGN KEY ([SalesPersonID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID]) - ALTER TABLE [Sales].[Store] CHECK CONSTRAINT [FK_Store_SalesPerson_SalesPersonID] -END - IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Store_BusinessEntity_BusinessEntityID]') AND parent_object_id = OBJECT_ID('[Sales].[Store]')) BEGIN ALTER TABLE [Sales].[Store] WITH CHECK ADD CONSTRAINT [FK_Store_BusinessEntity_BusinessEntityID] FOREIGN KEY ([BusinessEntityID]) REFERENCES [Person].[BusinessEntity] ([BusinessEntityID]) ALTER TABLE [Sales].[Store] CHECK CONSTRAINT [FK_Store_BusinessEntity_BusinessEntityID] END +IF NOT EXISTS (SELECT 1 FROM sys.foreign_keys WHERE object_id = OBJECT_ID('[Sales].[FK_Store_SalesPerson_SalesPersonID]') AND parent_object_id = OBJECT_ID('[Sales].[Store]')) +BEGIN + ALTER TABLE [Sales].[Store] WITH CHECK ADD CONSTRAINT [FK_Store_SalesPerson_SalesPersonID] FOREIGN KEY ([SalesPersonID]) REFERENCES [Sales].[SalesPerson] ([BusinessEntityID]) + ALTER TABLE [Sales].[Store] CHECK CONSTRAINT [FK_Store_SalesPerson_SalesPersonID] +END + IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('[Sales].[Store]') AND name = 'AK_Store_rowguid') CREATE UNIQUE NONCLUSTERED INDEX [AK_Store_rowguid] ON [Sales].[Store]([rowguid] ASC) diff --git a/src/queries/mssql.ts b/src/queries/mssql.ts index 6d28f8b..3224559 100644 --- a/src/queries/mssql.ts +++ b/src/queries/mssql.ts @@ -62,6 +62,8 @@ export const columnsRead = ` c.is_identity = 1 AND c.object_id = ic.object_id AND c.column_id = ic.column_id + ORDER BY + c.object_id, c.column_id `; /** @@ -116,6 +118,8 @@ export const foreignKeysRead = ` JOIN sys.foreign_keys fk ON fk.object_id = k.constraint_object_id JOIN sys.objects ro ON ro.object_id = fk.referenced_object_id JOIN sys.objects po ON po.object_id = fk.parent_object_id + ORDER BY + po.object_id, k.constraint_object_id `; /** @@ -144,8 +148,8 @@ export const indexesRead = ` ORDER BY ro.schema_id, ro.name, - ic.key_ordinal, - c.object_id + i.name, + ic.key_ordinal `; /** From 234c9cdbc69c3205328f6d446f52a80cb99a7530 Mon Sep 17 00:00:00 2001 From: Marco von Ballmoos Date: Wed, 3 Feb 2021 12:52:36 +0100 Subject: [PATCH 3/5] Update AppVeyor tests to match Docker tests --- appveyor/index.spec.ts | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/appveyor/index.spec.ts b/appveyor/index.spec.ts index 84952ec..808e850 100644 --- a/appveyor/index.spec.ts +++ b/appveyor/index.spec.ts @@ -1,8 +1,35 @@ -const snapshot = require('../snapshots/AdventureWorks2017.json'); -const cache = require('../_sql-database/cache.json'); +import { readFileSync, statSync } from 'fs-extra'; +import { glob } from 'glob'; describe('appveyor', () => { - it('cache should match snapshot', () => { - expect(cache).toEqual(snapshot); + it('file contents should match snapshots', () => { + const getAllFilenames = (folder: string): string[] => { + return glob.sync(folder + '**/*'); + }; + + const snapshots = getAllFilenames( + 'snapshots/AdventureWorks2017/_sql-database/' + ); + const results = getAllFilenames('_sql-database/'); + + // Just in case the glob results aren't in a predictable order + snapshots.sort(); + results.sort(); + + expect(snapshots.length).toEqual(results.length); + + snapshots.map((snapshot, index) => { + const result = results[index]; + + expect(snapshot).toContain(result); + + const stat = statSync(result); + if (stat.isFile()) { + const resultContent = readFileSync(result).toString(); + const snapshotContent = readFileSync(snapshot).toString(); + + expect(resultContent).toEqual(snapshotContent); + } + }); }); }); From fd36f93bbdedf5585cc0bf119b830dbc6ed7d537 Mon Sep 17 00:00:00 2001 From: Marco von Ballmoos Date: Wed, 3 Feb 2021 16:02:41 +0100 Subject: [PATCH 4/5] Restore Appveyor tests to original --- appveyor/index.spec.ts | 35 +------- snapshots/AdventureWorks2017.json | 143 ++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 31 deletions(-) create mode 100644 snapshots/AdventureWorks2017.json diff --git a/appveyor/index.spec.ts b/appveyor/index.spec.ts index 808e850..84952ec 100644 --- a/appveyor/index.spec.ts +++ b/appveyor/index.spec.ts @@ -1,35 +1,8 @@ -import { readFileSync, statSync } from 'fs-extra'; -import { glob } from 'glob'; +const snapshot = require('../snapshots/AdventureWorks2017.json'); +const cache = require('../_sql-database/cache.json'); describe('appveyor', () => { - it('file contents should match snapshots', () => { - const getAllFilenames = (folder: string): string[] => { - return glob.sync(folder + '**/*'); - }; - - const snapshots = getAllFilenames( - 'snapshots/AdventureWorks2017/_sql-database/' - ); - const results = getAllFilenames('_sql-database/'); - - // Just in case the glob results aren't in a predictable order - snapshots.sort(); - results.sort(); - - expect(snapshots.length).toEqual(results.length); - - snapshots.map((snapshot, index) => { - const result = results[index]; - - expect(snapshot).toContain(result); - - const stat = statSync(result); - if (stat.isFile()) { - const resultContent = readFileSync(result).toString(); - const snapshotContent = readFileSync(snapshot).toString(); - - expect(resultContent).toEqual(snapshotContent); - } - }); + it('cache should match snapshot', () => { + expect(cache).toEqual(snapshot); }); }); diff --git a/snapshots/AdventureWorks2017.json b/snapshots/AdventureWorks2017.json new file mode 100644 index 0000000..f227909 --- /dev/null +++ b/snapshots/AdventureWorks2017.json @@ -0,0 +1,143 @@ +{ + "files": { + "./_sql-database/schemas/dbo.sql": "ab32ab028d124a45f5c4d3c148eaebadb0738cf8", + "./_sql-database/schemas/HumanResources.sql": "bd95f0305ee87484bc9a8a9b6176ade02e70ed11", + "./_sql-database/schemas/Person.sql": "8e55687d62e5e537bd9519ff96a7877db009f19c", + "./_sql-database/schemas/Production.sql": "ddcaa67a5bf9bdf64a67be9191fcf26f5610769e", + "./_sql-database/schemas/Purchasing.sql": "b1a26eaff02db9f89b88a6960f35c973447505cf", + "./_sql-database/schemas/Sales.sql": "9329154240adedb11b53eccc910cafe83b6fbd1f", + "./_sql-database/stored-procedures/dbo.uspGetBillOfMaterials.sql": "0cc00ba82b124428ac91ebc1dc05558d606fbb7f", + "./_sql-database/stored-procedures/dbo.uspGetEmployeeManagers.sql": "218b4be7b510a2c838a1c1daad658b48ef1069d5", + "./_sql-database/stored-procedures/dbo.uspGetManagerEmployees.sql": "b63e47f2dff7c80ccfd0a544ca343ca2a2de5544", + "./_sql-database/stored-procedures/dbo.uspGetWhereUsedProductID.sql": "3a99561f6f1873cbdd9c842d66055ef58462e4c0", + "./_sql-database/stored-procedures/dbo.uspLogError.sql": "838fecb15ec6e45197803b652a22d9a1046124c7", + "./_sql-database/stored-procedures/dbo.uspPrintError.sql": "71bf88dcf933ed08387f73306ab3907a489e4f22", + "./_sql-database/stored-procedures/dbo.uspSearchCandidateResumes.sql": "c4a5f35c64311358d4113d1ac226d0a783141930", + "./_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeHireInfo.sql": "432749be8995c284104c3970b5a7ed0571713dbd", + "./_sql-database/stored-procedures/HumanResources.uspUpdateEmployeeLogin.sql": "a614a10747ce76b0b655837133d8fddaf5efba3f", + "./_sql-database/stored-procedures/HumanResources.uspUpdateEmployeePersonalInfo.sql": "ad9e9ab3e22e8053ace33e69f77def6ef555a039", + "./_sql-database/views/Person.vAdditionalContactInfo.sql": "b83438a64db91e3aa8674646d279af1b06fc34a9", + "./_sql-database/views/HumanResources.vEmployee.sql": "7c6f1ada004551d5c74ee966904d8333ac01c0b2", + "./_sql-database/views/HumanResources.vEmployeeDepartment.sql": "3a22df2651bbb36691096e40d5488e7d67a428f3", + "./_sql-database/views/HumanResources.vEmployeeDepartmentHistory.sql": "ad108190c5c840a8e131067b3a6290822418686d", + "./_sql-database/views/Sales.vIndividualCustomer.sql": "3ac79fd6538a57100ae25df79b62bd7a9bdb04e1", + "./_sql-database/views/HumanResources.vJobCandidate.sql": "7eb4680596d0b4052fc089111e9174ef0677ae03", + "./_sql-database/views/HumanResources.vJobCandidateEducation.sql": "c1ad5033a546f9435e736f660a766d6ca517f26c", + "./_sql-database/views/HumanResources.vJobCandidateEmployment.sql": "0ea15dcedeb8fc13734aa4786d94c63b4ec4dd13", + "./_sql-database/views/Sales.vPersonDemographics.sql": "6c2fb36428ca6b091f7f6e78d232e881bd784d64", + "./_sql-database/views/Production.vProductAndDescription.sql": "14915893e8c2fabe182942fee1f64f5eed5eea6b", + "./_sql-database/views/Production.vProductModelCatalogDescription.sql": "518931fcc28566ff2b659c1aecead08c8344294f", + "./_sql-database/views/Production.vProductModelInstructions.sql": "76f224bc7757ffd0100b9f8936601760b239df07", + "./_sql-database/views/Sales.vSalesPerson.sql": "037edfed2f6f286113aa49429c2ea46cdc9a8532", + "./_sql-database/views/Sales.vSalesPersonSalesByFiscalYears.sql": "08f1cf832612ce4ad2aea277b3545059fc903401", + "./_sql-database/views/Person.vStateProvinceCountryRegion.sql": "79c71e00f6a08115314b992fc4453e42d84c7cf7", + "./_sql-database/views/Sales.vStoreWithAddresses.sql": "a8e74cd95afd84b908daff277efaa1cafcc6130d", + "./_sql-database/views/Sales.vStoreWithContacts.sql": "0352d850146aa2168cfcbda8bff3eee3e34b5f8c", + "./_sql-database/views/Sales.vStoreWithDemographics.sql": "77ce7090441d4c81c110c8f73bac6550d405fa7d", + "./_sql-database/views/Purchasing.vVendorWithAddresses.sql": "19d027ce6d9c4f4e1829950602591bf536ab3dcf", + "./_sql-database/views/Purchasing.vVendorWithContacts.sql": "00d9b8402624bd8680fc2d475e91c20f228693bc", + "./_sql-database/functions/dbo.ufnGetAccountingEndDate.sql": "fe57d91d8a800862ae73a4c5163f5dd3409f1d63", + "./_sql-database/functions/dbo.ufnGetAccountingStartDate.sql": "169fd6daa2164db963470e844889a441f8cb778e", + "./_sql-database/functions/dbo.ufnGetContactInformation.sql": "33213843f20b7401d9f0ba579f75db327b417c35", + "./_sql-database/functions/dbo.ufnGetDocumentStatusText.sql": "fcc5e1c2313bff7df571ee65680364eff13e7b7e", + "./_sql-database/functions/dbo.ufnGetProductDealerPrice.sql": "a6a08d34ea4be9b177de0b6e0a247ffe3b751f57", + "./_sql-database/functions/dbo.ufnGetProductListPrice.sql": "c1574f35ae403181c47c6979ce550d10791677d7", + "./_sql-database/functions/dbo.ufnGetProductStandardCost.sql": "0dfb45fff6f317a665d00b52eda2eb10563c8bf4", + "./_sql-database/functions/dbo.ufnGetPurchaseOrderStatusText.sql": "b495457c121389dadd8b9ee89aa247a0fa2f2890", + "./_sql-database/functions/dbo.ufnGetSalesOrderStatusText.sql": "80da881ebc6a96fcdef85d2171f41db1bdb917eb", + "./_sql-database/functions/dbo.ufnGetStock.sql": "27cc114a95bbdcfb9d5665a48d98f61561b8a2b6", + "./_sql-database/functions/dbo.ufnLeadingZeros.sql": "47ccc6e15ba6110a0f8806068674ac721195e752", + "./_sql-database/triggers/HumanResources.dEmployee.sql": "1dc87b4bf7c91a029d8a752c9d90bf84fa6ba7da", + "./_sql-database/triggers/Purchasing.dVendor.sql": "167b9ad6d1122f4e1c3dcb4dd652f1cc6a391143", + "./_sql-database/triggers/Sales.iduSalesOrderDetail.sql": "f8c5bc6596ce6ddb8be8fa89b39f5a9041e5e899", + "./_sql-database/triggers/Purchasing.iPurchaseOrderDetail.sql": "8e2f85e50cd5a3e7122b203c55cb9a515bba85df", + "./_sql-database/triggers/Person.iuPerson.sql": "940660a7e53f984389ad4ad0746f7d21e933084d", + "./_sql-database/triggers/Production.iWorkOrder.sql": "7c087ed26dcfad01fcc39f1d8cf579d97ad9f891", + "./_sql-database/triggers/Purchasing.uPurchaseOrderDetail.sql": "05d927aecfd03e2aa8c41b9a5a7af23387400a9f", + "./_sql-database/triggers/Purchasing.uPurchaseOrderHeader.sql": "1ead0a3e5d39e5a35be293ba730af183e817619f", + "./_sql-database/triggers/Sales.uSalesOrderHeader.sql": "dff5943e51d3b3003961d90557b37e6c8bda822a", + "./_sql-database/triggers/Production.uWorkOrder.sql": "f43cfdc4c456b6e846d515ade5295682d4ec3fca", + "./_sql-database/tables/dbo.AWBuildVersion.sql": "29c80eba0303f1a759266e3cf4c5b330bf28bb7b", + "./_sql-database/tables/dbo.DatabaseLog.sql": "9b20616aecea60d1132431f20dce0fde9afb31de", + "./_sql-database/tables/dbo.ErrorLog.sql": "6c739cf6b1b1aa3961fe170e7d0a0ae923231dc6", + "./_sql-database/tables/HumanResources.Department.sql": "4bf0595e675d1c71d990a77fc33d68c396b0d241", + "./_sql-database/tables/HumanResources.Employee.sql": "efb72f408a7abffb1f530000d5dcf5a2ff975df6", + "./_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql": "ef90daec320d2041e876901451e2eb67b509e014", + "./_sql-database/tables/HumanResources.EmployeePayHistory.sql": "e678293368b54c34b83cfbdd5ed3dbedc44abbe8", + "./_sql-database/tables/HumanResources.JobCandidate.sql": "dd7d9e12a1ae830f413c842bbde6722060272232", + "./_sql-database/tables/HumanResources.Shift.sql": "5412bee432ceac402b6fd77c6ecf87aa625bb38f", + "./_sql-database/tables/Person.Address.sql": "68680d701dff19b65fef954f220a8533b307404b", + "./_sql-database/tables/Person.AddressType.sql": "8e5a5bfbf1e131930b4140e13093f24def40241a", + "./_sql-database/tables/Person.BusinessEntity.sql": "974a196e5c5b127d95e7f85f24ac45e04117684a", + "./_sql-database/tables/Person.BusinessEntityAddress.sql": "b8f0dc95ff96356fd546f88027be3ec2549694a5", + "./_sql-database/tables/Person.BusinessEntityContact.sql": "db00db36a8c305369614ccc5b928e8597e3b1cc2", + "./_sql-database/tables/Person.ContactType.sql": "ae76fd3b5a19761acd6957cc95ef81b23bbc0458", + "./_sql-database/tables/Person.CountryRegion.sql": "6dcb67e6e55ec55854090e164562551a42eb0880", + "./_sql-database/tables/Person.EmailAddress.sql": "e94818c21608b6c16059debc16f29a09befe0f99", + "./_sql-database/tables/Person.Password.sql": "a41a0ec2d9436debe18d14814320d64039a6571f", + "./_sql-database/tables/Person.Person.sql": "adfd8437559df08805009a01a639406d7a06c614", + "./_sql-database/tables/Person.PersonPhone.sql": "aa5de40c666f70eecfc40a3067bfe01de5c8e123", + "./_sql-database/tables/Person.PhoneNumberType.sql": "b3f1927d41efef70d3163b872248fe10d59a2836", + "./_sql-database/tables/Person.StateProvince.sql": "7282919a39b919cf793bd7d5ddbc20a817aa418d", + "./_sql-database/tables/Production.BillOfMaterials.sql": "7d64a3f1e814414b679f84a4dc68f33cdf3207c2", + "./_sql-database/tables/Production.Culture.sql": "669198dedd761006eab9c95d4c2787b81af382e7", + "./_sql-database/tables/Production.Document.sql": "944cbdb6e94631a1b6a40f646b5b2dc8e19944a7", + "./_sql-database/tables/Production.Illustration.sql": "b52688b6f9683af379664a18d369ec37aa0a876b", + "./_sql-database/tables/Production.Location.sql": "3925e29b56e538ac8a809e628e10bf131e88c510", + "./_sql-database/tables/Production.Product.sql": "6772a934c8b90450de2593cff0cf08f29badd71f", + "./_sql-database/tables/Production.ProductCategory.sql": "fa70876299e8516c069f23fd487020382bb492dc", + "./_sql-database/tables/Production.ProductCostHistory.sql": "2f000a5d847fd588eb0e2731959497c116fe1766", + "./_sql-database/tables/Production.ProductDescription.sql": "53200ad11d1c00bb4c5aba33084a19f5d926610a", + "./_sql-database/tables/Production.ProductDocument.sql": "0bc9e98df535489220831e319911a3e91f37af84", + "./_sql-database/tables/Production.ProductInventory.sql": "7b7dd3eb81441b115f7dbd3653184b22d2884977", + "./_sql-database/tables/Production.ProductListPriceHistory.sql": "43a187a7830aecc7cac2c66679f65b0408812bd7", + "./_sql-database/tables/Production.ProductModel.sql": "45044e688a4df4b4145ef29b143ecacc0002d530", + "./_sql-database/tables/Production.ProductModelIllustration.sql": "a0fc4231412400c3778340c9bf591d3ef34bf9ad", + "./_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql": "f7a4713f2c77236a2791f26ecc9e0951fcd2679b", + "./_sql-database/tables/Production.ProductPhoto.sql": "d7b72993e64484f44bb8932ed4e80a353cff329a", + "./_sql-database/tables/Production.ProductProductPhoto.sql": "13698d2287e6db1afbd1bec573381e2227c6cadd", + "./_sql-database/tables/Production.ProductReview.sql": "85ef51696acecab21e2d2944f3e9af874c916a90", + "./_sql-database/tables/Production.ProductSubcategory.sql": "4a42eb49408d68c684c801fdbf609a3226e2b35b", + "./_sql-database/tables/Production.ScrapReason.sql": "938430d791716420e4b87daf758fc33b7775f31e", + "./_sql-database/tables/Production.TransactionHistory.sql": "9a09d00eb017ea790aea36dc2dabcb2f094ecf6f", + "./_sql-database/tables/Production.TransactionHistoryArchive.sql": "bfc3780f6a06bccb1855e0f80e95528729a1452a", + "./_sql-database/tables/Production.UnitMeasure.sql": "fa9d2d7d7f3765d3b4207f387a00da1017caa2c4", + "./_sql-database/tables/Production.WorkOrder.sql": "2bb7abe8a821dc1186acd6fb48089b7253d84cf5", + "./_sql-database/tables/Production.WorkOrderRouting.sql": "e8bc4941b895aed4a22d72e164149c55a36c00f1", + "./_sql-database/tables/Purchasing.ProductVendor.sql": "5679232c7304bedb60db966e179f2ef2295d98e3", + "./_sql-database/tables/Purchasing.PurchaseOrderDetail.sql": "82fe42908da1126989ce6ab95870717099922cac", + "./_sql-database/tables/Purchasing.PurchaseOrderHeader.sql": "77c76c3fdecbb4730a97a6d716eef6429478e2d5", + "./_sql-database/tables/Purchasing.ShipMethod.sql": "5394f2981ad744a8dbaee1a2c38ab71147341b51", + "./_sql-database/tables/Purchasing.Vendor.sql": "ced603aa7c11d0fb9d08382789c418063b0e0edd", + "./_sql-database/tables/Sales.CountryRegionCurrency.sql": "5622b3c4f006221a6f12a30c4939445e9d9493c6", + "./_sql-database/tables/Sales.CreditCard.sql": "f4af312a986ea206311b2cfaa53594be33932cb1", + "./_sql-database/tables/Sales.Currency.sql": "fabf07099843b49440dcd19d8ba9ed1076c8f388", + "./_sql-database/tables/Sales.CurrencyRate.sql": "5d70f9ddae2217579f68385a51e87d383e22731f", + "./_sql-database/tables/Sales.Customer.sql": "05ef02be43fece57282fcbf4620ef784e77849f5", + "./_sql-database/tables/Sales.PersonCreditCard.sql": "d7ad3c50573afa566eea8b81d82c5e3a4cf893d0", + "./_sql-database/tables/Sales.SalesOrderDetail.sql": "f49f8e7285180f1fcb72d62bcb06a220f87c461f", + "./_sql-database/tables/Sales.SalesOrderHeader.sql": "73f740194dbd318306739fa19a9e7f9b61d32268", + "./_sql-database/tables/Sales.SalesOrderHeaderSalesReason.sql": "73ae5cd408599da33244513ad3b28b7e62c5c5e9", + "./_sql-database/tables/Sales.SalesPerson.sql": "eca6c6e1784db302f77ba4174d8309f1b531ab2f", + "./_sql-database/tables/Sales.SalesPersonQuotaHistory.sql": "ef550aaf480d195cad77ee64012550d84bfc32f5", + "./_sql-database/tables/Sales.SalesReason.sql": "f96124a0f52cdd19f97c33c9509628910e3f7e04", + "./_sql-database/tables/Sales.SalesTaxRate.sql": "90a84223ccf918555e12b41dc88206dd27f11398", + "./_sql-database/tables/Sales.SalesTerritory.sql": "08b85a0de37219f9490188427a94436edaeb6c2f", + "./_sql-database/tables/Sales.SalesTerritoryHistory.sql": "2cca90321c0428b1614453f9cf821a1a37d51547", + "./_sql-database/tables/Sales.ShoppingCartItem.sql": "8206e8481d09d11bc70a9641da950455fe50e154", + "./_sql-database/tables/Sales.SpecialOffer.sql": "6a4dd953f1199f84324869d412ddc76b3783e85d", + "./_sql-database/tables/Sales.SpecialOfferProduct.sql": "d64c059bc3e4d7f6f5843f7c973d6d36f06100f9", + "./_sql-database/tables/Sales.Store.sql": "2df1f5fcafd6c96952bbebc30303810110c26d12", + "./_sql-database/types/dbo.AccountNumber.sql": "055ec65e54884c34ea6cb9e054cf550744e6ad97", + "./_sql-database/types/dbo.Flag.sql": "79e7e65d23ae0f9c89855c28e7fa12e4ea58575e", + "./_sql-database/types/dbo.NameStyle.sql": "f6c4f576d12ee8d600a657f5a803a58932b0d2d5", + "./_sql-database/types/dbo.Name.sql": "63b77aab82230cf5613ef06421329e9e0d53028e", + "./_sql-database/types/dbo.OrderNumber.sql": "b5b7741933db9658ad02816652109c4abdbaa4ca", + "./_sql-database/types/dbo.Phone.sql": "4a3b82ce5e309f44354a7694e453ca78dfae0427", + "./_sql-database/data/Person.AddressType.sql": "b4b114619f8775ab9f1a99a1a33aee3e87968456", + "./_sql-database/data/Person.ContactType.sql": "6c5a092b5a8ba36459789da8c8c1dcd09b2fe0a0", + "./_sql-database/data/Person.CountryRegion.sql": "50215c0a214eb20e6882329ff26b0a839d3e2625", + "./_sql-database/data/Person.PhoneNumberType.sql": "49561e8b0201f6d869fdc3b034332b656e02aa30", + "./_sql-database/data/Purchasing.ShipMethod.sql": "718cd7615faa5c9915b9d8bee486eb79343ab2fd" + } +} From b521f6a4ebeda80eb8ab454df83e1cc41fd15b67 Mon Sep 17 00:00:00 2001 From: Marco von Ballmoos Date: Wed, 3 Feb 2021 16:13:18 +0100 Subject: [PATCH 5/5] Update Appveyor expectation --- snapshots/AdventureWorks2017.json | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/snapshots/AdventureWorks2017.json b/snapshots/AdventureWorks2017.json index f227909..51eb17d 100644 --- a/snapshots/AdventureWorks2017.json +++ b/snapshots/AdventureWorks2017.json @@ -61,30 +61,30 @@ "./_sql-database/tables/dbo.DatabaseLog.sql": "9b20616aecea60d1132431f20dce0fde9afb31de", "./_sql-database/tables/dbo.ErrorLog.sql": "6c739cf6b1b1aa3961fe170e7d0a0ae923231dc6", "./_sql-database/tables/HumanResources.Department.sql": "4bf0595e675d1c71d990a77fc33d68c396b0d241", - "./_sql-database/tables/HumanResources.Employee.sql": "efb72f408a7abffb1f530000d5dcf5a2ff975df6", - "./_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql": "ef90daec320d2041e876901451e2eb67b509e014", + "./_sql-database/tables/HumanResources.Employee.sql": "869fd1a890dac547e5ac415b394af65bf5c2056d", + "./_sql-database/tables/HumanResources.EmployeeDepartmentHistory.sql": "2bce1ecb28ad83ec8e2fde23d5f53d1532e422c2", "./_sql-database/tables/HumanResources.EmployeePayHistory.sql": "e678293368b54c34b83cfbdd5ed3dbedc44abbe8", "./_sql-database/tables/HumanResources.JobCandidate.sql": "dd7d9e12a1ae830f413c842bbde6722060272232", "./_sql-database/tables/HumanResources.Shift.sql": "5412bee432ceac402b6fd77c6ecf87aa625bb38f", "./_sql-database/tables/Person.Address.sql": "68680d701dff19b65fef954f220a8533b307404b", - "./_sql-database/tables/Person.AddressType.sql": "8e5a5bfbf1e131930b4140e13093f24def40241a", + "./_sql-database/tables/Person.AddressType.sql": "db20ad02fef4d29f269ee2ad8f0145e9afc2cc93", "./_sql-database/tables/Person.BusinessEntity.sql": "974a196e5c5b127d95e7f85f24ac45e04117684a", "./_sql-database/tables/Person.BusinessEntityAddress.sql": "b8f0dc95ff96356fd546f88027be3ec2549694a5", - "./_sql-database/tables/Person.BusinessEntityContact.sql": "db00db36a8c305369614ccc5b928e8597e3b1cc2", + "./_sql-database/tables/Person.BusinessEntityContact.sql": "037f5207e4d2e6492cc7db5cfdfd47787cce72b5", "./_sql-database/tables/Person.ContactType.sql": "ae76fd3b5a19761acd6957cc95ef81b23bbc0458", "./_sql-database/tables/Person.CountryRegion.sql": "6dcb67e6e55ec55854090e164562551a42eb0880", "./_sql-database/tables/Person.EmailAddress.sql": "e94818c21608b6c16059debc16f29a09befe0f99", "./_sql-database/tables/Person.Password.sql": "a41a0ec2d9436debe18d14814320d64039a6571f", - "./_sql-database/tables/Person.Person.sql": "adfd8437559df08805009a01a639406d7a06c614", + "./_sql-database/tables/Person.Person.sql": "99b4a04c751bcfec7865a1d09b0e79861d5e1302", "./_sql-database/tables/Person.PersonPhone.sql": "aa5de40c666f70eecfc40a3067bfe01de5c8e123", "./_sql-database/tables/Person.PhoneNumberType.sql": "b3f1927d41efef70d3163b872248fe10d59a2836", - "./_sql-database/tables/Person.StateProvince.sql": "7282919a39b919cf793bd7d5ddbc20a817aa418d", + "./_sql-database/tables/Person.StateProvince.sql": "2b39fed01f057f53f21b420e37d3f033d214bbd9", "./_sql-database/tables/Production.BillOfMaterials.sql": "7d64a3f1e814414b679f84a4dc68f33cdf3207c2", "./_sql-database/tables/Production.Culture.sql": "669198dedd761006eab9c95d4c2787b81af382e7", - "./_sql-database/tables/Production.Document.sql": "944cbdb6e94631a1b6a40f646b5b2dc8e19944a7", + "./_sql-database/tables/Production.Document.sql": "1fc68a7ae8d1786ef7d4686bbd6798ef38c39fd5", "./_sql-database/tables/Production.Illustration.sql": "b52688b6f9683af379664a18d369ec37aa0a876b", "./_sql-database/tables/Production.Location.sql": "3925e29b56e538ac8a809e628e10bf131e88c510", - "./_sql-database/tables/Production.Product.sql": "6772a934c8b90450de2593cff0cf08f29badd71f", + "./_sql-database/tables/Production.Product.sql": "faf32aa3aa164bb969326142d0f4681a12bde5cd", "./_sql-database/tables/Production.ProductCategory.sql": "fa70876299e8516c069f23fd487020382bb492dc", "./_sql-database/tables/Production.ProductCostHistory.sql": "2f000a5d847fd588eb0e2731959497c116fe1766", "./_sql-database/tables/Production.ProductDescription.sql": "53200ad11d1c00bb4c5aba33084a19f5d926610a", @@ -92,8 +92,8 @@ "./_sql-database/tables/Production.ProductInventory.sql": "7b7dd3eb81441b115f7dbd3653184b22d2884977", "./_sql-database/tables/Production.ProductListPriceHistory.sql": "43a187a7830aecc7cac2c66679f65b0408812bd7", "./_sql-database/tables/Production.ProductModel.sql": "45044e688a4df4b4145ef29b143ecacc0002d530", - "./_sql-database/tables/Production.ProductModelIllustration.sql": "a0fc4231412400c3778340c9bf591d3ef34bf9ad", - "./_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql": "f7a4713f2c77236a2791f26ecc9e0951fcd2679b", + "./_sql-database/tables/Production.ProductModelIllustration.sql": "35702a9bfabb60d049e1b459e52ebcef6bf9f0ba", + "./_sql-database/tables/Production.ProductModelProductDescriptionCulture.sql": "18839f0e1271aaadfd042934b4c9b71355301eea", "./_sql-database/tables/Production.ProductPhoto.sql": "d7b72993e64484f44bb8932ed4e80a353cff329a", "./_sql-database/tables/Production.ProductProductPhoto.sql": "13698d2287e6db1afbd1bec573381e2227c6cadd", "./_sql-database/tables/Production.ProductReview.sql": "85ef51696acecab21e2d2944f3e9af874c916a90", @@ -102,23 +102,23 @@ "./_sql-database/tables/Production.TransactionHistory.sql": "9a09d00eb017ea790aea36dc2dabcb2f094ecf6f", "./_sql-database/tables/Production.TransactionHistoryArchive.sql": "bfc3780f6a06bccb1855e0f80e95528729a1452a", "./_sql-database/tables/Production.UnitMeasure.sql": "fa9d2d7d7f3765d3b4207f387a00da1017caa2c4", - "./_sql-database/tables/Production.WorkOrder.sql": "2bb7abe8a821dc1186acd6fb48089b7253d84cf5", + "./_sql-database/tables/Production.WorkOrder.sql": "32e16e3790fd167b5d3f95fb491d22f104df5217", "./_sql-database/tables/Production.WorkOrderRouting.sql": "e8bc4941b895aed4a22d72e164149c55a36c00f1", - "./_sql-database/tables/Purchasing.ProductVendor.sql": "5679232c7304bedb60db966e179f2ef2295d98e3", + "./_sql-database/tables/Purchasing.ProductVendor.sql": "9da691fd0de7987569c2b89bb6e50a9590f5a673", "./_sql-database/tables/Purchasing.PurchaseOrderDetail.sql": "82fe42908da1126989ce6ab95870717099922cac", - "./_sql-database/tables/Purchasing.PurchaseOrderHeader.sql": "77c76c3fdecbb4730a97a6d716eef6429478e2d5", + "./_sql-database/tables/Purchasing.PurchaseOrderHeader.sql": "613489231b1a0f1b3975c45a57269714107ccdbc", "./_sql-database/tables/Purchasing.ShipMethod.sql": "5394f2981ad744a8dbaee1a2c38ab71147341b51", "./_sql-database/tables/Purchasing.Vendor.sql": "ced603aa7c11d0fb9d08382789c418063b0e0edd", "./_sql-database/tables/Sales.CountryRegionCurrency.sql": "5622b3c4f006221a6f12a30c4939445e9d9493c6", "./_sql-database/tables/Sales.CreditCard.sql": "f4af312a986ea206311b2cfaa53594be33932cb1", "./_sql-database/tables/Sales.Currency.sql": "fabf07099843b49440dcd19d8ba9ed1076c8f388", "./_sql-database/tables/Sales.CurrencyRate.sql": "5d70f9ddae2217579f68385a51e87d383e22731f", - "./_sql-database/tables/Sales.Customer.sql": "05ef02be43fece57282fcbf4620ef784e77849f5", + "./_sql-database/tables/Sales.Customer.sql": "094a871031dca6359ee69d633e4650109e9fdc24", "./_sql-database/tables/Sales.PersonCreditCard.sql": "d7ad3c50573afa566eea8b81d82c5e3a4cf893d0", - "./_sql-database/tables/Sales.SalesOrderDetail.sql": "f49f8e7285180f1fcb72d62bcb06a220f87c461f", - "./_sql-database/tables/Sales.SalesOrderHeader.sql": "73f740194dbd318306739fa19a9e7f9b61d32268", + "./_sql-database/tables/Sales.SalesOrderDetail.sql": "224f2c8fad11bd509ac433f0f44bb78134951dc8", + "./_sql-database/tables/Sales.SalesOrderHeader.sql": "f4bc38c4b80a9f2a3ba596d2cd964e3aa5a2c9c7", "./_sql-database/tables/Sales.SalesOrderHeaderSalesReason.sql": "73ae5cd408599da33244513ad3b28b7e62c5c5e9", - "./_sql-database/tables/Sales.SalesPerson.sql": "eca6c6e1784db302f77ba4174d8309f1b531ab2f", + "./_sql-database/tables/Sales.SalesPerson.sql": "fa795cef613a61e4a054d97d52fe607bd9545d69", "./_sql-database/tables/Sales.SalesPersonQuotaHistory.sql": "ef550aaf480d195cad77ee64012550d84bfc32f5", "./_sql-database/tables/Sales.SalesReason.sql": "f96124a0f52cdd19f97c33c9509628910e3f7e04", "./_sql-database/tables/Sales.SalesTaxRate.sql": "90a84223ccf918555e12b41dc88206dd27f11398", @@ -127,7 +127,7 @@ "./_sql-database/tables/Sales.ShoppingCartItem.sql": "8206e8481d09d11bc70a9641da950455fe50e154", "./_sql-database/tables/Sales.SpecialOffer.sql": "6a4dd953f1199f84324869d412ddc76b3783e85d", "./_sql-database/tables/Sales.SpecialOfferProduct.sql": "d64c059bc3e4d7f6f5843f7c973d6d36f06100f9", - "./_sql-database/tables/Sales.Store.sql": "2df1f5fcafd6c96952bbebc30303810110c26d12", + "./_sql-database/tables/Sales.Store.sql": "e139180fa8ff7e7989842121398e4fd04405505b", "./_sql-database/types/dbo.AccountNumber.sql": "055ec65e54884c34ea6cb9e054cf550744e6ad97", "./_sql-database/types/dbo.Flag.sql": "79e7e65d23ae0f9c89855c28e7fa12e4ea58575e", "./_sql-database/types/dbo.NameStyle.sql": "f6c4f576d12ee8d600a657f5a803a58932b0d2d5",