B.ProductKey
8 | AND A.ProductSubcategoryKey = B.ProductSubcategoryKey
9 | ORDER BY A.ProductSubcategoryKey;
--------------------------------------------------------------------------------
/help_files/Chapter 3/3.2.2.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | select p.ProductKey, sum(s.SalesAmount) as Sum_of_Sales
3 | from DimProduct p
4 | left join FactInternetSales s using(ProductKey)
5 | group by p.ProductKey;
--------------------------------------------------------------------------------
/help_files/Chapter 3/create_views_ch3.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | drop view customer_email_a;
3 | create view customer_email_a as
4 | select CustomerKey, EmailAddress from DimCustomer
5 | where EmailAddress like '%a%@adventure-works.com';
6 |
7 | drop view customer_address_us;
8 | create view customer_address_us as
9 | select CustomerKey, AddressLine1, AddressLine2, C.GeographyKey from DimCustomer C
10 | join DimGeography G ON C.GeographyKey = G.GeographyKey
11 | where CountryRegionCode = 'US';
--------------------------------------------------------------------------------
/help_files/Chapter 4/4.4.1.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | SELECT a.*, b.*
3 | FROM
4 | DimCustomer a
5 | LEFT JOIN FactSurveyResponse b
6 | ON a.CustomerKey = b.CustomerKey
7 | UNION
8 | SELECT a.*, b.*
9 | FROM
10 | FactSurveyResponse b
11 | LEFT JOIN DimCustomer a
12 | ON a.CustomerKey = b.CustomerKey;
--------------------------------------------------------------------------------
/solutions/Chapter 1/Solution 1.3.txt:
--------------------------------------------------------------------------------
1 | * Script to Run for Solution
2 | .open AdventureWorks.db
3 | .mode html
4 | .output adventureworks_docs.html
5 | .headers on
6 | .tables
7 | SELECT "Number of rows in DimCurrency";
8 | SELECT count(1) from DimCurrency;
9 | SELECT "Number of rows in DimCustomer";
10 | SELECT count(1) from DimCustomer;
11 | SELECT "Number of rows in DimDate";
12 | SELECT count(1) from DimDate;
13 | SELECT "Number of rows in DimDepartmentGroup";
14 | SELECT count(1) from DimDepartmentGroup;
15 | SELECT "Number of rows in DimEmployee";
16 | SELECT count(1) from DimEmployee;
17 | SELECT "Number of rows in DimGeography";
18 | SELECT count(1) from DimGeography;
19 | SELECT "Number of rows in DimOrganization";
20 | SELECT count(1) from DimOrganization;
21 | SELECT "Number of rows in DimProduct";
22 | SELECT count(1) from DimProduct;
23 | SELECT "Number of rows in DimProductCategory";
24 | SELECT count(1) from DimProductCategory;
25 | SELECT "Number of rows in DimProductSubCategory";
26 | SELECT count(1) from DimProductSubCategory;
27 | SELECT "Number of rows in DimPromotion";
28 | SELECT count(1) from DimPromotion;
29 | SELECT "Number of rows in DimReseller";
30 | SELECT count(1) from DimReseller;
31 | SELECT "Number of rows in DimSalesReason";
32 | SELECT count(1) from DimSalesReason;
33 | SELECT "Number of rows in DimSalesTerritory";
34 | SELECT count(1) from DimSalesTerritory;
35 | SELECT "Number of rows in FactCurrencyRate";
36 | SELECT count(1) from FactCurrencyRate;
37 | SELECT "Number of rows in FactInternetSales";
38 | SELECT count(1) from FactInternetSales;
39 | SELECT "Number of rows in FactInternetSalesReason";
40 | SELECT count(1) from FactInternetSalesReason;
41 | SELECT "Number of rows in FactResellerSales";
42 | SELECT count(1) from FactResellerSales;
43 | SELECT "Number of rows in FactSurveyResponse";
44 | SELECT count(1) from FactSurveyResponse;
45 |
46 | SELECT sql from sqlite_master where name in
47 | ('DimCurrency','DimProductCategory', 'FactInternetSalesReason',
48 | 'DimCustomer','DimProductSubcategory','FactResellerSales',
49 | 'DimDate','DimPromotion','FactSurveyResponse',
50 | 'DimDepartmentGroup','DimReseller',
51 | 'DimEmployee','DimSalesReason',
52 | 'DimGeography','DimSalesTerritory',
53 | 'DimOrganization','FactCurrencyRate',
54 | 'DimProduct','FactInternetSales');
--------------------------------------------------------------------------------
/solutions/Chapter 1/adventureworks_docs.html:
--------------------------------------------------------------------------------
1 | DimCurrency DimProductCategory FactInternetSalesReason
2 | DimCustomer DimProductSubcategory FactResellerSales
3 | DimDate DimPromotion FactSurveyResponse
4 | DimDepartmentGroup DimReseller customer_address_us
5 | DimEmployee DimSalesReason customer_email_a
6 | DimGeography DimSalesTerritory vwCUSTOMER_ADDRESS
7 | DimOrganization FactCurrencyRate vwCUSTOMER_BIRTHDATE
8 | DimProduct FactInternetSales
9 | "Number of rows in DimCurrency" |
10 |
11 | Number of rows in DimCurrency |
12 |
13 | count(1) |
14 |
15 | 105 |
16 |
17 | "Number of rows in DimCustomer" |
18 |
19 | Number of rows in DimCustomer |
20 |
21 | count(1) |
22 |
23 | 18484 |
24 |
25 | "Number of rows in DimDate" |
26 |
27 | Number of rows in DimDate |
28 |
29 | count(1) |
30 |
31 | 3652 |
32 |
33 | "Number of rows in DimDepartmentGroup" |
34 |
35 | Number of rows in DimDepartmentGroup |
36 |
37 | count(1) |
38 |
39 | 7 |
40 |
41 | "Number of rows in DimEmployee" |
42 |
43 | Number of rows in DimEmployee |
44 |
45 | count(1) |
46 |
47 | 296 |
48 |
49 | "Number of rows in DimGeography" |
50 |
51 | Number of rows in DimGeography |
52 |
53 | count(1) |
54 |
55 | 655 |
56 |
57 | "Number of rows in DimOrganization" |
58 |
59 | Number of rows in DimOrganization |
60 |
61 | count(1) |
62 |
63 | 14 |
64 |
65 | "Number of rows in DimProduct" |
66 |
67 | Number of rows in DimProduct |
68 |
69 | count(1) |
70 |
71 | 606 |
72 |
73 | "Number of rows in DimProductCategory" |
74 |
75 | Number of rows in DimProductCategory |
76 |
77 | count(1) |
78 |
79 | 4 |
80 |
81 | "Number of rows in DimProductSubCategory" |
82 |
83 | Number of rows in DimProductSubCategory |
84 |
85 | count(1) |
86 |
87 | 37 |
88 |
89 | "Number of rows in DimPromotion" |
90 |
91 | Number of rows in DimPromotion |
92 |
93 | count(1) |
94 |
95 | 16 |
96 |
97 | "Number of rows in DimReseller" |
98 |
99 | Number of rows in DimReseller |
100 |
101 | count(1) |
102 |
103 | 701 |
104 |
105 | "Number of rows in DimSalesReason" |
106 |
107 | Number of rows in DimSalesReason |
108 |
109 | count(1) |
110 |
111 | 10 |
112 |
113 | "Number of rows in DimSalesTerritory" |
114 |
115 | Number of rows in DimSalesTerritory |
116 |
117 | count(1) |
118 |
119 | 11 |
120 |
121 | "Number of rows in FactCurrencyRate" |
122 |
123 | Number of rows in FactCurrencyRate |
124 |
125 | count(1) |
126 |
127 | 14264 |
128 |
129 | "Number of rows in FactInternetSales" |
130 |
131 | Number of rows in FactInternetSales |
132 |
133 | count(1) |
134 |
135 | 60398 |
136 |
137 | "Number of rows in FactInternetSalesReason" |
138 |
139 | Number of rows in FactInternetSalesReason |
140 |
141 | count(1) |
142 |
143 | 64515 |
144 |
145 | "Number of rows in FactResellerSales" |
146 |
147 | Number of rows in FactResellerSales |
148 |
149 | count(1) |
150 |
151 | 58820 |
152 |
153 | "Number of rows in FactSurveyResponse" |
154 |
155 | Number of rows in FactSurveyResponse |
156 |
157 | count(1) |
158 |
159 | 2727 |
160 |
161 | sql |
162 |
163 | CREATE TABLE DimCurrency(
164 | CurrencyKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
165 | CurrencyAlternateKey nchar(3) NOT NULL,
166 | CurrencyName nvarchar(50) NOT NULL
167 | ) |
168 |
169 | CREATE TABLE DimCustomer(
170 | CustomerKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
171 | GeographyKey int NULL,
172 | CustomerAlternateKey nvarchar(15) NOT NULL,
173 | Title nvarchar(8) NULL,
174 | FirstName nvarchar(50) NULL,
175 | MiddleName nvarchar(50) NULL,
176 | LastName nvarchar(50) NULL,
177 | NameStyle bit NULL,
178 | BirthDate date NULL,
179 | MaritalStatus nchar(1) NULL,
180 | Suffix nvarchar(10) NULL,
181 | Gender nvarchar(1) NULL,
182 | EmailAddress nvarchar(50) NULL,
183 | YearlyIncome money NULL,
184 | TotalChildren tinyint NULL,
185 | NumberChildrenAtHome tinyint NULL,
186 | EnglishEducation nvarchar(40) NULL,
187 | SpanishEducation nvarchar(40) NULL,
188 | FrenchEducation nvarchar(40) NULL,
189 | EnglishOccupation nvarchar(100) NULL,
190 | SpanishOccupation nvarchar(100) NULL,
191 | FrenchOccupation nvarchar(100) NULL,
192 | HouseOwnerFlag nchar(1) NULL,
193 | NumberCarsOwned tinyint NULL,
194 | AddressLine1 nvarchar(120) NULL,
195 | AddressLine2 nvarchar(120) NULL,
196 | Phone nvarchar(20) NULL,
197 | DateFirstPurchase date NULL,
198 | CommuteDistance nvarchar(15) NULL,
199 | FOREIGN KEY (GeographyKey) REFERENCES DimGeography(GeographyKey)
200 | ) |
201 |
202 | CREATE TABLE DimDate(
203 | DateKey int NOT NULL PRIMARY KEY,
204 | FullDateAlternateKey date NOT NULL,
205 | DayNumberOfWeek tinyint NOT NULL,
206 | EnglishDayNameOfWeek nvarchar(10) NOT NULL,
207 | SpanishDayNameOfWeek nvarchar(10) NOT NULL,
208 | FrenchDayNameOfWeek nvarchar(10) NOT NULL,
209 | DayNumberOfMonth tinyint NOT NULL,
210 | DayNumberOfYear smallint NOT NULL,
211 | WeekNumberOfYear tinyint NOT NULL,
212 | EnglishMonthName nvarchar(10) NOT NULL,
213 | SpanishMonthName nvarchar(10) NOT NULL,
214 | FrenchMonthName nvarchar(10) NOT NULL,
215 | MonthNumberOfYear tinyint NOT NULL,
216 | CalendarQuarter tinyint NOT NULL,
217 | CalendarYear smallint NOT NULL,
218 | CalendarSemester tinyint NOT NULL,
219 | FiscalQuarter tinyint NOT NULL,
220 | FiscalYear smallint NOT NULL,
221 | FiscalSemester tinyint NOT NULL
222 | ) |
223 |
224 | CREATE TABLE DimDepartmentGroup(
225 | DepartmentGroupKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
226 | ParentDepartmentGroupKey int NULL,
227 | DepartmentGroupName nvarchar(50) NULL
228 | ) |
229 |
230 | CREATE TABLE DimSalesTerritory(
231 | SalesTerritoryKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
232 | SalesTerritoryAlternateKey int NULL,
233 | SalesTerritoryRegion nvarchar(50) NOT NULL,
234 | SalesTerritoryCountry nvarchar(50) NOT NULL,
235 | SalesTerritoryGroup nvarchar(50) NULL,
236 | SalesTerritoryImage varbinary(255) NULL
237 | ) |
238 |
239 | CREATE TABLE DimEmployee(
240 | EmployeeKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
241 | ParentEmployeeKey int NULL,
242 | EmployeeNationalIDAlternateKey nvarchar(15) NULL,
243 | ParentEmployeeNationalIDAlternateKey nvarchar(15) NULL,
244 | SalesTerritoryKey int NULL,
245 | FirstName nvarchar(50) NOT NULL,
246 | LastName nvarchar(50) NOT NULL,
247 | MiddleName nvarchar(50) NULL,
248 | NameStyle bit NOT NULL,
249 | Title nvarchar(50) NULL,
250 | HireDate date NULL,
251 | BirthDate date NULL,
252 | LoginID nvarchar(256) NULL,
253 | EmailAddress nvarchar(50) NULL,
254 | Phone nvarchar(25) NULL,
255 | MaritalStatus nchar(1) NULL,
256 | EmergencyContactName nvarchar(50) NULL,
257 | EmergencyContactPhone nvarchar(25) NULL,
258 | SalariedFlag bit NULL,
259 | Gender nchar(1) NULL,
260 | PayFrequency tinyint NULL,
261 | BaseRate money NULL,
262 | VacationHours smallint NULL,
263 | SickLeaveHours smallint NULL,
264 | CurrentFlag bit NOT NULL,
265 | SalesPersonFlag bit NOT NULL,
266 | DepartmentName nvarchar(50) NULL,
267 | StartDate date NULL,
268 | EndDate date NULL,
269 | Status nvarchar(50) NULL,
270 | EmployeePhoto varbinary NULL,
271 | FOREIGN KEY (SalesTerritoryKey) REFERENCES DimSalesTerritory(SalesTerritoryKey)
272 | ) |
273 |
274 | CREATE TABLE DimGeography(
275 | GeographyKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
276 | City nvarchar(30) NULL,
277 | StateProvinceCode nvarchar(3) NULL,
278 | StateProvinceName nvarchar(50) NULL,
279 | CountryRegionCode nvarchar(3) NULL,
280 | EnglishCountryRegionName nvarchar(50) NULL,
281 | SpanishCountryRegionName nvarchar(50) NULL,
282 | FrenchCountryRegionName nvarchar(50) NULL,
283 | PostalCode nvarchar(15) NULL,
284 | SalesTerritoryKey int NULL,
285 | IpAddressLocator nvarchar(15) NULL,
286 | FOREIGN KEY (SalesTerritoryKey) REFERENCES DimSalesTerritory(SalesTerritoryKey)
287 | ) |
288 |
289 | CREATE TABLE DimOrganization(
290 | OrganizationKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
291 | ParentOrganizationKey int NULL,
292 | PercentageOfOwnership nvarchar(16) NULL,
293 | OrganizationName nvarchar(50) NULL,
294 | CurrencyKey int NULL,
295 | FOREIGN KEY (CurrencyKey) REFERENCES DimCurrency(CurrencyKey)
296 | ) |
297 |
298 | CREATE TABLE DimProductCategory(
299 | ProductCategoryKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
300 | ProductCategoryAlternateKey int NULL,
301 | EnglishProductCategoryName nvarchar(50) NOT NULL,
302 | SpanishProductCategoryName nvarchar(50) NOT NULL,
303 | FrenchProductCategoryName nvarchar(50) NOT NULL
304 | ) |
305 |
306 | CREATE TABLE DimProductSubcategory(
307 | ProductSubcategoryKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
308 | ProductSubcategoryAlternateKey int NULL,
309 | EnglishProductSubcategoryName nvarchar(50) NOT NULL,
310 | SpanishProductSubcategoryName nvarchar(50) NOT NULL,
311 | FrenchProductSubcategoryName nvarchar(50) NOT NULL,
312 | ProductCategoryKey int NULL,
313 | FOREIGN KEY (ProductCategoryKey) REFERENCES DimProductCategory(ProductCategoryKey)
314 | ) |
315 |
316 | CREATE TABLE DimProduct(
317 | ProductKey int IDENTITY(1,1) PRIMARY KEY,
318 | ProductAlternateKey nvarchar(25) NULL,
319 | ProductSubcategoryKey int NULL,
320 | WeightUnitMeasureCode nchar(3) NULL,
321 | SizeUnitMeasureCode nchar(3) NULL,
322 | EnglishProductName nvarchar(50) NOT NULL,
323 | SpanishProductName nvarchar(50) NOT NULL,
324 | FrenchProductName nvarchar(50) NOT NULL,
325 | StandardCost money NULL,
326 | FinishedGoodsFlag bit NOT NULL,
327 | Color nvarchar(15) NOT NULL,
328 | SafetyStockLevel smallint NULL,
329 | ReorderPoint smallint NULL,
330 | ListPrice money NULL,
331 | Size nvarchar(50) NULL,
332 | SizeRange nvarchar(50) NULL,
333 | Weight float NULL,
334 | DaysToManufacture int NULL,
335 | ProductLine nchar(2) NULL,
336 | DealerPrice money NULL,
337 | Class nchar(2) NULL,
338 | Style nchar(2) NULL,
339 | ModelName nvarchar(50) NULL,
340 | LargePhoto varbinary NULL,
341 | EnglishDescription nvarchar(400) NULL,
342 | FrenchDescription nvarchar(400) NULL,
343 | ChineseDescription nvarchar(400) NULL,
344 | ArabicDescription nvarchar(400) NULL,
345 | HebrewDescription nvarchar(400) NULL,
346 | ThaiDescription nvarchar(400) NULL,
347 | GermanDescription nvarchar(400) NULL,
348 | JapaneseDescription nvarchar(400) NULL,
349 | TurkishDescription nvarchar(400) NULL,
350 | StartDate datetime NULL,
351 | EndDate datetime NULL,
352 | Status nvarchar(7) NULL,
353 | FOREIGN KEY (ProductSubCategoryKey) REFERENCES DimProductSubCategory(ProductSubCategoryKey)
354 | ) |
355 |
356 | CREATE TABLE DimPromotion(
357 | PromotionKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
358 | PromotionAlternateKey int NULL,
359 | EnglishPromotionName nvarchar(255) NULL,
360 | SpanishPromotionName nvarchar(255) NULL,
361 | FrenchPromotionName nvarchar(255) NULL,
362 | DiscountPct float NULL,
363 | EnglishPromotionType nvarchar(50) NULL,
364 | SpanishPromotionType nvarchar(50) NULL,
365 | FrenchPromotionType nvarchar(50) NULL,
366 | EnglishPromotionCategory nvarchar(50) NULL,
367 | SpanishPromotionCategory nvarchar(50) NULL,
368 | FrenchPromotionCategory nvarchar(50) NULL,
369 | StartDate datetime NOT NULL,
370 | EndDate datetime NULL,
371 | MinQty int NULL,
372 | MaxQty int NULL
373 | ) |
374 |
375 | CREATE TABLE DimSalesReason(
376 | SalesReasonKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
377 | SalesReasonAlternateKey int NOT NULL,
378 | SalesReasonName nvarchar(50) NOT NULL,
379 | SalesReasonReasonType nvarchar(50) NOT NULL
380 | ) |
381 |
382 | CREATE TABLE FactCurrencyRate(
383 | CurrencyKey int NOT NULL,
384 | DateKey int NOT NULL,
385 | AverageRate float NOT NULL,
386 | EndOfDayRate float NOT NULL,
387 | Date datetime NULL,
388 | PRIMARY KEY (CurrencyKey,DateKey),
389 | FOREIGN KEY(DateKey) REFERENCES DimDate(DateKey),
390 | FOREIGN KEY(CurrencyKey) REFERENCES DimCurrency(CurrencyKey)
391 | ) |
392 |
393 | CREATE TABLE FactInternetSales(
394 | ProductKey int NOT NULL,
395 | OrderDateKey int NOT NULL,
396 | DueDateKey int NOT NULL,
397 | ShipDateKey int NOT NULL,
398 | CustomerKey int NOT NULL,
399 | PromotionKey int NOT NULL,
400 | CurrencyKey int NOT NULL,
401 | SalesTerritoryKey int NOT NULL,
402 | SalesOrderNumber nvarchar(20) NOT NULL,
403 | SalesOrderLineNumber tinyint NOT NULL,
404 | RevisionNumber tinyint NOT NULL,
405 | OrderQuantity smallint NOT NULL,
406 | UnitPrice money NOT NULL,
407 | ExtendedAmount money NOT NULL,
408 | UnitPriceDiscountPct float NOT NULL,
409 | DiscountAmount float NOT NULL,
410 | ProductStandardCost money NOT NULL,
411 | TotalProductCost money NOT NULL,
412 | SalesAmount money NOT NULL,
413 | TaxAmt money NOT NULL,
414 | Freight money NOT NULL,
415 | CarrierTrackingNumber nvarchar(25) NULL,
416 | CustomerPONumber nvarchar(25) NULL,
417 | OrderDate datetime NULL,
418 | DueDate datetime NULL,
419 | ShipDate datetime NULL,
420 | PRIMARY KEY(SalesOrderNumber,SalesOrderLineNumber),
421 | FOREIGN KEY(CurrencyKey) REFERENCES DimCurrency(CurrencyKey),
422 | FOREIGN KEY(CustomerKey) REFERENCES DimCustomer(CustomerKey),
423 | FOREIGN KEY(OrderDateKey) REFERENCES DimDate(DateKey),
424 | FOREIGN KEY(DueDateKey) REFERENCES DimDate(DateKey),
425 | FOREIGN KEY(ShipDateKey) REFERENCES DimDate(DateKey),
426 | --FOREIGN KEY(ProductKey) REFERENCES DimProduct(ProductKey)
427 | FOREIGN KEY(PromotionKey) REFERENCES DimPromotion(PromotionKey),
428 | FOREIGN KEY(SalesTerritoryKey) REFERENCES DimSalesTerritory(SalesTerritoryKey)
429 | ) |
430 |
431 | CREATE TABLE FactInternetSalesReason(
432 | SalesOrderNumber nvarchar(20) NOT NULL,
433 | SalesOrderLineNumber tinyint NOT NULL,
434 | SalesReasonKey int NOT NULL,
435 | PRIMARY KEY (SalesOrderNumber,SalesOrderLineNumber,SalesReasonKey),
436 | FOREIGN KEY(SalesOrderNumber,SalesOrderLineNumber) REFERENCES FactInternetSales(SalesOrderNumber, SalesOrderLineNumber),
437 | FOREIGN KEY(SalesReasonKey) REFERENCES DimSalesReason(SalesReasonKey)
438 | ) |
439 |
440 | CREATE TABLE FactSurveyResponse(
441 | SurveyResponseKey int IDENTITY(1,1) NOT NULL PRIMARY KEY,
442 | DateKey int NOT NULL,
443 | CustomerKey int NOT NULL,
444 | ProductCategoryKey int NOT NULL,
445 | EnglishProductCategoryName nvarchar(50) NOT NULL,
446 | ProductSubcategoryKey int NOT NULL,
447 | EnglishProductSubcategoryName nvarchar(50) NOT NULL,
448 | Date datetime NULL,
449 | FOREIGN KEY (DateKey) REFERENCES DimDate(DateKey),
450 | FOREIGN KEY (CustomerKey) REFERENCES DimCustomer(CustomerKey)
451 |
452 | ) |
453 |
454 | CREATE TABLE [DimReseller](
455 | [ResellerKey] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
456 | [GeographyKey] [int] NULL,
457 | [ResellerAlternateKey] [nvarchar](15) NULL,
458 | [Phone] [nvarchar](25) NULL,
459 | [BusinessType] [varchar](20) NOT NULL,
460 | [ResellerName] [nvarchar](50) NOT NULL,
461 | [NumberEmployees] [int] NULL,
462 | [OrderFrequency] [char](1) NULL,
463 | [OrderMonth] [tinyint] NULL,
464 | [FirstOrderYear] [int] NULL,
465 | [LastOrderYear] [int] NULL,
466 | [ProductLine] [nvarchar](50) NULL,
467 | [AddressLine1] [nvarchar](60) NULL,
468 | [AddressLine2] [nvarchar](60) NULL,
469 | [AnnualSales] [money] NULL,
470 | [BankName] [nvarchar](50) NULL,
471 | [MinPaymentType] [tinyint] NULL,
472 | [MinPaymentAmount] [money] NULL,
473 | [AnnualRevenue] [money] NULL,
474 | [YearOpened] [int] NULL,
475 | FOREIGN KEY (GeographyKey) REFERENCES DimGeography(GeographyKey)
476 | ) |
477 |
478 | CREATE TABLE [FactResellerSales](
479 | [ProductKey] [int] NOT NULL,
480 | [OrderDateKey] [int] NOT NULL,
481 | [DueDateKey] [int] NOT NULL,
482 | [ShipDateKey] [int] NOT NULL,
483 | [ResellerKey] [int] NOT NULL,
484 | [EmployeeKey] [int] NOT NULL,
485 | [PromotionKey] [int] NOT NULL,
486 | [CurrencyKey] [int] NOT NULL,
487 | [SalesTerritoryKey] [int] NOT NULL,
488 | [SalesOrderNumber] [nvarchar](20) NOT NULL,
489 | [SalesOrderLineNumber] [tinyint] NOT NULL,
490 | [RevisionNumber] [tinyint] NULL,
491 | [OrderQuantity] [smallint] NULL,
492 | [UnitPrice] [money] NULL,
493 | [ExtendedAmount] [money] NULL,
494 | [UnitPriceDiscountPct] [float] NULL,
495 | [DiscountAmount] [float] NULL,
496 | [ProductStandardCost] [money] NULL,
497 | [TotalProductCost] [money] NULL,
498 | [SalesAmount] [money] NULL,
499 | [TaxAmt] [money] NULL,
500 | [Freight] [money] NULL,
501 | [CarrierTrackingNumber] [nvarchar](25) NULL,
502 | [CustomerPONumber] [nvarchar](25) NULL,
503 | [OrderDate] [datetime] NULL,
504 | [DueDate] [datetime] NULL,
505 | [ShipDate] [datetime] NULL,
506 | PRIMARY KEY (SalesOrderNumber, SalesOrderLineNumber),
507 | FOREIGN KEY(CurrencyKey) REFERENCES DimCurrency(CurrencyKey),
508 | FOREIGN KEY(OrderDateKey) REFERENCES DimDate(DateKey),
509 | FOREIGN KEY(DueDateKey) REFERENCES DimDate(DateKey),
510 | FOREIGN KEY(ShipDateKey) REFERENCES DimDate(DateKey),
511 | FOREIGN KEY(EmployeeKey) REFERENCES DimEmployee(EmployeeKey),
512 | FOREIGN KEY(ProductKey) REFERENCES DimProduct(ProductKey),
513 | FOREIGN KEY(PromotionKey) REFERENCES DimPromotion(PromotionKey),
514 | FOREIGN KEY(ResellerKey) REFERENCES DimReseller(ResellerKey),
515 | FOREIGN KEY(SalesTerritoryKey) REFERENCES DimSalesTerritory(SalesTerritoryKey)
516 | ) |
517 |
518 |
--------------------------------------------------------------------------------
/solutions/Chapter 1/adventureworks_docs_v2.html:
--------------------------------------------------------------------------------
1 |
2 | List of Database tables
3 | ------------
4 |
5 | DimCurrency DimProductCategory FactInternetSalesReason
6 | DimCustomer DimProductSubcategory FactResellerSales
7 | DimDate DimPromotion FactSurveyResponse
8 | DimDepartmentGroup DimReseller customer_address_us
9 | DimEmployee DimSalesReason customer_email_a
10 | DimGeography DimSalesTerritory vwCUSTOMER_ADDRESS
11 | DimOrganization FactCurrencyRate vwCUSTOMER_BIRTHDATE
12 | DimProduct FactInternetSales
13 |
14 | DimCurrency
15 |
16 |
17 | cid |
18 | name |
19 | type |
20 | notnull |
21 | dflt_value |
22 | pk |
23 |
24 | 0 |
25 | CurrencyKey |
26 | int IDENTITY(1,1) |
27 | 1 |
28 | |
29 | 1 |
30 |
31 | 1 |
32 | CurrencyAlternateKey |
33 | nchar(3) |
34 | 1 |
35 | |
36 | 0 |
37 |
38 | 2 |
39 | CurrencyName |
40 | nvarchar(50) |
41 | 1 |
42 | |
43 | 0 |
44 |
45 |
46 | DimProductCategory
47 |
48 |
49 | cid |
50 | name |
51 | type |
52 | notnull |
53 | dflt_value |
54 | pk |
55 |
56 | 0 |
57 | ProductCategoryKey |
58 | int IDENTITY(1,1) |
59 | 1 |
60 | |
61 | 1 |
62 |
63 | 1 |
64 | ProductCategoryAlternateKey |
65 | int |
66 | 0 |
67 | |
68 | 0 |
69 |
70 | 2 |
71 | EnglishProductCategoryName |
72 | nvarchar(50) |
73 | 1 |
74 | |
75 | 0 |
76 |
77 | 3 |
78 | SpanishProductCategoryName |
79 | nvarchar(50) |
80 | 1 |
81 | |
82 | 0 |
83 |
84 | 4 |
85 | FrenchProductCategoryName |
86 | nvarchar(50) |
87 | 1 |
88 | |
89 | 0 |
90 |
91 |
92 | FactInternetSalesReason
93 |
94 |
95 | cid |
96 | name |
97 | type |
98 | notnull |
99 | dflt_value |
100 | pk |
101 |
102 | 0 |
103 | ProductKey |
104 | int |
105 | 1 |
106 | |
107 | 0 |
108 |
109 | 1 |
110 | OrderDateKey |
111 | int |
112 | 1 |
113 | |
114 | 0 |
115 |
116 | 2 |
117 | DueDateKey |
118 | int |
119 | 1 |
120 | |
121 | 0 |
122 |
123 | 3 |
124 | ShipDateKey |
125 | int |
126 | 1 |
127 | |
128 | 0 |
129 |
130 | 4 |
131 | CustomerKey |
132 | int |
133 | 1 |
134 | |
135 | 0 |
136 |
137 | 5 |
138 | PromotionKey |
139 | int |
140 | 1 |
141 | |
142 | 0 |
143 |
144 | 6 |
145 | CurrencyKey |
146 | int |
147 | 1 |
148 | |
149 | 0 |
150 |
151 | 7 |
152 | SalesTerritoryKey |
153 | int |
154 | 1 |
155 | |
156 | 0 |
157 |
158 | 8 |
159 | SalesOrderNumber |
160 | nvarchar(20) |
161 | 1 |
162 | |
163 | 1 |
164 |
165 | 9 |
166 | SalesOrderLineNumber |
167 | tinyint |
168 | 1 |
169 | |
170 | 2 |
171 |
172 | 10 |
173 | RevisionNumber |
174 | tinyint |
175 | 1 |
176 | |
177 | 0 |
178 |
179 | 11 |
180 | OrderQuantity |
181 | smallint |
182 | 1 |
183 | |
184 | 0 |
185 |
186 | 12 |
187 | UnitPrice |
188 | money |
189 | 1 |
190 | |
191 | 0 |
192 |
193 | 13 |
194 | ExtendedAmount |
195 | money |
196 | 1 |
197 | |
198 | 0 |
199 |
200 | 14 |
201 | UnitPriceDiscountPct |
202 | float |
203 | 1 |
204 | |
205 | 0 |
206 |
207 | 15 |
208 | DiscountAmount |
209 | float |
210 | 1 |
211 | |
212 | 0 |
213 |
214 | 16 |
215 | ProductStandardCost |
216 | money |
217 | 1 |
218 | |
219 | 0 |
220 |
221 | 17 |
222 | TotalProductCost |
223 | money |
224 | 1 |
225 | |
226 | 0 |
227 |
228 | 18 |
229 | SalesAmount |
230 | money |
231 | 1 |
232 | |
233 | 0 |
234 |
235 | 19 |
236 | TaxAmt |
237 | money |
238 | 1 |
239 | |
240 | 0 |
241 |
242 | 20 |
243 | Freight |
244 | money |
245 | 1 |
246 | |
247 | 0 |
248 |
249 | 21 |
250 | CarrierTrackingNumber |
251 | nvarchar(25) |
252 | 0 |
253 | |
254 | 0 |
255 |
256 | 22 |
257 | CustomerPONumber |
258 | nvarchar(25) |
259 | 0 |
260 | |
261 | 0 |
262 |
263 | 23 |
264 | OrderDate |
265 | datetime |
266 | 0 |
267 | |
268 | 0 |
269 |
270 | 24 |
271 | DueDate |
272 | datetime |
273 | 0 |
274 | |
275 | 0 |
276 |
277 | 25 |
278 | ShipDate |
279 | datetime |
280 | 0 |
281 | |
282 | 0 |
283 |
284 |
285 | DimCustomer
286 |
287 |
288 | cid |
289 | name |
290 | type |
291 | notnull |
292 | dflt_value |
293 | pk |
294 |
295 | 0 |
296 | CustomerKey |
297 | int IDENTITY(1,1) |
298 | 1 |
299 | |
300 | 1 |
301 |
302 | 1 |
303 | GeographyKey |
304 | int |
305 | 0 |
306 | |
307 | 0 |
308 |
309 | 2 |
310 | CustomerAlternateKey |
311 | nvarchar(15) |
312 | 1 |
313 | |
314 | 0 |
315 |
316 | 3 |
317 | Title |
318 | nvarchar(8) |
319 | 0 |
320 | |
321 | 0 |
322 |
323 | 4 |
324 | FirstName |
325 | nvarchar(50) |
326 | 0 |
327 | |
328 | 0 |
329 |
330 | 5 |
331 | MiddleName |
332 | nvarchar(50) |
333 | 0 |
334 | |
335 | 0 |
336 |
337 | 6 |
338 | LastName |
339 | nvarchar(50) |
340 | 0 |
341 | |
342 | 0 |
343 |
344 | 7 |
345 | NameStyle |
346 | bit |
347 | 0 |
348 | |
349 | 0 |
350 |
351 | 8 |
352 | BirthDate |
353 | date |
354 | 0 |
355 | |
356 | 0 |
357 |
358 | 9 |
359 | MaritalStatus |
360 | nchar(1) |
361 | 0 |
362 | |
363 | 0 |
364 |
365 | 10 |
366 | Suffix |
367 | nvarchar(10) |
368 | 0 |
369 | |
370 | 0 |
371 |
372 | 11 |
373 | Gender |
374 | nvarchar(1) |
375 | 0 |
376 | |
377 | 0 |
378 |
379 | 12 |
380 | EmailAddress |
381 | nvarchar(50) |
382 | 0 |
383 | |
384 | 0 |
385 |
386 | 13 |
387 | YearlyIncome |
388 | money |
389 | 0 |
390 | |
391 | 0 |
392 |
393 | 14 |
394 | TotalChildren |
395 | tinyint |
396 | 0 |
397 | |
398 | 0 |
399 |
400 | 15 |
401 | NumberChildrenAtHome |
402 | tinyint |
403 | 0 |
404 | |
405 | 0 |
406 |
407 | 16 |
408 | EnglishEducation |
409 | nvarchar(40) |
410 | 0 |
411 | |
412 | 0 |
413 |
414 | 17 |
415 | SpanishEducation |
416 | nvarchar(40) |
417 | 0 |
418 | |
419 | 0 |
420 |
421 | 18 |
422 | FrenchEducation |
423 | nvarchar(40) |
424 | 0 |
425 | |
426 | 0 |
427 |
428 | 19 |
429 | EnglishOccupation |
430 | nvarchar(100) |
431 | 0 |
432 | |
433 | 0 |
434 |
435 | 20 |
436 | SpanishOccupation |
437 | nvarchar(100) |
438 | 0 |
439 | |
440 | 0 |
441 |
442 | 21 |
443 | FrenchOccupation |
444 | nvarchar(100) |
445 | 0 |
446 | |
447 | 0 |
448 |
449 | 22 |
450 | HouseOwnerFlag |
451 | nchar(1) |
452 | 0 |
453 | |
454 | 0 |
455 |
456 | 23 |
457 | NumberCarsOwned |
458 | tinyint |
459 | 0 |
460 | |
461 | 0 |
462 |
463 | 24 |
464 | AddressLine1 |
465 | nvarchar(120) |
466 | 0 |
467 | |
468 | 0 |
469 |
470 | 25 |
471 | AddressLine2 |
472 | nvarchar(120) |
473 | 0 |
474 | |
475 | 0 |
476 |
477 | 26 |
478 | Phone |
479 | nvarchar(20) |
480 | 0 |
481 | |
482 | 0 |
483 |
484 | 27 |
485 | DateFirstPurchase |
486 | date |
487 | 0 |
488 | |
489 | 0 |
490 |
491 | 28 |
492 | CommuteDistance |
493 | nvarchar(15) |
494 | 0 |
495 | |
496 | 0 |
497 |
498 |
499 | DimProductSubcategory
500 |
501 |
502 | cid |
503 | name |
504 | type |
505 | notnull |
506 | dflt_value |
507 | pk |
508 |
509 | 0 |
510 | ProductSubcategoryKey |
511 | int IDENTITY(1,1) |
512 | 1 |
513 | |
514 | 1 |
515 |
516 | 1 |
517 | ProductSubcategoryAlternateKey |
518 | int |
519 | 0 |
520 | |
521 | 0 |
522 |
523 | 2 |
524 | EnglishProductSubcategoryName |
525 | nvarchar(50) |
526 | 1 |
527 | |
528 | 0 |
529 |
530 | 3 |
531 | SpanishProductSubcategoryName |
532 | nvarchar(50) |
533 | 1 |
534 | |
535 | 0 |
536 |
537 | 4 |
538 | FrenchProductSubcategoryName |
539 | nvarchar(50) |
540 | 1 |
541 | |
542 | 0 |
543 |
544 | 5 |
545 | ProductCategoryKey |
546 | int |
547 | 0 |
548 | |
549 | 0 |
550 |
551 |
552 | FactResellerSales
553 |
554 |
555 | cid |
556 | name |
557 | type |
558 | notnull |
559 | dflt_value |
560 | pk |
561 |
562 | 0 |
563 | ProductKey |
564 | int |
565 | 1 |
566 | |
567 | 0 |
568 |
569 | 1 |
570 | OrderDateKey |
571 | int |
572 | 1 |
573 | |
574 | 0 |
575 |
576 | 2 |
577 | DueDateKey |
578 | int |
579 | 1 |
580 | |
581 | 0 |
582 |
583 | 3 |
584 | ShipDateKey |
585 | int |
586 | 1 |
587 | |
588 | 0 |
589 |
590 | 4 |
591 | ResellerKey |
592 | int |
593 | 1 |
594 | |
595 | 0 |
596 |
597 | 5 |
598 | EmployeeKey |
599 | int |
600 | 1 |
601 | |
602 | 0 |
603 |
604 | 6 |
605 | PromotionKey |
606 | int |
607 | 1 |
608 | |
609 | 0 |
610 |
611 | 7 |
612 | CurrencyKey |
613 | int |
614 | 1 |
615 | |
616 | 0 |
617 |
618 | 8 |
619 | SalesTerritoryKey |
620 | int |
621 | 1 |
622 | |
623 | 0 |
624 |
625 | 9 |
626 | SalesOrderNumber |
627 | nvarchar |
628 | 1 |
629 | |
630 | 1 |
631 |
632 | 10 |
633 | SalesOrderLineNumber |
634 | tinyint |
635 | 1 |
636 | |
637 | 2 |
638 |
639 | 11 |
640 | RevisionNumber |
641 | tinyint |
642 | 0 |
643 | |
644 | 0 |
645 |
646 | 12 |
647 | OrderQuantity |
648 | smallint |
649 | 0 |
650 | |
651 | 0 |
652 |
653 | 13 |
654 | UnitPrice |
655 | money |
656 | 0 |
657 | |
658 | 0 |
659 |
660 | 14 |
661 | ExtendedAmount |
662 | money |
663 | 0 |
664 | |
665 | 0 |
666 |
667 | 15 |
668 | UnitPriceDiscountPct |
669 | float |
670 | 0 |
671 | |
672 | 0 |
673 |
674 | 16 |
675 | DiscountAmount |
676 | float |
677 | 0 |
678 | |
679 | 0 |
680 |
681 | 17 |
682 | ProductStandardCost |
683 | money |
684 | 0 |
685 | |
686 | 0 |
687 |
688 | 18 |
689 | TotalProductCost |
690 | money |
691 | 0 |
692 | |
693 | 0 |
694 |
695 | 19 |
696 | SalesAmount |
697 | money |
698 | 0 |
699 | |
700 | 0 |
701 |
702 | 20 |
703 | TaxAmt |
704 | money |
705 | 0 |
706 | |
707 | 0 |
708 |
709 | 21 |
710 | Freight |
711 | money |
712 | 0 |
713 | |
714 | 0 |
715 |
716 | 22 |
717 | CarrierTrackingNumber |
718 | nvarchar |
719 | 0 |
720 | |
721 | 0 |
722 |
723 | 23 |
724 | CustomerPONumber |
725 | nvarchar |
726 | 0 |
727 | |
728 | 0 |
729 |
730 | 24 |
731 | OrderDate |
732 | datetime |
733 | 0 |
734 | |
735 | 0 |
736 |
737 | 25 |
738 | DueDate |
739 | datetime |
740 | 0 |
741 | |
742 | 0 |
743 |
744 | 26 |
745 | ShipDate |
746 | datetime |
747 | 0 |
748 | |
749 | 0 |
750 |
751 |
752 | DimDate
753 |
754 |
755 | cid |
756 | name |
757 | type |
758 | notnull |
759 | dflt_value |
760 | pk |
761 |
762 | 0 |
763 | DateKey |
764 | int |
765 | 1 |
766 | |
767 | 1 |
768 |
769 | 1 |
770 | FullDateAlternateKey |
771 | date |
772 | 1 |
773 | |
774 | 0 |
775 |
776 | 2 |
777 | DayNumberOfWeek |
778 | tinyint |
779 | 1 |
780 | |
781 | 0 |
782 |
783 | 3 |
784 | EnglishDayNameOfWeek |
785 | nvarchar(10) |
786 | 1 |
787 | |
788 | 0 |
789 |
790 | 4 |
791 | SpanishDayNameOfWeek |
792 | nvarchar(10) |
793 | 1 |
794 | |
795 | 0 |
796 |
797 | 5 |
798 | FrenchDayNameOfWeek |
799 | nvarchar(10) |
800 | 1 |
801 | |
802 | 0 |
803 |
804 | 6 |
805 | DayNumberOfMonth |
806 | tinyint |
807 | 1 |
808 | |
809 | 0 |
810 |
811 | 7 |
812 | DayNumberOfYear |
813 | smallint |
814 | 1 |
815 | |
816 | 0 |
817 |
818 | 8 |
819 | WeekNumberOfYear |
820 | tinyint |
821 | 1 |
822 | |
823 | 0 |
824 |
825 | 9 |
826 | EnglishMonthName |
827 | nvarchar(10) |
828 | 1 |
829 | |
830 | 0 |
831 |
832 | 10 |
833 | SpanishMonthName |
834 | nvarchar(10) |
835 | 1 |
836 | |
837 | 0 |
838 |
839 | 11 |
840 | FrenchMonthName |
841 | nvarchar(10) |
842 | 1 |
843 | |
844 | 0 |
845 |
846 | 12 |
847 | MonthNumberOfYear |
848 | tinyint |
849 | 1 |
850 | |
851 | 0 |
852 |
853 | 13 |
854 | CalendarQuarter |
855 | tinyint |
856 | 1 |
857 | |
858 | 0 |
859 |
860 | 14 |
861 | CalendarYear |
862 | smallint |
863 | 1 |
864 | |
865 | 0 |
866 |
867 | 15 |
868 | CalendarSemester |
869 | tinyint |
870 | 1 |
871 | |
872 | 0 |
873 |
874 | 16 |
875 | FiscalQuarter |
876 | tinyint |
877 | 1 |
878 | |
879 | 0 |
880 |
881 | 17 |
882 | FiscalYear |
883 | smallint |
884 | 1 |
885 | |
886 | 0 |
887 |
888 | 18 |
889 | FiscalSemester |
890 | tinyint |
891 | 1 |
892 | |
893 | 0 |
894 |
895 |
896 | DimPromotion
897 |
898 |
899 | cid |
900 | name |
901 | type |
902 | notnull |
903 | dflt_value |
904 | pk |
905 |
906 | 0 |
907 | PromotionKey |
908 | int IDENTITY(1,1) |
909 | 1 |
910 | |
911 | 1 |
912 |
913 | 1 |
914 | PromotionAlternateKey |
915 | int |
916 | 0 |
917 | |
918 | 0 |
919 |
920 | 2 |
921 | EnglishPromotionName |
922 | nvarchar(255) |
923 | 0 |
924 | |
925 | 0 |
926 |
927 | 3 |
928 | SpanishPromotionName |
929 | nvarchar(255) |
930 | 0 |
931 | |
932 | 0 |
933 |
934 | 4 |
935 | FrenchPromotionName |
936 | nvarchar(255) |
937 | 0 |
938 | |
939 | 0 |
940 |
941 | 5 |
942 | DiscountPct |
943 | float |
944 | 0 |
945 | |
946 | 0 |
947 |
948 | 6 |
949 | EnglishPromotionType |
950 | nvarchar(50) |
951 | 0 |
952 | |
953 | 0 |
954 |
955 | 7 |
956 | SpanishPromotionType |
957 | nvarchar(50) |
958 | 0 |
959 | |
960 | 0 |
961 |
962 | 8 |
963 | FrenchPromotionType |
964 | nvarchar(50) |
965 | 0 |
966 | |
967 | 0 |
968 |
969 | 9 |
970 | EnglishPromotionCategory |
971 | nvarchar(50) |
972 | 0 |
973 | |
974 | 0 |
975 |
976 | 10 |
977 | SpanishPromotionCategory |
978 | nvarchar(50) |
979 | 0 |
980 | |
981 | 0 |
982 |
983 | 11 |
984 | FrenchPromotionCategory |
985 | nvarchar(50) |
986 | 0 |
987 | |
988 | 0 |
989 |
990 | 12 |
991 | StartDate |
992 | datetime |
993 | 1 |
994 | |
995 | 0 |
996 |
997 | 13 |
998 | EndDate |
999 | datetime |
1000 | 0 |
1001 | |
1002 | 0 |
1003 |
1004 | 14 |
1005 | MinQty |
1006 | int |
1007 | 0 |
1008 | |
1009 | 0 |
1010 |
1011 | 15 |
1012 | MaxQty |
1013 | int |
1014 | 0 |
1015 | |
1016 | 0 |
1017 |
1018 |
1019 | FactSurveyResponse
1020 |
1021 |
1022 | cid |
1023 | name |
1024 | type |
1025 | notnull |
1026 | dflt_value |
1027 | pk |
1028 |
1029 | 0 |
1030 | SurveyResponseKey |
1031 | int IDENTITY(1,1) |
1032 | 1 |
1033 | |
1034 | 1 |
1035 |
1036 | 1 |
1037 | DateKey |
1038 | int |
1039 | 1 |
1040 | |
1041 | 0 |
1042 |
1043 | 2 |
1044 | CustomerKey |
1045 | int |
1046 | 1 |
1047 | |
1048 | 0 |
1049 |
1050 | 3 |
1051 | ProductCategoryKey |
1052 | int |
1053 | 1 |
1054 | |
1055 | 0 |
1056 |
1057 | 4 |
1058 | EnglishProductCategoryName |
1059 | nvarchar(50) |
1060 | 1 |
1061 | |
1062 | 0 |
1063 |
1064 | 5 |
1065 | ProductSubcategoryKey |
1066 | int |
1067 | 1 |
1068 | |
1069 | 0 |
1070 |
1071 | 6 |
1072 | EnglishProductSubcategoryName |
1073 | nvarchar(50) |
1074 | 1 |
1075 | |
1076 | 0 |
1077 |
1078 | 7 |
1079 | Date |
1080 | datetime |
1081 | 0 |
1082 | |
1083 | 0 |
1084 |
1085 |
1086 | DimDepartmentGroup
1087 |
1088 |
1089 | cid |
1090 | name |
1091 | type |
1092 | notnull |
1093 | dflt_value |
1094 | pk |
1095 |
1096 | 0 |
1097 | DepartmentGroupKey |
1098 | int IDENTITY(1,1) |
1099 | 1 |
1100 | |
1101 | 1 |
1102 |
1103 | 1 |
1104 | ParentDepartmentGroupKey |
1105 | int |
1106 | 0 |
1107 | |
1108 | 0 |
1109 |
1110 | 2 |
1111 | DepartmentGroupName |
1112 | nvarchar(50) |
1113 | 0 |
1114 | |
1115 | 0 |
1116 |
1117 |
1118 | DimReseller
1119 |
1120 |
1121 | cid |
1122 | name |
1123 | type |
1124 | notnull |
1125 | dflt_value |
1126 | pk |
1127 |
1128 | 0 |
1129 | ResellerKey |
1130 | int |
1131 | 1 |
1132 | |
1133 | 1 |
1134 |
1135 | 1 |
1136 | GeographyKey |
1137 | int |
1138 | 0 |
1139 | |
1140 | 0 |
1141 |
1142 | 2 |
1143 | ResellerAlternateKey |
1144 | nvarchar |
1145 | 0 |
1146 | |
1147 | 0 |
1148 |
1149 | 3 |
1150 | Phone |
1151 | nvarchar |
1152 | 0 |
1153 | |
1154 | 0 |
1155 |
1156 | 4 |
1157 | BusinessType |
1158 | varchar |
1159 | 1 |
1160 | |
1161 | 0 |
1162 |
1163 | 5 |
1164 | ResellerName |
1165 | nvarchar |
1166 | 1 |
1167 | |
1168 | 0 |
1169 |
1170 | 6 |
1171 | NumberEmployees |
1172 | int |
1173 | 0 |
1174 | |
1175 | 0 |
1176 |
1177 | 7 |
1178 | OrderFrequency |
1179 | char |
1180 | 0 |
1181 | |
1182 | 0 |
1183 |
1184 | 8 |
1185 | OrderMonth |
1186 | tinyint |
1187 | 0 |
1188 | |
1189 | 0 |
1190 |
1191 | 9 |
1192 | FirstOrderYear |
1193 | int |
1194 | 0 |
1195 | |
1196 | 0 |
1197 |
1198 | 10 |
1199 | LastOrderYear |
1200 | int |
1201 | 0 |
1202 | |
1203 | 0 |
1204 |
1205 | 11 |
1206 | ProductLine |
1207 | nvarchar |
1208 | 0 |
1209 | |
1210 | 0 |
1211 |
1212 | 12 |
1213 | AddressLine1 |
1214 | nvarchar |
1215 | 0 |
1216 | |
1217 | 0 |
1218 |
1219 | 13 |
1220 | AddressLine2 |
1221 | nvarchar |
1222 | 0 |
1223 | |
1224 | 0 |
1225 |
1226 | 14 |
1227 | AnnualSales |
1228 | money |
1229 | 0 |
1230 | |
1231 | 0 |
1232 |
1233 | 15 |
1234 | BankName |
1235 | nvarchar |
1236 | 0 |
1237 | |
1238 | 0 |
1239 |
1240 | 16 |
1241 | MinPaymentType |
1242 | tinyint |
1243 | 0 |
1244 | |
1245 | 0 |
1246 |
1247 | 17 |
1248 | MinPaymentAmount |
1249 | money |
1250 | 0 |
1251 | |
1252 | 0 |
1253 |
1254 | 18 |
1255 | AnnualRevenue |
1256 | money |
1257 | 0 |
1258 | |
1259 | 0 |
1260 |
1261 | 19 |
1262 | YearOpened |
1263 | int |
1264 | 0 |
1265 | |
1266 | 0 |
1267 |
1268 |
1269 | DimEmployee
1270 |
1271 |
1272 | cid |
1273 | name |
1274 | type |
1275 | notnull |
1276 | dflt_value |
1277 | pk |
1278 |
1279 | 0 |
1280 | EmployeeKey |
1281 | int IDENTITY(1,1) |
1282 | 1 |
1283 | |
1284 | 1 |
1285 |
1286 | 1 |
1287 | ParentEmployeeKey |
1288 | int |
1289 | 0 |
1290 | |
1291 | 0 |
1292 |
1293 | 2 |
1294 | EmployeeNationalIDAlternateKey |
1295 | nvarchar(15) |
1296 | 0 |
1297 | |
1298 | 0 |
1299 |
1300 | 3 |
1301 | ParentEmployeeNationalIDAlternateKey |
1302 | nvarchar(15) |
1303 | 0 |
1304 | |
1305 | 0 |
1306 |
1307 | 4 |
1308 | SalesTerritoryKey |
1309 | int |
1310 | 0 |
1311 | |
1312 | 0 |
1313 |
1314 | 5 |
1315 | FirstName |
1316 | nvarchar(50) |
1317 | 1 |
1318 | |
1319 | 0 |
1320 |
1321 | 6 |
1322 | LastName |
1323 | nvarchar(50) |
1324 | 1 |
1325 | |
1326 | 0 |
1327 |
1328 | 7 |
1329 | MiddleName |
1330 | nvarchar(50) |
1331 | 0 |
1332 | |
1333 | 0 |
1334 |
1335 | 8 |
1336 | NameStyle |
1337 | bit |
1338 | 1 |
1339 | |
1340 | 0 |
1341 |
1342 | 9 |
1343 | Title |
1344 | nvarchar(50) |
1345 | 0 |
1346 | |
1347 | 0 |
1348 |
1349 | 10 |
1350 | HireDate |
1351 | date |
1352 | 0 |
1353 | |
1354 | 0 |
1355 |
1356 | 11 |
1357 | BirthDate |
1358 | date |
1359 | 0 |
1360 | |
1361 | 0 |
1362 |
1363 | 12 |
1364 | LoginID |
1365 | nvarchar(256) |
1366 | 0 |
1367 | |
1368 | 0 |
1369 |
1370 | 13 |
1371 | EmailAddress |
1372 | nvarchar(50) |
1373 | 0 |
1374 | |
1375 | 0 |
1376 |
1377 | 14 |
1378 | Phone |
1379 | nvarchar(25) |
1380 | 0 |
1381 | |
1382 | 0 |
1383 |
1384 | 15 |
1385 | MaritalStatus |
1386 | nchar(1) |
1387 | 0 |
1388 | |
1389 | 0 |
1390 |
1391 | 16 |
1392 | EmergencyContactName |
1393 | nvarchar(50) |
1394 | 0 |
1395 | |
1396 | 0 |
1397 |
1398 | 17 |
1399 | EmergencyContactPhone |
1400 | nvarchar(25) |
1401 | 0 |
1402 | |
1403 | 0 |
1404 |
1405 | 18 |
1406 | SalariedFlag |
1407 | bit |
1408 | 0 |
1409 | |
1410 | 0 |
1411 |
1412 | 19 |
1413 | Gender |
1414 | nchar(1) |
1415 | 0 |
1416 | |
1417 | 0 |
1418 |
1419 | 20 |
1420 | PayFrequency |
1421 | tinyint |
1422 | 0 |
1423 | |
1424 | 0 |
1425 |
1426 | 21 |
1427 | BaseRate |
1428 | money |
1429 | 0 |
1430 | |
1431 | 0 |
1432 |
1433 | 22 |
1434 | VacationHours |
1435 | smallint |
1436 | 0 |
1437 | |
1438 | 0 |
1439 |
1440 | 23 |
1441 | SickLeaveHours |
1442 | smallint |
1443 | 0 |
1444 | |
1445 | 0 |
1446 |
1447 | 24 |
1448 | CurrentFlag |
1449 | bit |
1450 | 1 |
1451 | |
1452 | 0 |
1453 |
1454 | 25 |
1455 | SalesPersonFlag |
1456 | bit |
1457 | 1 |
1458 | |
1459 | 0 |
1460 |
1461 | 26 |
1462 | DepartmentName |
1463 | nvarchar(50) |
1464 | 0 |
1465 | |
1466 | 0 |
1467 |
1468 | 27 |
1469 | StartDate |
1470 | date |
1471 | 0 |
1472 | |
1473 | 0 |
1474 |
1475 | 28 |
1476 | EndDate |
1477 | date |
1478 | 0 |
1479 | |
1480 | 0 |
1481 |
1482 | 29 |
1483 | Status |
1484 | nvarchar(50) |
1485 | 0 |
1486 | |
1487 | 0 |
1488 |
1489 | 30 |
1490 | EmployeePhoto |
1491 | varbinary |
1492 | 0 |
1493 | |
1494 | 0 |
1495 |
1496 |
1497 | DimSalesReason
1498 |
1499 |
1500 | cid |
1501 | name |
1502 | type |
1503 | notnull |
1504 | dflt_value |
1505 | pk |
1506 |
1507 | 0 |
1508 | SalesReasonKey |
1509 | int IDENTITY(1,1) |
1510 | 1 |
1511 | |
1512 | 1 |
1513 |
1514 | 1 |
1515 | SalesReasonAlternateKey |
1516 | int |
1517 | 1 |
1518 | |
1519 | 0 |
1520 |
1521 | 2 |
1522 | SalesReasonName |
1523 | nvarchar(50) |
1524 | 1 |
1525 | |
1526 | 0 |
1527 |
1528 | 3 |
1529 | SalesReasonReasonType |
1530 | nvarchar(50) |
1531 | 1 |
1532 | |
1533 | 0 |
1534 |
1535 |
1536 | DimGeography
1537 |
1538 |
1539 | cid |
1540 | name |
1541 | type |
1542 | notnull |
1543 | dflt_value |
1544 | pk |
1545 |
1546 | 0 |
1547 | GeographyKey |
1548 | int IDENTITY(1,1) |
1549 | 1 |
1550 | |
1551 | 1 |
1552 |
1553 | 1 |
1554 | City |
1555 | nvarchar(30) |
1556 | 0 |
1557 | |
1558 | 0 |
1559 |
1560 | 2 |
1561 | StateProvinceCode |
1562 | nvarchar(3) |
1563 | 0 |
1564 | |
1565 | 0 |
1566 |
1567 | 3 |
1568 | StateProvinceName |
1569 | nvarchar(50) |
1570 | 0 |
1571 | |
1572 | 0 |
1573 |
1574 | 4 |
1575 | CountryRegionCode |
1576 | nvarchar(3) |
1577 | 0 |
1578 | |
1579 | 0 |
1580 |
1581 | 5 |
1582 | EnglishCountryRegionName |
1583 | nvarchar(50) |
1584 | 0 |
1585 | |
1586 | 0 |
1587 |
1588 | 6 |
1589 | SpanishCountryRegionName |
1590 | nvarchar(50) |
1591 | 0 |
1592 | |
1593 | 0 |
1594 |
1595 | 7 |
1596 | FrenchCountryRegionName |
1597 | nvarchar(50) |
1598 | 0 |
1599 | |
1600 | 0 |
1601 |
1602 | 8 |
1603 | PostalCode |
1604 | nvarchar(15) |
1605 | 0 |
1606 | |
1607 | 0 |
1608 |
1609 | 9 |
1610 | SalesTerritoryKey |
1611 | int |
1612 | 0 |
1613 | |
1614 | 0 |
1615 |
1616 | 10 |
1617 | IpAddressLocator |
1618 | nvarchar(15) |
1619 | 0 |
1620 | |
1621 | 0 |
1622 |
1623 |
1624 | DimSalesTerritory
1625 |
1626 |
1627 | cid |
1628 | name |
1629 | type |
1630 | notnull |
1631 | dflt_value |
1632 | pk |
1633 |
1634 | 0 |
1635 | SalesTerritoryKey |
1636 | int IDENTITY(1,1) |
1637 | 1 |
1638 | |
1639 | 1 |
1640 |
1641 | 1 |
1642 | SalesTerritoryAlternateKey |
1643 | int |
1644 | 0 |
1645 | |
1646 | 0 |
1647 |
1648 | 2 |
1649 | SalesTerritoryRegion |
1650 | nvarchar(50) |
1651 | 1 |
1652 | |
1653 | 0 |
1654 |
1655 | 3 |
1656 | SalesTerritoryCountry |
1657 | nvarchar(50) |
1658 | 1 |
1659 | |
1660 | 0 |
1661 |
1662 | 4 |
1663 | SalesTerritoryGroup |
1664 | nvarchar(50) |
1665 | 0 |
1666 | |
1667 | 0 |
1668 |
1669 | 5 |
1670 | SalesTerritoryImage |
1671 | varbinary(255) |
1672 | 0 |
1673 | |
1674 | 0 |
1675 |
1676 |
1677 | DimOrganization
1678 |
1679 |
1680 | cid |
1681 | name |
1682 | type |
1683 | notnull |
1684 | dflt_value |
1685 | pk |
1686 |
1687 | 0 |
1688 | OrganizationKey |
1689 | int IDENTITY(1,1) |
1690 | 1 |
1691 | |
1692 | 1 |
1693 |
1694 | 1 |
1695 | ParentOrganizationKey |
1696 | int |
1697 | 0 |
1698 | |
1699 | 0 |
1700 |
1701 | 2 |
1702 | PercentageOfOwnership |
1703 | nvarchar(16) |
1704 | 0 |
1705 | |
1706 | 0 |
1707 |
1708 | 3 |
1709 | OrganizationName |
1710 | nvarchar(50) |
1711 | 0 |
1712 | |
1713 | 0 |
1714 |
1715 | 4 |
1716 | CurrencyKey |
1717 | int |
1718 | 0 |
1719 | |
1720 | 0 |
1721 |
1722 |
1723 | FactCurrencyRate
1724 |
1725 |
1726 | cid |
1727 | name |
1728 | type |
1729 | notnull |
1730 | dflt_value |
1731 | pk |
1732 |
1733 | 0 |
1734 | CurrencyKey |
1735 | int |
1736 | 1 |
1737 | |
1738 | 1 |
1739 |
1740 | 1 |
1741 | DateKey |
1742 | int |
1743 | 1 |
1744 | |
1745 | 2 |
1746 |
1747 | 2 |
1748 | AverageRate |
1749 | float |
1750 | 1 |
1751 | |
1752 | 0 |
1753 |
1754 | 3 |
1755 | EndOfDayRate |
1756 | float |
1757 | 1 |
1758 | |
1759 | 0 |
1760 |
1761 | 4 |
1762 | Date |
1763 | datetime |
1764 | 0 |
1765 | |
1766 | 0 |
1767 |
1768 |
1769 | DimProduct
1770 |
1771 |
1772 | cid |
1773 | name |
1774 | type |
1775 | notnull |
1776 | dflt_value |
1777 | pk |
1778 |
1779 | 0 |
1780 | ProductKey |
1781 | int IDENTITY(1,1) |
1782 | 0 |
1783 | |
1784 | 1 |
1785 |
1786 | 1 |
1787 | ProductAlternateKey |
1788 | nvarchar(25) |
1789 | 0 |
1790 | |
1791 | 0 |
1792 |
1793 | 2 |
1794 | ProductSubcategoryKey |
1795 | int |
1796 | 0 |
1797 | |
1798 | 0 |
1799 |
1800 | 3 |
1801 | WeightUnitMeasureCode |
1802 | nchar(3) |
1803 | 0 |
1804 | |
1805 | 0 |
1806 |
1807 | 4 |
1808 | SizeUnitMeasureCode |
1809 | nchar(3) |
1810 | 0 |
1811 | |
1812 | 0 |
1813 |
1814 | 5 |
1815 | EnglishProductName |
1816 | nvarchar(50) |
1817 | 1 |
1818 | |
1819 | 0 |
1820 |
1821 | 6 |
1822 | SpanishProductName |
1823 | nvarchar(50) |
1824 | 1 |
1825 | |
1826 | 0 |
1827 |
1828 | 7 |
1829 | FrenchProductName |
1830 | nvarchar(50) |
1831 | 1 |
1832 | |
1833 | 0 |
1834 |
1835 | 8 |
1836 | StandardCost |
1837 | money |
1838 | 0 |
1839 | |
1840 | 0 |
1841 |
1842 | 9 |
1843 | FinishedGoodsFlag |
1844 | bit |
1845 | 1 |
1846 | |
1847 | 0 |
1848 |
1849 | 10 |
1850 | Color |
1851 | nvarchar(15) |
1852 | 1 |
1853 | |
1854 | 0 |
1855 |
1856 | 11 |
1857 | SafetyStockLevel |
1858 | smallint |
1859 | 0 |
1860 | |
1861 | 0 |
1862 |
1863 | 12 |
1864 | ReorderPoint |
1865 | smallint |
1866 | 0 |
1867 | |
1868 | 0 |
1869 |
1870 | 13 |
1871 | ListPrice |
1872 | money |
1873 | 0 |
1874 | |
1875 | 0 |
1876 |
1877 | 14 |
1878 | Size |
1879 | nvarchar(50) |
1880 | 0 |
1881 | |
1882 | 0 |
1883 |
1884 | 15 |
1885 | SizeRange |
1886 | nvarchar(50) |
1887 | 0 |
1888 | |
1889 | 0 |
1890 |
1891 | 16 |
1892 | Weight |
1893 | float |
1894 | 0 |
1895 | |
1896 | 0 |
1897 |
1898 | 17 |
1899 | DaysToManufacture |
1900 | int |
1901 | 0 |
1902 | |
1903 | 0 |
1904 |
1905 | 18 |
1906 | ProductLine |
1907 | nchar(2) |
1908 | 0 |
1909 | |
1910 | 0 |
1911 |
1912 | 19 |
1913 | DealerPrice |
1914 | money |
1915 | 0 |
1916 | |
1917 | 0 |
1918 |
1919 | 20 |
1920 | Class |
1921 | nchar(2) |
1922 | 0 |
1923 | |
1924 | 0 |
1925 |
1926 | 21 |
1927 | Style |
1928 | nchar(2) |
1929 | 0 |
1930 | |
1931 | 0 |
1932 |
1933 | 22 |
1934 | ModelName |
1935 | nvarchar(50) |
1936 | 0 |
1937 | |
1938 | 0 |
1939 |
1940 | 23 |
1941 | LargePhoto |
1942 | varbinary |
1943 | 0 |
1944 | |
1945 | 0 |
1946 |
1947 | 24 |
1948 | EnglishDescription |
1949 | nvarchar(400) |
1950 | 0 |
1951 | |
1952 | 0 |
1953 |
1954 | 25 |
1955 | FrenchDescription |
1956 | nvarchar(400) |
1957 | 0 |
1958 | |
1959 | 0 |
1960 |
1961 | 26 |
1962 | ChineseDescription |
1963 | nvarchar(400) |
1964 | 0 |
1965 | |
1966 | 0 |
1967 |
1968 | 27 |
1969 | ArabicDescription |
1970 | nvarchar(400) |
1971 | 0 |
1972 | |
1973 | 0 |
1974 |
1975 | 28 |
1976 | HebrewDescription |
1977 | nvarchar(400) |
1978 | 0 |
1979 | |
1980 | 0 |
1981 |
1982 | 29 |
1983 | ThaiDescription |
1984 | nvarchar(400) |
1985 | 0 |
1986 | |
1987 | 0 |
1988 |
1989 | 30 |
1990 | GermanDescription |
1991 | nvarchar(400) |
1992 | 0 |
1993 | |
1994 | 0 |
1995 |
1996 | 31 |
1997 | JapaneseDescription |
1998 | nvarchar(400) |
1999 | 0 |
2000 | |
2001 | 0 |
2002 |
2003 | 32 |
2004 | TurkishDescription |
2005 | nvarchar(400) |
2006 | 0 |
2007 | |
2008 | 0 |
2009 |
2010 | 33 |
2011 | StartDate |
2012 | datetime |
2013 | 0 |
2014 | |
2015 | 0 |
2016 |
2017 | 34 |
2018 | EndDate |
2019 | datetime |
2020 | 0 |
2021 | |
2022 | 0 |
2023 |
2024 | 35 |
2025 | Status |
2026 | nvarchar(7) |
2027 | 0 |
2028 | |
2029 | 0 |
2030 |
2031 |
2032 | FactInternetSales
2033 |
2034 |
2035 | cid |
2036 | name |
2037 | type |
2038 | notnull |
2039 | dflt_value |
2040 | pk |
2041 |
2042 | 0 |
2043 | ProductKey |
2044 | int |
2045 | 1 |
2046 | |
2047 | 0 |
2048 |
2049 | 1 |
2050 | OrderDateKey |
2051 | int |
2052 | 1 |
2053 | |
2054 | 0 |
2055 |
2056 | 2 |
2057 | DueDateKey |
2058 | int |
2059 | 1 |
2060 | |
2061 | 0 |
2062 |
2063 | 3 |
2064 | ShipDateKey |
2065 | int |
2066 | 1 |
2067 | |
2068 | 0 |
2069 |
2070 | 4 |
2071 | CustomerKey |
2072 | int |
2073 | 1 |
2074 | |
2075 | 0 |
2076 |
2077 | 5 |
2078 | PromotionKey |
2079 | int |
2080 | 1 |
2081 | |
2082 | 0 |
2083 |
2084 | 6 |
2085 | CurrencyKey |
2086 | int |
2087 | 1 |
2088 | |
2089 | 0 |
2090 |
2091 | 7 |
2092 | SalesTerritoryKey |
2093 | int |
2094 | 1 |
2095 | |
2096 | 0 |
2097 |
2098 | 8 |
2099 | SalesOrderNumber |
2100 | nvarchar(20) |
2101 | 1 |
2102 | |
2103 | 1 |
2104 |
2105 | 9 |
2106 | SalesOrderLineNumber |
2107 | tinyint |
2108 | 1 |
2109 | |
2110 | 2 |
2111 |
2112 | 10 |
2113 | RevisionNumber |
2114 | tinyint |
2115 | 1 |
2116 | |
2117 | 0 |
2118 |
2119 | 11 |
2120 | OrderQuantity |
2121 | smallint |
2122 | 1 |
2123 | |
2124 | 0 |
2125 |
2126 | 12 |
2127 | UnitPrice |
2128 | money |
2129 | 1 |
2130 | |
2131 | 0 |
2132 |
2133 | 13 |
2134 | ExtendedAmount |
2135 | money |
2136 | 1 |
2137 | |
2138 | 0 |
2139 |
2140 | 14 |
2141 | UnitPriceDiscountPct |
2142 | float |
2143 | 1 |
2144 | |
2145 | 0 |
2146 |
2147 | 15 |
2148 | DiscountAmount |
2149 | float |
2150 | 1 |
2151 | |
2152 | 0 |
2153 |
2154 | 16 |
2155 | ProductStandardCost |
2156 | money |
2157 | 1 |
2158 | |
2159 | 0 |
2160 |
2161 | 17 |
2162 | TotalProductCost |
2163 | money |
2164 | 1 |
2165 | |
2166 | 0 |
2167 |
2168 | 18 |
2169 | SalesAmount |
2170 | money |
2171 | 1 |
2172 | |
2173 | 0 |
2174 |
2175 | 19 |
2176 | TaxAmt |
2177 | money |
2178 | 1 |
2179 | |
2180 | 0 |
2181 |
2182 | 20 |
2183 | Freight |
2184 | money |
2185 | 1 |
2186 | |
2187 | 0 |
2188 |
2189 | 21 |
2190 | CarrierTrackingNumber |
2191 | nvarchar(25) |
2192 | 0 |
2193 | |
2194 | 0 |
2195 |
2196 | 22 |
2197 | CustomerPONumber |
2198 | nvarchar(25) |
2199 | 0 |
2200 | |
2201 | 0 |
2202 |
2203 | 23 |
2204 | OrderDate |
2205 | datetime |
2206 | 0 |
2207 | |
2208 | 0 |
2209 |
2210 | 24 |
2211 | DueDate |
2212 | datetime |
2213 | 0 |
2214 | |
2215 | 0 |
2216 |
2217 | 25 |
2218 | ShipDate |
2219 | datetime |
2220 | 0 |
2221 | |
2222 | 0 |
2223 |
2224 |
2225 |
2226 |
--------------------------------------------------------------------------------
/solutions/Chapter 1/create_documentation.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | sqlite3 ../../AdventureWorks.db << EOF
3 | .mode html
4 | .output adventureworks_docs_v2.html
5 | .headers on
6 | .print
7 | .print List of Database tables
8 | .print ------------
9 | .print
12 | .print DimCurrency
13 | .print
14 | .print
15 | PRAGMA table_info('DimCurrency');
16 | .print
17 | .print DimProductCategory
18 | .print
19 | .print
20 | PRAGMA table_info('DimProductCategory');
21 | .print
22 | .print FactInternetSalesReason
23 | .print
24 | .print
25 | PRAGMA table_info('FactInternetSales');
26 | .print
27 | .print DimCustomer
28 | .print
29 | .print
30 | PRAGMA table_info('DimCustomer');
31 | .print
32 | .print DimProductSubcategory
33 | .print
34 | .print
35 | PRAGMA table_info('DimProductSubCategory');
36 | .print
37 | .print FactResellerSales
38 | .print
39 | .print
40 | PRAGMA table_info('FactResellerSales');
41 | .print
42 | .print DimDate
43 | .print
44 | .print
45 | PRAGMA table_info('DimDate');
46 | .print
47 | .print DimPromotion
48 | .print
49 | .print
50 | PRAGMA table_info('DimPromotion');
51 | .print
52 | .print FactSurveyResponse
53 | .print
54 | .print
55 | PRAGMA table_info('FactSurveyResponse');
56 | .print
57 | .print DimDepartmentGroup
58 | .print
59 | .print
60 | PRAGMA table_info('DimDepartmentGroup');
61 | .print
62 | .print DimReseller
63 | .print
64 | .print
65 | PRAGMA table_info('DimReseller');
66 | .print
67 | .print DimEmployee
68 | .print
69 | .print
70 | PRAGMA table_info('DimEmployee');
71 | .print
72 | .print DimSalesReason
73 | .print
74 | .print
75 | PRAGMA table_info('DimSalesReason');
76 | .print
77 | .print DimGeography
78 | .print
79 | .print
80 | PRAGMA table_info('DimGeography');
81 | .print
82 | .print DimSalesTerritory
83 | .print
84 | .print
85 | PRAGMA table_info('DimSalesTerritory');
86 | .print
87 | .print DimOrganization
88 | .print
89 | .print
90 | PRAGMA table_info('DimOrganization');
91 | .print
92 | .print FactCurrencyRate
93 | .print
94 | .print
95 | PRAGMA table_info('FactCurrencyRate');
96 | .print
97 | .print DimProduct
98 | .print
99 | .print
100 | PRAGMA table_info('DimProduct');
101 | .print
102 | .print FactInternetSales
103 | .print
104 | .print
105 | PRAGMA table_info('FactInternetSales');
106 | .print
107 | .print
108 | .quit
109 | EOF
--------------------------------------------------------------------------------
/solutions/Chapter 2/Chapter 2.3.2.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | SELECT a.*, b.*
3 | from vwCUSTOMER_BIRTHDATE a
4 | INNER JOIN vwCUSTOMER_ADDRESS b
5 | ON a.CustomerKey = b.CustomerKey
--------------------------------------------------------------------------------
/solutions/Chapter 2/Chapter 2.3.3.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | SELECT a.*, b.* from
3 | DimCustomer a
4 | INNER JOIN
5 | FactInternetSales b
6 | ON a.CustomerKey = b.CustomerKey
7 | ORDER By a.CustomerKey;
--------------------------------------------------------------------------------
/solutions/Chapter 2/Chapter 2.3.4.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | SELECT a.*, b.* from
3 | FactInternetSales a
4 | INNER JOIN
5 | DimCustomer b
6 | ON a.CustomerKey = b.CustomerKey
7 | ORDER By a.CustomerKey;
--------------------------------------------------------------------------------
/solutions/Chapter 2/Chapter 2.3.5.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | SELECT a.*, b.*
3 | FROM
4 | FactInternetSales a
5 | INNER JOIN
6 | FactSurveyResponse b
7 | ON
8 | a.OrderDate = b.Date
--------------------------------------------------------------------------------
/solutions/Chapter 2/Chapter 2.3.sql:
--------------------------------------------------------------------------------
1 | -- SQLite Chapter 2.3
2 |
3 | -- create views
4 | create view vwCUSTOMER_ADDRESS
5 | as SELECT
6 | CustomerKey,
7 | AddressLine1,
8 | AddressLine2,
9 | GeographyKey
10 | FROM
11 | DimCustomer;
12 |
13 | CREATE view vwCUSTOMER_BIRTHDATE
14 | AS SELECT
15 | CustomerKey,
16 | Title,
17 | FirstName,
18 | MiddleName,
19 | LastName,
20 | NameStyle,
21 | BirthDate
22 | FROM
23 | DimCustomer;
24 |
25 |
--------------------------------------------------------------------------------
/solutions/Chapter 2/Chapter 2.6.1.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | Select E.EmployeeKey as EmployeeKey,
3 | E. FirstName as Employee_First_Name,
4 | E.LastName as Employee_Last_Name,
5 | M.FirstName as Manager_First_Name,
6 | M.LastName as Manager_Last_Name
7 | from DimEmployee E
8 | join DimEmployee M
9 | on E.ParentEmployeeKey = M.EmployeeKey;
--------------------------------------------------------------------------------
/solutions/Chapter 3/3.3.1.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | select C.CustomerKey,
3 | C.FirstName,
4 | C.LastName,
5 | A.EmailAddress,
6 | B.GeographyKey
7 | from
8 | DimCustomer C
9 | LEFT JOIN customer_email_a as A
10 | ON C.CustomerKey = A.CustomerKEY
11 | LEFT JOIN customer_address_us as B
12 | ON C.CustomerKey = B.CustomerKEY
--------------------------------------------------------------------------------
/solutions/Chapter 3/3.3.2.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | SELECT p.ProductKey,
3 | sum(s.SalesAmount) as Sum_of_Sales
4 | from DimProduct p
5 | left join FactInternetSales s using(ProductKey)
6 | group by p.ProductKey
7 |
--------------------------------------------------------------------------------
/solutions/Chapter 3/3.3.3.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | select DimProduct.ProductKey,
3 | DimProduct.EnglishProductName,
4 | FactInternetSales.OrderDate,
5 | FactInternetSales.OrderQuantity,
6 | FactInternetSales.SalesAmount
7 | from DimProduct
8 | left join FactInternetSales
9 | on DimProduct.ProductKey = FactInternetSales.ProductKey
10 | order by DimProduct.ProductKey;
--------------------------------------------------------------------------------
/solutions/Chapter 3/3.5.1.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | Select
3 | ResellerName,
4 | AddressLine1,
5 | AddressLine2,
6 | G.City,
7 | G.StateProvinceCode,
8 | G.PostalCode,
9 | G.CountryRegionCode,
10 | S.ProductKey,
11 | P.ProductSubcategoryKey,
12 | S.SalesAmount
13 | FROM
14 | DimReseller as R
15 | LEFT JOIN FactResellerSales as S
16 | ON R.ResellerKey = S.ResellerKey
17 | INNER JOIN DimGeography as G
18 | ON R.GeographyKey = G.GeographyKey
19 | LEFT JOIN DimProduct as P
20 | ON S.ProductKey = P.ProductKey
21 | WHERE G.CountryRegionCode = 'US'
22 | ORDER BY S.SalesAmount ASC
--------------------------------------------------------------------------------
/solutions/Chapter 4/4.3.1.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | Select p.ProductKey,
3 | p.EnglishProductName, s.*
4 | FROM DimProduct p
5 | LEFT JOIN FactInternetSales s ON p.ProductKey = s.ProductKey;
--------------------------------------------------------------------------------
/solutions/Chapter 4/4.3.2.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | SELECT
3 | p.ProductKey,
4 | p.EnglishProductName,
5 | s.*
6 | FROM FactInternetSales s
7 | LEFT JOIN DimProduct p ON p.ProductKey = s.ProductKey;
--------------------------------------------------------------------------------
/solutions/Chapter 4/4.3.3.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | select * from DimProduct where productkey = 480;
--------------------------------------------------------------------------------
/solutions/Chapter 4/4.5.1.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | SELECT a.*, b.*
3 | FROM
4 | customer_address_us a
5 | LEFT JOIN FactInternetSales b
6 | ON a.CustomerKey = b.CustomerKey
7 | UNION
8 | SELECT a.*, b.*
9 | FROM
10 | FactInternetSales b
11 | LEFT JOIN customer_address_us a
12 | ON a.CustomerKey = b.CustomerKey
--------------------------------------------------------------------------------
/solutions/Chapter 5/5.3.1.sql:
--------------------------------------------------------------------------------
1 | -- SQLite
2 | Select *
3 | from DimCurrency CROSS JOIN DimDepartmentGroup;
--------------------------------------------------------------------------------