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 5a261bc
Showing
258 changed files
with
21,095 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,27 @@ | ||
Freeware License, some rights reserved | ||
|
||
Copyright (c) 2006 Rick Dobson | ||
|
||
Permission is hereby granted, free of charge, to anyone obtaining a copy | ||
of this software and associated documentation files (the "Software"), | ||
to work with the Software within the limits of freeware distribution and fair use. | ||
This includes the rights to use, copy, and modify the Software for personal use. | ||
Users are also allowed and encouraged to submit corrections and modifications | ||
to the Software for the benefit of other users. | ||
|
||
It is not allowed to reuse, modify, or redistribute the Software for | ||
commercial use in any way, or for a user�s educational materials such as books | ||
or blog articles without prior permission from the copyright holder. | ||
|
||
The above copyright notice and this permission notice need to be included | ||
in all copies or substantial portions of the software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
|
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 @@ | ||
#Apress Source Code | ||
|
||
This repository accompanies [*Beginning SQL Server 2005 Express Database Applications with Visual Basic Express and Visual Web Developer Express*](http://www.apress.com/9781590595237) by Rick Dobson (Apress, 2006). | ||
|
||
![Cover image](9781590595237.jpg) | ||
|
||
Download the files as a zip using the green button, or clone the repository to your machine using Git. | ||
|
||
##Releases | ||
|
||
Release v1.0 corresponds to the code in the published book, without corrections or updates. | ||
|
||
##Contributions | ||
|
||
See the file Contributing.md for more information on how you can contribute to this repository. |
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 @@ | ||
sqlcmd -S .\sqlexpress -v DBName = "Northwind" CName = "CompanyName" TName = "Shippers" -i c:\prosseapps\chapter02\ListColumnValues.sql -o c:\prosseapps\chapter02\ColumnValuesOut.rpt |
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,4 @@ | ||
USE $(DBName) | ||
GO | ||
SELECT $(CName) FROM $(TName) | ||
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,2 @@ | ||
sqlcmd -S .\sqlexpress -v DBName = "Northwind" CName = "CompanyName" TName = "Shippers" -i c:\prosseapps\chapter02\ListColumnValues.sql -o c:\prosseapps\chapter02\ColumnValuesOut.rpt | ||
sqlcmd -S .\sqlexpress -v DBName = "Northwind" CName = "CompanyName" TName = "Customers" -i c:\prosseapps\chapter02\ListColumnValues.sql >> c:\prosseapps\chapter02\ColumnValuesOut.rpt |
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,4 @@ | ||
USE AdventureWorks | ||
SELECT TOP 3 SalesPersonID, SalesYTD, SalesLastYear | ||
FROM Sales.SalesPerson | ||
ORDER BY SalesYTD DESC |
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,16 @@ | ||
USE ProSSEApps | ||
|
||
--Original copied T-SQL FROM vContactName | ||
SELECT TOP (100) PERCENT dbo.Customer.CustomerName, dbo.CustomerContact.ContactName, dbo.CustomerContact.EmailAddr | ||
FROM dbo.Customer INNER JOIN | ||
dbo.CustomerContact ON dbo.Customer.CustomerID = dbo.CustomerContact.CustomerID | ||
WHERE (PATINDEX('%Church%', dbo.Customer.CustomerName) > 0) | ||
ORDER BY dbo.CustomerContact.ContactName DESC | ||
|
||
--Edited and re-formatted T-SQL FROM vContactName | ||
SELECT TOP (100) PERCENT dbo.Customer.CustomerName, | ||
dbo.CustomerContact.ContactName, dbo.CustomerContact.EmailAddr | ||
FROM dbo.Customer INNER JOIN dbo.CustomerContact | ||
ON dbo.Customer.CustomerID = dbo.CustomerContact.CustomerID | ||
WHERE (PATINDEX('%Church%', dbo.Customer.CustomerName) = 0) | ||
ORDER BY dbo.CustomerContact.ContactName DESC |
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,7 @@ | ||
USE AdventureWorks | ||
|
||
SELECT COUNT(SalesPersonID) AS 'Sales person' | ||
FROM Sales.SalesPerson | ||
|
||
SELECT COUNT(EmployeeID) AS 'Employees' | ||
FROM HumanResources.Employee |
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,11 @@ | ||
Changed database context to 'AdventureWorks'. | ||
Sales person | ||
------------ | ||
17 | ||
|
||
(1 rows affected) | ||
Employees | ||
----------- | ||
290 | ||
|
||
(1 rows affected) |
10 changes: 10 additions & 0 deletions
10
SamplesForChapter03/Chapter03/RevisedScriptsFigures/CopyDB_1aFiles.bat
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 @@ | ||
REM Erase old database and log files | ||
cd c:\prosseapps\chapter03\ | ||
ERASE Database_1a*.* | ||
|
||
REM Copy new database and log files to new folder | ||
REM and to .bak files in the same folder | ||
cd c:\program files\microsoft sql server\mssql.1\mssql\data\ | ||
copy Database_1a*.* c:\prosseapps\chapter03\ | ||
copy Database_1a.mdf Database_1a.bak | ||
copy Database_1a_log.ldf Database_1a_log.bak |
Binary file not shown.
Binary file added
BIN
+512 KB
SamplesForChapter03/Chapter03/RevisedScriptsFigures/Database_SP_log.ldf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+2.13 MB
SamplesForChapter03/Chapter03/RevisedScriptsFigures/ProSSEAppsCh04.mdf
Binary file not shown.
Binary file added
BIN
+768 KB
SamplesForChapter03/Chapter03/RevisedScriptsFigures/ProSSEAppsCh04_log.LDF
Binary file not shown.
4 changes: 4 additions & 0 deletions
4
SamplesForChapter03/Chapter03/RevisedScriptsFigures/RecoverDB_1aFiles.bat
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,4 @@ | ||
REM Rename backup files as database and log files | ||
cd c:\program files\microsoft sql server\mssql.1\mssql\data\ | ||
rename Database_1a.bak Database_1a.mdf | ||
rename Database_1a_log.bak Database_1a_log.ldf |
4 changes: 4 additions & 0 deletions
4
SamplesForChapter03/Chapter03/RevisedScriptsFigures/SQLQuery1_f0301.sql
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,4 @@ | ||
USE master | ||
GO | ||
|
||
EXEC sp_helpdb |
4 changes: 4 additions & 0 deletions
4
SamplesForChapter03/Chapter03/RevisedScriptsFigures/SQLQuery1_f0302.sql
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,4 @@ | ||
USE master | ||
GO | ||
|
||
EXEC sp_helpdb @dbname = 'Northwind' |
54 changes: 54 additions & 0 deletions
54
SamplesForChapter03/Chapter03/RevisedScriptsFigures/SQLQuery2_f0303_f0304.sql
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,54 @@ | ||
--List database names and is_auto_close_on values | ||
--on server instance | ||
USE master | ||
GO | ||
|
||
SELECT name, is_auto_close_on | ||
FROM sys.databases | ||
|
||
--Modify and restore autoclode database-level option | ||
--for the Northwind database | ||
USE master | ||
SELECT name, is_auto_close_on | ||
FROM sys.databases | ||
WHERE name = 'Northwind' | ||
GO | ||
sp_dboption 'Northwind', 'autoclose', 'FALSE' | ||
GO | ||
SELECT name, is_auto_close_on | ||
FROM sys.databases | ||
WHERE name = 'Northwind' | ||
GO | ||
sp_dboption 'Northwind', 'autoclose', 'True' | ||
GO | ||
SELECT name, is_auto_close_on | ||
FROM sys.databases | ||
WHERE name = 'Northwind' | ||
GO | ||
|
||
|
||
--List name and object_id from the sys.tables view for | ||
--@TBLName and matching name, column_id, and object_id | ||
--from the sys.columns view | ||
USE master | ||
GO | ||
|
||
DECLARE @DBName nvarchar(128) | ||
DECLARE @TBLName nvarchar(128) | ||
SET @DBName = N'Northwind' | ||
SET @TBLName = N'Shippers' | ||
|
||
SELECT name | ||
FROM sys.databases | ||
WHERE name = @DBName | ||
USE Northwind | ||
SELECT name, object_id | ||
FROM sys.tables | ||
WHERE name = @TBLName | ||
SELECT name, column_id, object_id | ||
FROM sys.columns | ||
WHERE object_id IN | ||
(SELECT object_id | ||
FROM sys.tables | ||
WHERE name = @TBLName) | ||
|
35 changes: 35 additions & 0 deletions
35
SamplesForChapter03/Chapter03/RevisedScriptsFigures/SQLQuery4_f0306_f0307_f0308.sql
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,35 @@ | ||
--Just specify database name | ||
EXEC sp_helpdb model | ||
CREATE DATABASE Database_2 | ||
EXEC sp_helpdb Database_2 | ||
DROP DATABASE Database_2 | ||
|
||
--Specify database name and primary | ||
--database file specification | ||
CREATE DATABASE Database_2 | ||
ON | ||
(NAME = Database_2_dat, | ||
FILENAME = 'c:\prosseapps\chapter03\database_2.mdf', | ||
SIZE = 2MB, | ||
MAXSIZE = 20, | ||
FILEGROWTH = 10%) | ||
EXEC sp_helpdb Database_2 | ||
DROP DATABASE Database_2 | ||
|
||
--Specify database and log file specifications | ||
CREATE DATABASE Database_2 | ||
ON PRIMARY | ||
(NAME = Database_2_dat, | ||
FILENAME = 'c:\prosseapps\chapter03\database_2dat.mdf', | ||
SIZE = 2MB, | ||
MAXSIZE = 20, | ||
FILEGROWTH = 10%) | ||
LOG ON | ||
(NAME = Database_2_log, | ||
FILENAME = 'c:\prosseapps\chapter03\database_2log.ldf', | ||
SIZE = 4MB, | ||
MAXSIZE = 10MB, | ||
FILEGROWTH = 20%) | ||
EXEC sp_helpdb Database_2 | ||
DROP DATABASE Database_2 | ||
|
48 changes: 48 additions & 0 deletions
48
SamplesForChapter03/Chapter03/RevisedScriptsFigures/SQLQuery5_f0310_f0311.sql
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,48 @@ | ||
--Copy database and log files for Database_1a from | ||
--c:\program files\microsoft sql server\mssql.1\mssql\data\ | ||
--to c:\prosseapps\chapter03\ and make .bak files for .mdf and .ldf | ||
--in c:\program files\microsoft sql server\mssql.1\mssql\data\ | ||
xp_cmdshell 'c:\prosseapps\chapter03\copydb_1afiles' | ||
GO | ||
--Look at databaes before adding a new one | ||
--Notice paths for database and log files of | ||
--Database_1a | ||
SELECT name, database_id FROM sys.databases | ||
EXEC sp_helpdb @dbname = N'Database_1a' | ||
GO | ||
--Create a new database (Database_1b) based on the | ||
--copied database and log files from Database_1a, | ||
--which was created originally as Database_1 | ||
CREATE DATABASE Database_1b | ||
ON PRIMARY (FILENAME = 'c:\prosseapps\chapter03\Database_1a.mdf') | ||
FOR ATTACH | ||
GO | ||
--See what happened after CREATE DATABASE...FOR ATTACH | ||
SELECT name, database_id FROM sys.databases | ||
EXEC sp_helpdb @dbname = N'Database_1b' | ||
GO | ||
--Drop Database_1b and delete unused log file | ||
DROP DATABASE Database_1b | ||
GO | ||
xp_cmdshell 'erase c:\prosseapps\chapter03\Database_1a_log.ldf' | ||
GO | ||
|
||
--See what happened to Database_1a after | ||
--dropping Database_1b | ||
EXEC sp_helpdb @dbname = N'Database_1a' | ||
|
||
--Now drop Database_1a and rename .bak files | ||
DROP DATABASE Database_1a | ||
GO | ||
xp_cmdshell 'c:\prosseapps\chapter03\recoverdb_1afiles' | ||
GO | ||
--Re-create Database_1a | ||
CREATE DATABASE Database_1a | ||
ON (FILENAME = | ||
'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Database_1a.mdf') | ||
FOR ATTACH | ||
GO | ||
SELECT name, database_id FROM sys.databases | ||
EXEC sp_helpdb @dbname = N'Database_1a' | ||
GO | ||
|
28 changes: 28 additions & 0 deletions
28
SamplesForChapter03/Chapter03/RevisedScriptsFigures/SQLQuery6_f0312.sql
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 @@ | ||
--repeat with FOR ATTACH sample with references to both | ||
--database and log files | ||
|
||
--Copy files | ||
xp_cmdshell 'c:\prosseapps\chapter03\copydb_1afiles' | ||
GO | ||
|
||
--Attach copied files | ||
CREATE DATABASE Database_1b | ||
ON PRIMARY (FILENAME = 'c:\prosseapps\chapter03\Database_1a.mdf') | ||
LOG ON (FILENAME = 'c:\prosseapps\chapter03\Database_1a_log.ldf') | ||
FOR ATTACH | ||
GO | ||
|
||
--Monitor results | ||
SELECT name, database_id FROM sys.databases | ||
EXEC sp_helpdb @dbname = N'Database_1b' | ||
GO | ||
|
||
--Clean up | ||
DROP DATABASE Database_1b | ||
GO | ||
xp_cmdshell 'erase "c:\program files\microsoft sql server\mssql.1\mssql\data\Database_1a*.bak"' | ||
GO | ||
EXEC sp_helpdb @dbname = N'Database_1a' | ||
GO | ||
|
||
|
63 changes: 63 additions & 0 deletions
63
SamplesForChapter03/Chapter03/RevisedScriptsFigures/SQLQuery7_f0313_f0314_f0315.sql
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,63 @@ | ||
--Create Database_2 | ||
CREATE DATABASE Database_2 | ||
ON PRIMARY | ||
(NAME = Database_2_dat, | ||
FILENAME = 'c:\prosseapps\chapter03\database_2dat.mdf', | ||
SIZE = 2MB, | ||
MAXSIZE = 20, | ||
FILEGROWTH = 10%) | ||
LOG ON | ||
(NAME = Database_2_log, | ||
FILENAME = 'c:\prosseapps\chapter03\database_2log.ldf', | ||
SIZE = 4MB, | ||
MAXSIZE = 10MB, | ||
FILEGROWTH = 20%) | ||
GO | ||
|
||
--Show database's autoclose setting; copy one database | ||
--file; then erase copy | ||
SELECT name, database_id, is_auto_close_on | ||
FROM sys.databases WHERE name = 'Database_2' | ||
DECLARE @str1 nvarchar(90) | ||
SET @str1 = 'copy c:\prosseapps\chapter03\database_2dat.mdf ' + | ||
'c:\prosseapps\chapter03\database_2dat.bak' | ||
EXEC master..xp_cmdshell @str1 | ||
SET @str1 = 'erase ' + | ||
'c:\prosseapps\chapter03\database_2dat.bak' | ||
EXEC master..xp_cmdshell @str1 | ||
GO | ||
|
||
|
||
--Detach database; then attach | ||
EXEC sp_detach_db @dbname = N'Database_2' | ||
GO | ||
--Show database is gone, but its files remain | ||
SELECT name | ||
FROM sys.databases WHERE name = 'Database_2' | ||
DECLARE @str1 nvarchar(90) | ||
SET @str1 = 'dir ' + | ||
'c:\prosseapps\chapter03\database_2*.*' | ||
EXEC master..xp_cmdshell @str1 | ||
GO | ||
|
||
--Create a new Database_2 by attaching files | ||
CREATE DATABASE Database_2 | ||
ON PRIMARY (FILENAME = 'c:\prosseapps\chapter03\Database_2dat.mdf') | ||
LOG ON (FILENAME = 'c:\prosseapps\chapter03\Database_2log.ldf') | ||
FOR ATTACH | ||
GO | ||
|
||
--Show database's autoclose setting | ||
SELECT name, database_id, is_auto_close_on | ||
FROM sys.databases WHERE name = 'Database_2' | ||
GO | ||
|
||
--With a database created via FOR ATTACH clause copy does not work | ||
DECLARE @str1 nvarchar(90) | ||
SET @str1 = 'copy c:\prosseapps\chapter03\database_2dat.mdf ' + | ||
'c:\prosseapps\chapter03\database_2dat.bak' | ||
EXEC master..xp_cmdshell @str1 | ||
GO | ||
|
||
--Clean up | ||
DROP DATABASE Database_2 |
Oops, something went wrong.