Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Apress
committed
Oct 6, 2016
0 parents
commit 73b67c8
Showing
78 changed files
with
2,370 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
USE TestDB1 | ||
|
||
ALTER TABLE Table2 | ||
ADD CONSTRAINT fk_table2_table1_idcol FOREIGN KEY (Table1_IDCol) | ||
REFERENCES Table1(IDCol) | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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%) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SELECT * FROM Food_Table CROSS JOIN Group_Table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT * FROM Food_Table | ||
INNER JOIN Group_Table ON Food_Table.Food_ID = | ||
Group_Table.Group_ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
USE Northwind | ||
|
||
SELECT Food_ID, Food_Name FROM Food_Table ORDER BY Food_Name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]%' | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
EXEC msdb..sp_add_operator @name = 'SuperDBA', @email_address = 'superdba@mycompanyname.xyz' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SELECT MAX(backup_finish_date) | ||
FROM msdb..backupset | ||
WHERE type = 'D' AND database_name = 'Northwind' |
Binary file not shown.
31 changes: 31 additions & 0 deletions
31
293x_CODE/Chap07code/CreateADONetConnection/AssemblyInfo.vb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.*")> |
Oops, something went wrong.