Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 6, 2016
0 parents commit 73b67c8
Show file tree
Hide file tree
Showing 78 changed files with 2,370 additions and 0 deletions.
14 changes: 14 additions & 0 deletions 1244.html
@@ -0,0 +1,14 @@
Chapter 1: Being a DBA <br />
Chapter 2: SQL Server Installation <br />
Chapter 3: Creating a Database <br />
Chapter 4: DML and Querying <br />
Chapter 5: Basic Management Tasks <br />
Chapter 6: Security <br />
Chapter 7: Connectivity <br />
Chapter 8: Backup and Recovery <br />
Chapter 9: Replication <br />
Chapter 10: Development with Transact-SQL <br />
Chapter 11: Data Warehousing and Analysis <br />
Chapter 12: Data Transformation Services <br />
Chapter 13: Monitor, Profile, and Tune <br />
Chapter 14: Keeping the Plates Spinning
Binary file added 1450.pdf
Binary file not shown.
Binary file added 1451.pdf
Binary file not shown.
Binary file added 293x_CODE/Chap03code/Thumbs.db
Binary file not shown.
6 changes: 6 additions & 0 deletions 293x_CODE/Chap03code/alter_constraints.sql
@@ -0,0 +1,6 @@
USE TestDB1

ALTER TABLE Table2
ADD CONSTRAINT fk_table2_table1_idcol FOREIGN KEY (Table1_IDCol)
REFERENCES Table1(IDCol)
GO
24 changes: 24 additions & 0 deletions 293x_CODE/Chap03code/create_database.sql
@@ -0,0 +1,24 @@
CREATE DATABASE Test3
ON PRIMARY
(NAME = test3_primary_data1,
FILENAME = 'd:\sqldata\test3_primary_data1.mdf',
SIZE = 1MB,
MAXSIZE = 200MB,
FILEGROWTH = 10%),
(NAME = test3_primary_data2,
FILENAME = 'd:\sqldata\test3_primary_data2.ndf',
SIZE = 1MB,
MAXSIZE = 200MB,
FILEGROWTH = 10%),
FILEGROUP FG2
(NAME = test3_fg2_data1,
FILENAME = 'd:\sqldata\test3_fg2_data1.ndf',
SIZE = 1MB,
MAXSIZE = 200MB,
FILEGROWTH = 10%)

LOG ON (NAME = test3_log1,
FILENAME = 'd:\sqldata\test3_log1.ldf',
SIZE = 51MB,
MAXSIZE = 200MB,
FILEGROWTH = 10%)
28 changes: 28 additions & 0 deletions 293x_CODE/Chap03code/create_table.sql
@@ -0,0 +1,28 @@
use Test3

CREATE TABLE Table2
(
IDCol int identity(1,1) PRIMARY KEY,
Table1_IDCol int NULL,
VarCharCol varchar(255) NOT NULL,
)
GO


CREATE DATABASE TestDB1
CREATE TABLE Table1
(
IDCol int identity(1,1) PRIMARY KEY,
Table1_IDCol int NULL,
VarCharCol varchar(255) NOT NULL,
DateCol datetime NOT NULL,
MoneyCol money NULL
)

CREATE TABLE Table2
(
IDCol int identity(1,1) PRIMARY KEY,
Table1_IDCol int NULL,
VarCharCol varchar(255) NOT NULL
)
GO
13 changes: 13 additions & 0 deletions 293x_CODE/Chap04code/create_example_tables.sql
@@ -0,0 +1,13 @@
USE Northwind

CREATE TABLE Food_Table
(
Food_ID INT PRIMARY KEY,
Food_Name VARCHAR(255)
)

CREATE TABLE Group_Table
(
Group_ID INT PRIMARY KEY,
Group_Name VARCHAR(255)
)
20 changes: 20 additions & 0 deletions 293x_CODE/Chap04code/create_full_text_index.sql
@@ -0,0 +1,20 @@
USE Northwind

EXEC sp_fulltext_database 'enable'
GO


USE Northwind
EXEC sp_fulltext_catalog 'NorthFTCatalog', 'create'
GO


USE Northwind
EXEC sp_fulltext_table 'dbo.Products',
'Create', 'NorthFTCatalog', 'PK_Products'
GO


USE Northwind
EXEC sp_fulltext_column 'dbo.Products', 'ProductName', 'add'
GO
1 change: 1 addition & 0 deletions 293x_CODE/Chap04code/cross_join.sql
@@ -0,0 +1 @@
SELECT * FROM Food_Table CROSS JOIN Group_Table
9 changes: 9 additions & 0 deletions 293x_CODE/Chap04code/deleting_data.sql
@@ -0,0 +1,9 @@
USE Northwind

