Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 11, 2016
0 parents commit 64d63fa
Show file tree
Hide file tree
Showing 203 changed files with 1,499 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 1-59059-720-6/Chapter01/readme.txt
@@ -0,0 +1,6 @@
This chapter installs SQL Server and creates additional logon users

There is no code within this chapter

Robin Dewson
www.fat-belly.com
1 change: 1 addition & 0 deletions 1-59059-720-6/Chapter02/ReadMe.txt
@@ -0,0 +1 @@
No code
10 changes: 10 additions & 0 deletions 1-59059-720-6/Chapter03/CREATE DATABASE.sql
@@ -0,0 +1,10 @@
CREATE DATABASE ApressFinancial ON PRIMARY
( NAME = N'ApressFinancial',
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ApressFinancial.mdf' , SIZE = 3072KB ,
MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = 'ApressFinancial_log',
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ApressFinancial_log.ldf' ,
SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
COLLATE SQL_Latin1_General_CP1_CI_AS
GO
5 changes: 5 additions & 0 deletions 1-59059-720-6/Chapter04/1-CREATE AJMASON.sql
@@ -0,0 +1,5 @@
USE [master]
GO
CREATE LOGIN [XP-HOME\AJMason]
FROM WINDOWS
GO
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter04/2-ALTER LOGIN.sql
@@ -0,0 +1,3 @@
ALTER LOGIN [XP-HOME\AJMason]
WITH DEFAULT_DATABASE=ApressFinancial
GO
2 changes: 2 additions & 0 deletions 1-59059-720-6/Chapter04/3-CREATE USER.sql
@@ -0,0 +1,2 @@
CREATE USER [XP-HOME\AJMason]
FOR LOGIN [XP-HOME\AJMason]
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter04/4-CREATE SCHEMA Transactions.sql
@@ -0,0 +1,3 @@
USE ApressFinancial
GO
CREATE SCHEMA TransactionDetails AUTHORIZATION dbo
Binary file not shown.
10 changes: 10 additions & 0 deletions 1-59059-720-6/Chapter05/2-TransactionDetails.sql
@@ -0,0 +1,10 @@
CREATE TABLE TransactionDetails.Transactions
(TransactionId bigint IDENTITY(1,1) NOT NULL,
CustomerId bigint NOT NULL,
TransactionType int NOT NULL,
DateEntered datetime NOT NULL,
Amount numeric(18, 5) NOT NULL,
ReferenceDetails nvarchar(50) NULL,
Notes nvarchar(max) NULL,
RelatedShareId bigint NULL,
RelatedProductId bigint NOT NULL)
14 changes: 14 additions & 0 deletions 1-59059-720-6/Chapter05/3-TransactionTypes.sql
@@ -0,0 +1,14 @@
-- =========================================
-- Create table template
-- =========================================
USE ApressFinancial
GO
IF OBJECT_ID('TransactionDetails.TransactionTypes', 'U') IS NOT NULL
DROP TABLE TransactionDetails.TransactionTypes
GO
CREATE TABLE TransactionDetails.TransactionTypes(
TransactionTypeId int IDENTITY(1,1) NOT NULL,
TransactionDescription nvarchar(30) NOT NULL,
CreditType bit NOT NULL
)
GO
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter05/4-AlterTable.sql
@@ -0,0 +1,3 @@
ALTER TABLE TransactionDetails.TransactionTypes
ADD AffectCashBalance bit NULL
GO
33 changes: 33 additions & 0 deletions 1-59059-720-6/Chapter05/5-RemainingTables.sql
@@ -0,0 +1,33 @@
USE ApressFinancial
GO
CREATE TABLE CustomerDetails.CustomerProducts(
CustomerFinancialProductId bigint NOT NULL,
CustomerId bigint NOT NULL,
FinancialProductId bigint NOT NULL,
AmountToCollect money NOT NULL,
Frequency smallint NOT NULL,
LastCollected datetime NOT NULL,
LastCollection datetime NOT NULL,
Renewable bit NOT NULL
)
ON [PRIMARY]
GO
CREATE TABLE CustomerDetails.FinancialProducts(
ProductId bigint NOT NULL,
ProductName nvarchar(50) NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE ShareDetails.SharePrices(
SharePriceId bigint IDENTITY(1,1) NOT NULL,
ShareId bigint NOT NULL,
Price numeric(18, 5) NOT NULL,
PriceDate datetime NOT NULL
) ON [PRIMARY]
GO
CREATE TABLE ShareDetails.Shares(
ShareId bigint IDENTITY(1,1) NOT NULL,
ShareDesc nvarchar(50) NOT NULL,
ShareTickerId nvarchar(50) NULL,
CurrentPrice numeric(18, 5) NOT NULL
) ON [PRIMARY]
GO
10 changes: 10 additions & 0 deletions 1-59059-720-6/Chapter05/6-PrimaryKey.sql
@@ -0,0 +1,10 @@
ALTER TABLE CustomerDetails.Customers
ADD CONSTRAINT
PK_Customers PRIMARY KEY NONCLUSTERED
(
CustomerId
)
WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
GO
7 changes: 7 additions & 0 deletions 1-59059-720-6/Chapter05/7-foreignKey.sql
@@ -0,0 +1,7 @@
USE ApressFinancial
GO
ALTER TABLE TransactionDetails.Transactions
WITH NOCHECK
ADD CONSTRAINT FK_Transactions_Shares
FOREIGN KEY(RelatedShareId)
REFERENCES ShareDetails.Shares(ShareId)
8 changes: 8 additions & 0 deletions 1-59059-720-6/Chapter06/1-CustomerIndex.sql
@@ -0,0 +1,8 @@
USE ApressFinancial
GO
CREATE INDEX IX_CustomerProducts
ON CustomerDetails.CustomerProducts
(
CustomerId
)
GO
30 changes: 30 additions & 0 deletions 1-59059-720-6/Chapter06/2-OtherIndexes.sql
@@ -0,0 +1,30 @@
USE ApressFinancial
GO
CREATE UNIQUE CLUSTERED INDEX IX_TransactionTypes
ON TransactionDetails.TransactionTypes
(
TransactionTypeId ASC )
WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF,
DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = OFF)
ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX IX_Transactions_TType
ON TransactionDetails.Transactions
(
TransactionType ASC)
WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF,
DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = OFF)
ON [PRIMARY]
GO
ALTER TABLE TransactionDetails.TransactionTypes
ADD CONSTRAINT
PK_TransactionTypes PRIMARY KEY NONCLUSTERED
(
TransactionTypeId
)
WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
ON [PRIMARY]
GO
13 changes: 13 additions & 0 deletions 1-59059-720-6/Chapter06/3.Drop-Index.sql
@@ -0,0 +1,13 @@
USE ApressFinancial
GO
DROP INDEX IX_TransactionTypes ON TransactionDetails.TransactionTypes
GO
CREATE UNIQUE CLUSTERED INDEX IX_TransactionTypes
ON TransactionDetails.TransactionTypes
(
TransactionTypeId ASC
) WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF,
DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = OFF)
ON [PRIMARY]
GO
12 changes: 12 additions & 0 deletions 1-59059-720-6/Chapter06/4.ShareDetails.SharePrices-Index.sql
@@ -0,0 +1,12 @@
USE ApressFinancial
GO
CREATE UNIQUE CLUSTERED INDEX IX_SharePrices
ON ShareDetails.SharePrices
(
ShareId ASC,
PriceDate DESC,
Price
) WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF,
DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS =
OFF, DROP_EXISTING = OFF) ON [PRIMARY]
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter07/1.SetDBOffline.sql
@@ -0,0 +1,4 @@
USE master
GO
ALTER DATABASE ApressFinancial
SET OFFLINE
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter07/10.RestoreLogT-SQL.sql
@@ -0,0 +1,4 @@
-- Dont forget the FILE = 5 may be different
RESTORE LOG [ApressFinancial]
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ApressFinancial.bak' WITH FILE = 5,
NOUNLOAD, STATS = 10
Binary file added 1-59059-720-6/Chapter07/11.DetachTSQL.sql
Binary file not shown.
Binary file added 1-59059-720-6/Chapter07/12.AttachTSQL.sql
Binary file not shown.
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter07/2.SetDBOnline.sql
@@ -0,0 +1,4 @@
USE master
go
ALTER DATABASE ApressFinancial
SET ONLINE
6 changes: 6 additions & 0 deletions 1-59059-720-6/Chapter07/3.FullBackup.sql
@@ -0,0 +1,6 @@
BACKUP DATABASE ApressFinancial
TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ApressFinancial.bak'
WITH NAME = 'ApressFinancial-Full Database Backup',
SKIP,
NOUNLOAD,
STATS = 10
10 changes: 10 additions & 0 deletions 1-59059-720-6/Chapter07/4.DifferentialBackup.sql
@@ -0,0 +1,10 @@
BACKUP DATABASE ApressFinancial
TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ApressFinancial.bak'
WITH DIFFERENTIAL ,
DESCRIPTION = 'This is a differential backup',
RETAINDAYS = 60,
NAME = 'ApressFinancial-Differential Database Backup',
STATS = 10,
CHECKSUM,
CONTINUE_AFTER_ERROR
GO
17 changes: 17 additions & 0 deletions 1-59059-720-6/Chapter07/5.VerifyBackup.sql
@@ -0,0 +1,17 @@
DECLARE @BackupSet AS INT
SELECT @BackupSet = position
FROM msdb..backupset
WHERE database_name='ApressFinancial'
AND backup_set_id=
(SELECT MAX(backup_set_id)
FROM msdb..backupset
WHERE database_name='ApressFinancial' )
IF @BackupSet IS NULL
BEGIN
RAISERROR('Verify failed. Backup information for database''ApressFinancial'' not found.', 16, 1)
END
RESTORE VERIFYONLY
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ApressFinancial.bak'
WITH FILE = @BackupSet,
NOUNLOAD,
NOREWIND
6 changes: 6 additions & 0 deletions 1-59059-720-6/Chapter07/6.BackupTransactionLog.sql
@@ -0,0 +1,6 @@
BACKUP LOG ApressFinancial
TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ApressFinancial.bak'
WITH NAME = 'ApressFinancial-Transaction Log Backup',
SKIP,
NOUNLOAD,
STATS = 10
15 changes: 15 additions & 0 deletions 1-59059-720-6/Chapter07/7.SetRecoveryMode.sql
@@ -0,0 +1,15 @@
ALTER DATABASE ApressFinancial
SET RECOVERY FULL
GO
BACKUP DATABASE ApressFinancial TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ApressFinancial.bak'
WITH NAME = 'ApressFinancial-Full Database Backup' ,
SKIP,
NOUNLOAD,
STATS = 10
GO
BACKUP LOG ApressFinancial
TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ApressFinancial.bak'
WITH NAME = 'ApressFinancial-Transaction Log Backup' ,
SKIP,
NOUNLOAD,
STATS = 10
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter07/8.AlterTablePriorToTSQLRestore.sql
@@ -0,0 +1,4 @@
USE ApressFinancial
GO
ALTER TABLE ShareDetails.Shares
ADD DummyColumn varchar(30)
7 changes: 7 additions & 0 deletions 1-59059-720-6/Chapter07/9.RestoreT-SQLPart1.sql
@@ -0,0 +1,7 @@
USE Master
GO
-- Dont forget the FILE = 3 may be different
RESTORE DATABASE [ApressFinancial]
FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ApressFinancial.bak' WITH FILE = 3,
NORECOVERY, NOUNLOAD, REPLACE, STATS = 10
GO
10 changes: 10 additions & 0 deletions 1-59059-720-6/Chapter08/1.InsertShareDetails.Shares.sql
@@ -0,0 +1,10 @@
SET QUOTED_IDENTIFIER OFF
GO
INSERT INTO [ApressFinancial].[ShareDetails].[Shares]
([ShareDesc]
,[ShareTickerId]
,[CurrentPrice])
VALUES
("ACME'S HOMEBAKE COOKIES INC",
'AHCI',
2.34125)
2 changes: 2 additions & 0 deletions 1-59059-720-6/Chapter08/10.SELECT 3 Columns.sql
@@ -0,0 +1,2 @@
SELECT CustomerFirstName,CustomerLastName,ClearedBalance
FROM CustomerDetails.Customers
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter08/11.SELECTAlias.sql
@@ -0,0 +1,4 @@
SELECT CustomerFirstName As 'First Name',
CustomerLastName AS 'Surname',
ClearedBalance Balance
FROM CustomerDetails.Customers
12 changes: 12 additions & 0 deletions 1-59059-720-6/Chapter08/12.InsertShareDetails.Shares.sql
@@ -0,0 +1,12 @@
INSERT INTO ShareDetails.Shares
(ShareDesc, ShareTickerId,CurrentPrice)
VALUES ('FAT-BELLY.COM','FBC',45.20)
INSERT INTO ShareDetails.Shares
(ShareDesc, ShareTickerId,CurrentPrice)
VALUES ('NetRadio Inc','NRI',29.79)
INSERT INTO ShareDetails.Shares
(ShareDesc, ShareTickerId,CurrentPrice)
VALUES ('Texas Oil Industries','TOI',0.455)
INSERT INTO ShareDetails.Shares
(ShareDesc, ShareTickerId,CurrentPrice)
VALUES ('London Bridge Club','LBC',1.46)
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter08/13.SELECTSpecificCompany.sql
@@ -0,0 +1,3 @@
SELECT ShareDesc,CurrentPrice
FROM ShareDetails.Shares
WHERE ShareDesc = 'FAT-BELLY.COM'
7 changes: 7 additions & 0 deletions 1-59059-720-6/Chapter08/14.SELECTRanger.sql
@@ -0,0 +1,7 @@
SELECT ShareDesc,CurrentPrice
FROM ShareDetails.Shares
WHERE ShareDesc <> 'FAT-BELLY.COM'

