From 739381e36169daa2171e4bf4d60cbcc213e8d46d Mon Sep 17 00:00:00 2001 From: TexanInParis Date: Wed, 8 Jun 2016 11:35:03 +0200 Subject: [PATCH] Sample files --- .../Chapter 04/Listing 4.009.sql | 20 ++++++++++++++----- MySQL/Chapter 02/Listing 2.028.sql | 4 ++-- MySQL/Chapter 03/Listing 3.005.sql | 1 + MySQL/Chapter 04/Listing 4.007.sql | 2 +- MySQL/Chapter 04/Listing 4.008.sql | 6 +++--- MySQL/Chapter 04/Listing 4.009.sql | 8 ++++++-- 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Microsoft SQL Server/Chapter 04/Listing 4.009.sql b/Microsoft SQL Server/Chapter 04/Listing 4.009.sql index 9ec35a7..ca713f0 100644 --- a/Microsoft SQL Server/Chapter 04/Listing 4.009.sql +++ b/Microsoft SQL Server/Chapter 04/Listing 4.009.sql @@ -1,8 +1,15 @@ +-- Ensure you've run SalesOrdersStructure.sql +-- and SalesOrdersData.sql in the Sample Databases folder +-- in order to run this example. + -- NOTE: Sample table Students does not exist. CREATE DATABASE StudentsTest; GO +USE StudentsTest; +GO + CREATE TABLE Students ( StudentID int PRIMARY KEY NOT NULL, LastName varchar(50), @@ -11,9 +18,6 @@ CREATE TABLE Students ( ); GO -USE StudentsTest; -GO - SELECT Students.StudentID, Students.LastName, Students.FirstName, YEAR(GETDATE()) - YEAR(Students.BirthDate) - (CASE WHEN MONTH(Students.BirthDate) < MONTH(GETDATE()) @@ -24,9 +28,15 @@ SELECT Students.StudentID, Students.LastName, Students.FirstName, THEN 1 ELSE 0 END) AS Age FROM Students; - +GO + +-- Dummy USE to free up StudentsTest so it can be deleted. +USE SalesOrdersSample; +GO + DROP DATABASE StudentsTest; - +GO + --Similar code using EmpDOB in the Employees table in SalesOrdersSample -- Ensure you've run SalesOrdersStructure.sql -- and SalesOrdersData.sql in the Sample Databases folder diff --git a/MySQL/Chapter 02/Listing 2.028.sql b/MySQL/Chapter 02/Listing 2.028.sql index ba29d28..a664fc0 100644 --- a/MySQL/Chapter 02/Listing 2.028.sql +++ b/MySQL/Chapter 02/Listing 2.028.sql @@ -1,3 +1,3 @@ -Listing 2.28 shows how to create an index for case-sensitive RDBMS to allow case-insensitive queries. +-- Listing 2.28 shows how to create an index for case-sensitive RDBMS to allow case-insensitive queries. -Since MySQL Server is case-insensitive, there's no need to have this listing. \ No newline at end of file +-- Because MySQL Server is case-insensitive, there's no need to have this listing. \ No newline at end of file diff --git a/MySQL/Chapter 03/Listing 3.005.sql b/MySQL/Chapter 03/Listing 3.005.sql index d5e9738..3dc2cb8 100644 --- a/MySQL/Chapter 03/Listing 3.005.sql +++ b/MySQL/Chapter 03/Listing 3.005.sql @@ -1,6 +1,7 @@ -- Ensure you've run Ch03.20.01Structure.sql -- and Ch03.20.01Data.sql in the Sample Databases folder -- in order to run this example. +-- NOTE: MySQL doesn't allow "Dec" as a column name; Used "Decm" instead. USE Item19Example; diff --git a/MySQL/Chapter 04/Listing 4.007.sql b/MySQL/Chapter 04/Listing 4.007.sql index 7fc61e7..f639969 100644 --- a/MySQL/Chapter 04/Listing 4.007.sql +++ b/MySQL/Chapter 04/Listing 4.007.sql @@ -1,6 +1,6 @@ -- NOTE that these are code snippets that are not executable. ---(Replace a code with a word – two examples.) +-- (Replace a code with a word – two examples.) CASE Students.Gender WHEN 'M' THEN 'Male' ELSE 'Female' END CASE Students.Gender diff --git a/MySQL/Chapter 04/Listing 4.008.sql b/MySQL/Chapter 04/Listing 4.008.sql index 11e57ac..238747a 100644 --- a/MySQL/Chapter 04/Listing 4.008.sql +++ b/MySQL/Chapter 04/Listing 4.008.sql @@ -1,11 +1,11 @@ -- NOTE that some are code snippets that are not executable. ---(Generate a salutation based on gender and marital status.) +-- (Generate a salutation based on gender and marital status.) CASE WHEN Students.Gender = 'M' THEN 'Mr.' WHEN Students.MaritalStatus = 'S' THEN 'Ms.' ELSE 'Mrs.' END ---(Rate sales based by Product on quantity sold.) +-- (Rate sales based by Product on quantity sold.) Use Salesorderssample; SELECT Products.ProductNumber, Products.ProductName, @@ -27,7 +27,7 @@ CASE WHEN (SELECT SUM(QuantityOrdered) ELSE 'Excellent' END FROM Products; ---(Calculate raises based on position.) +-- (Calculate raises based on position.) CASE Staff.Title WHEN 'Instructor' THEN ROUND(Salary * 1.05, 0) diff --git a/MySQL/Chapter 04/Listing 4.009.sql b/MySQL/Chapter 04/Listing 4.009.sql index 3c2a0b3..5d050c6 100644 --- a/MySQL/Chapter 04/Listing 4.009.sql +++ b/MySQL/Chapter 04/Listing 4.009.sql @@ -1,6 +1,12 @@ +-- Ensure you've run SalesOrdersStructure.sql +-- and SalesOrdersData.sql in the Sample Databases folder +-- in order to run this example. + -- NOTE: Sample table Students does not exist. CREATE DATABASE StudentsTest; +USE StudentsTest; + CREATE TABLE Students ( StudentID int PRIMARY KEY NOT NULL, LastName varchar(50), @@ -8,8 +14,6 @@ CREATE TABLE Students ( BirthDate date ); -USE StudentsTest; - SELECT Students.StudentID, Students.LastName, Students.FirstName, YEAR(CURDATE()) - YEAR(Students.BirthDate) - CASE WHEN MONTH(Students.BirthDate) < MONTH(CURDATE())