SELECT Food_ID, Food_Name FROM Food_Table

DELETE Food_Table WHERE Food_Name='Steak'

SELECT Food_ID, Food_Name FROM Food_Table

INSERT Food_Table(Food_ID, Food_Name) VALUES(2, 'Steak')
23 changes: 23 additions & 0 deletions 293x_CODE/Chap04code/full_text_population.sql
@@ -0,0 +1,23 @@
--full population
EXEC sp_fulltext_catalog 'NorthFTCatalog', 'start_full'

EXEC sp_fulltext_table 'dbo.Products', 'start_full'


/*
--incremental population
USE Northwind
ALTER TABLE Products
ADD TimeStampCol timestamp
EXEC sp_fulltext_table 'dbo.Products', 'start_full'
UPDATE Products
SET ProductName='Marmite Spread' WHERE ProductID=63
UPDATE Products
SET ProductName='Canterbury Beer' WHERE ProductID=60
EXEC sp_fulltext_table 'dbo.Products','start_incremental'
*/
3 changes: 3 additions & 0 deletions 293x_CODE/Chap04code/inner_join.sql
@@ -0,0 +1,3 @@
SELECT * FROM Food_Table
INNER JOIN Group_Table ON Food_Table.Food_ID =
Group_Table.Group_ID
10 changes: 10 additions & 0 deletions 293x_CODE/Chap04code/multiple_predicates.sql
@@ -0,0 +1,10 @@
USE Northwind

SELECT Food_ID, Food_Name FROM Food_Table
WHERE Food_ID>1 AND (Food_Name='Steak' OR Food_Name='Milk')

/*
SELECT CustomerID, ContactName, City, PostalCode, Country
FROM Customers
WHERE City='London' OR (Country='Germany' AND PostalCode='80805')
*/
3 changes: 3 additions & 0 deletions 293x_CODE/Chap04code/ordering_data.sql
@@ -0,0 +1,3 @@
USE Northwind

SELECT Food_ID, Food_Name FROM Food_Table ORDER BY Food_Name
19 changes: 19 additions & 0 deletions 293x_CODE/Chap04code/outer_join.sql
@@ -0,0 +1,19 @@
--left outer join
SELECT * FROM Food_Table LEFT OUTER JOIN Group_Table ON
Food_Table.Food_ID = Group_Table.Group_ID


/*
--right outer join
SELECT * FROM
Food_Table RIGHT OUTER JOIN Group_Table ON
Food_Table.Food_ID = Group_Table.Group_ID
*/


/*
--full outer join
SELECT *FROM
Food_Table FULL OUTER JOIN Group_Table ON
Food_Table.Food_ID = Group_Table.Group_ID
*/
15 changes: 15 additions & 0 deletions 293x_CODE/Chap04code/querying_full_text.sql
@@ -0,0 +1,15 @@
--full-text query
SELECT * FROM Products
WHERE CONTAINS(ProductName, '"Syrup" OR "Cran*"')

--full-text query returned in a table
SELECT * FROM Products
WHERE CONTAINSTABLE(ProductName, '"Syrup" OR "Cran*"')

--freetext
SELECT * FROM Products
WHERE FREETEXT(ProductName,'Syrup Sauce')

--freetext table
SELECT * FROM Products
WHERE FREETEXTTABLE(ProductName,'Syrup Sauce')
19 changes: 19 additions & 0 deletions 293x_CODE/Chap04code/simple_insert.sql
@@ -0,0 +1,19 @@
USE Northwind

INSERT Food_Table(Food_ID, Food_Name) VALUES(1, 'Bread')

INSERT Food_Table(Food_ID, Food_Name) VALUES(2, 'Steak')

INSERT Food_Table(Food_Id, Food_Name) VALUES(3, 'Milk')
GO



USE Northwind

INSERT Group_Table(Group_ID, Group_Name) VALUES(1, 'Grains')

INSERT Group_Table(Group_ID, Group_Name) VALUES(5, 'Meat')

INSERT Group_Table(Group_ID, Group_Name) VALUES(3, 'Dairy')
GO
6 changes: 6 additions & 0 deletions 293x_CODE/Chap04code/update.sql
@@ -0,0 +1,6 @@
SELECT ContactName FROM Customers WHERE CustomerID='FRANR'

UPDATE Customers SET ContactName='Linda Glucina'
WHERE CustomerID='FRANR'

SELECT ContactName FROM Customers WHERE CustomerID='FRANR'
17 changes: 17 additions & 0 deletions 293x_CODE/Chap04code/using_an_index.sql
@@ -0,0 +1,17 @@
SELECT UnitPrice, Quantity FROM [Order Details]
WHERE Quantity BETWEEN 10 AND 11 AND UnitPrice > 50