SELECT ShareDesc,CurrentPrice
FROM ShareDetails.Shares
WHERE NOT ShareDesc = 'FAT-BELLY.COM'
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter08/15.SELECTRowcount.sql
@@ -0,0 +1,4 @@
SET ROWCOUNT 3
SELECT * FROM ShareDetails.Shares
SET ROWCOUNT 0
SELECT * FROM ShareDetails.Shares
5 changes: 5 additions & 0 deletions 1-59059-720-6/Chapter08/16.SELECTTopVRowcount.sql
@@ -0,0 +1,5 @@
SELECT TOP 3 * FROM ShareDetails.Shares
SET ROWCOUNT 3
SELECT TOP 2 * FROM ShareDetails.Shares
SET ROWCOUNT 2
SELECT TOP 3 * FROM ShareDetails.Shares
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter08/17.SELECTConcatenation.sql
@@ -0,0 +1,3 @@
SELECT CustomerFirstName + ' ' + CustomerLastName AS 'Name',
ClearedBalance Balance
FROM CustomerDetails.Customers
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter08/18.SELECTConcatenationALIAS.sql
@@ -0,0 +1,3 @@
SELECT LEFT(CustomerFirstName + ' ' + CustomerLastName,50) AS 'Name',
ClearedBalance Balance
FROM CustomerDetails.Customers
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter08/19.SELECTWithOrder.sql
@@ -0,0 +1,4 @@
SELECT LEFT(CustomerFirstName + ' ' + CustomerLastName,50) AS 'Name',
ClearedBalance Balance
FROM CustomerDetails.Customers
ORDER BY Balance
12 changes: 12 additions & 0 deletions 1-59059-720-6/Chapter08/2.FixupCustomerDetails.Customers.sql
@@ -0,0 +1,12 @@
DELETE FROM CustomerDetails.Customers
DBCC CHECKIDENT('CustomerDetails.Customers',RESEED,1)
INSERT INTO CustomerDetails.Customers
(CustomerTitleId,CustomerFirstName,CustomerOtherInitials,
CustomerLastName,AddressId,AccountNumber,AccountTypeId,
ClearedBalance,UnclearedBalance)
VALUES (1,'Vic',NULL,'McGlynn',111,87612311,1,4311.22,213.11)
INSERT INTO CustomerDetails.Customers
(CustomerTitleId,CustomerLastName,CustomerFirstName,
CustomerOtherInitials,AddressId,AccountNumber,AccountTypeId,
ClearedBalance,UnclearedBalance)
VALUES (3,'Mason','Jack',NULL,145,53431993,1,437.97,-10.56)
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter08/20.SELECTWithOrderDESC.sql
@@ -0,0 +1,4 @@
SELECT LEFT(CustomerFirstName + ' ' + CustomerLastName,50) AS 'Name',
ClearedBalance Balance
FROM CustomerDetails.Customers
ORDER BY Balance DESC
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter08/21.SELECTWithLIKE.sql
@@ -0,0 +1,3 @@
SELECT CustomerFirstName + ' ' + CustomerLastName
FROM CustomerDetails.Customers
WHERE CustomerLastName LIKE '%Glynn'
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter08/22.SELECTWithLIKE2.sql
@@ -0,0 +1,3 @@
SELECT CustomerFirstName + ' ' + CustomerLastName AS [Name]
FROM CustomerDetails.Customers
WHERE CustomerFirstName + ' ' + CustomerLastName LIKE '%n%'
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter08/23.SELECT-ERROR.sql
@@ -0,0 +1,3 @@
SELECT CustomerFirstName + ' ' + CustomerLastName AS [Name]
FROM CustomerDetails.Customers
WHERE [Name] LIKE '%n%'
4 changes: 4 additions & 0 deletions 1-59059-720-6/Chapter08/24.SELECTINTO.sql
@@ -0,0 +1,4 @@
SELECT CustomerFirstName + ' ' + CustomerLastName AS [Name],
ClearedBalance,UnclearedBalance
INTO CustTemp
FROM CustomerDetails.Customers
3 changes: 3 additions & 0 deletions 1-59059-720-6/Chapter08/25-UpdateToBrodie.sql
@@ -0,0 +1,3 @@
UPDATE CustomerDetails.Customers
SET CustomerLastName = 'Brodie'
WHERE CustomerId = 1
2 changes: 2 additions & 0 deletions 1-59059-720-6/Chapter08/26-RetrieveBrodie.sql
@@ -0,0 +1,2 @@
SELECT * FROM CustomerDetails.Customers
WHERE CustomerId = 1

0 comments on commit 64d63fa

Please sign in to comment.