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 5a261bc
Show file tree
Hide file tree
Showing 258 changed files with 21,095 additions and 0 deletions.
Binary file added 2542.pdf
Binary file not shown.
Binary file added 2543.pdf
Binary file not shown.
Binary file added 2551.pdf
Binary file not shown.
Binary file added 9781590595237.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -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.


15 changes: 15 additions & 0 deletions README.md
@@ -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.
1 change: 1 addition & 0 deletions SamplesForChapter02/Chapter02/ListColumnValues.bat
@@ -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
4 changes: 4 additions & 0 deletions SamplesForChapter02/Chapter02/ListColumnValues.sql
@@ -0,0 +1,4 @@
USE $(DBName)
GO
SELECT $(CName) FROM $(TName)
GO
2 changes: 2 additions & 0 deletions SamplesForChapter02/Chapter02/ListColumnValues2.bat
@@ -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
4 changes: 4 additions & 0 deletions SamplesForChapter02/Chapter02/SQLQuery1_f0218.sql
@@ -0,0 +1,4 @@
USE AdventureWorks
SELECT TOP 3 SalesPersonID, SalesYTD, SalesLastYear
FROM Sales.SalesPerson
ORDER BY SalesYTD DESC
16 changes: 16 additions & 0 deletions SamplesForChapter02/Chapter02/SQLQuery1_f0220.sql
@@ -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 added SamplesForChapter02/Chapter02/SQLQuery1_f0222.sql
Binary file not shown.
7 changes: 7 additions & 0 deletions SamplesForChapter02/Chapter02/SQLQuery2_f0219.sql
@@ -0,0 +1,7 @@
USE AdventureWorks

SELECT COUNT(SalesPersonID) AS 'Sales person'
FROM Sales.SalesPerson

SELECT COUNT(EmployeeID) AS 'Employees'
FROM HumanResources.Employee
11 changes: 11 additions & 0 deletions SamplesForChapter02/Chapter02/saved_data.txt
@@ -0,0 +1,11 @@
Changed database context to 'AdventureWorks'.
Sales person
------------
17

(1 rows affected)
Employees
-----------
290

(1 rows affected)
@@ -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 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 not shown.
Binary file not shown.
@@ -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
@@ -0,0 +1,4 @@
USE master
GO

EXEC sp_helpdb
@@ -0,0 +1,4 @@
USE master
GO

EXEC sp_helpdb @dbname = 'Northwind'
@@ -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)

@@ -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

@@ -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

@@ -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


@@ -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

0 comments on commit 5a261bc

Please sign in to comment.