/*
CREATE NONCLUSTERED INDEX ix_orderdetails_productid
ON [Order Details](UnitPrice, Quantity)
*/


/*
SELECT UnitPrice, Quantity FROM [Order Details]
WHERE Quantity BETWEEN 10 AND 11 AND UnitPrice > 50
*/

/*
DROP INDEX [Order Details].ix_orderdetails_productid
*/
30 changes: 30 additions & 0 deletions 293x_CODE/Chap04code/using_wildcard.sql
@@ -0,0 +1,30 @@
USE Northwind

SELECT CustomerID, ContactName, City, PostalCode, Country
FROM Customers WHERE City LIKE 'L%'

/*
SELECT CustomerID, ContactName, City, PostalCode, Country
FROM Customers WHERE City LIKE '[ABC]%'
*/


/*
SELECT CustomerID, ContactName, City, PostalCode, Country
FROM Customers WHERE City LIKE '[A-C]%'
*/


/*
SELECT CustomerID, ContactName, City, PostalCode, Country
FROM Customers WHERE City LIKE '[^ABC]%'
*/


/*
SELECT CustomerID, ContactName, City, PostalCode, Country
FROM Customers WHERE City LIKE '_[a]%'
*/
8 changes: 8 additions & 0 deletions 293x_CODE/Chap05code/add_alert.sql
@@ -0,0 +1,8 @@
EXEC msdb..sp_add_alert @name = 'Alert: Object not found',
@severity = 11

/*
EXEC msdb..sp_add_notification 'Alert: Object not found',
'SuperDBA', 1
*/
41 changes: 41 additions & 0 deletions 293x_CODE/Chap05code/add_job.sql
@@ -0,0 +1,41 @@
DECLARE @JobID BINARY(16)

EXEC msdb.dbo.sp_add_job @job_id = @JobID OUTPUT ,
@job_name = 'Run DBCC on Northwind',
@enabled = 1, -- Active
@owner_login_name = 'sa',
@notify_level_eventlog = 2,
@notify_level_email = 2,
@notify_email_operator_name = 'SuperDBA'

SELECT @JobID

GO



EXEC msdb.dbo.sp_add_jobstep @job_name = 'Run DBCC on
Northwind',
@step_name = 'Run DBCC CheckDB on
Northwind',
@command = 'DBCC CheckDB
(''Northwind'')',
@subsystem = 'TSQL',
@output_file_name = 'C: \
DBCCResult.txt'


GO



EXEC msdb.dbo.sp_add_jobschedule @job_name = 'Run DBCC on
Northwind',
@name = 'Run DBCC Weekly',
@freq_type = 8, -- Weekly
@freq_interval = 2, -- Monday
@active_start_time = 40000,
@freq_recurrence_factor = 1
-- Every week

GO
1 change: 1 addition & 0 deletions 293x_CODE/Chap05code/add_operator.sql
@@ -0,0 +1 @@
EXEC msdb..sp_add_operator @name = 'SuperDBA', @email_address = 'superdba@mycompanyname.xyz'
8 changes: 8 additions & 0 deletions 293x_CODE/Chap05code/db_restore.sql
@@ -0,0 +1,8 @@
RESTORE DATABASE Northwind2
FROM DISK = 'C:\Program Files\Microsoft SQL Server
\MSSQL\BACKUP\Northwind.bak'
WITH
MOVE 'Northwind_log' TO 'C:\Program Files\
Microsoft SQL Server\MSSQL\data\Northwind2_log.ldf',
MOVE 'Northwind' TO 'C:\Program Files\
Microsoft SQL Server\MSSQL\data\Northwind2.mdf'
3 changes: 3 additions & 0 deletions 293x_CODE/Chap05code/when_db_backedup.sql
@@ -0,0 +1,3 @@
SELECT MAX(backup_finish_date)
FROM msdb..backupset
WHERE type = 'D' AND database_name = 'Northwind'
Binary file added 293x_CODE/Chap07code/7053_07_51.bmp
Binary file not shown.
31 changes: 31 additions & 0 deletions 293x_CODE/Chap07code/CreateADONetConnection/AssemblyInfo.vb
@@ -0,0 +1,31 @@
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("")>
<Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTrademark("")>
<Assembly: CLSCompliant(True)>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("B16F5997-381D-454F-BCDA-AF3B9F6AAA43")>

' Version information for an assembly consists of the following four values:
'
' Major Version
' Minor Version
' Build Number
' Revision
'
' You can specify all the values or you can default the Build and Revision Numbers
' by using the '*' as shown below:

<Assembly: AssemblyVersion("1.0.*")>

0 comments on commit 73b67c8

Please sign in to comment.