Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 16, 2016
0 parents commit 58b5e7f
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 0 deletions.
Binary file added 9781430243953.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AWMini_Azure.zip
Binary file not shown.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2012 Scott Klein and Herve Roggero

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 [*Pro SQL Database for Windows Azure*](http://www.apress.com/9781430243953) by Scott Klein and Herve Roggero (Apress, 2012).

![Cover image](9781430243953.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.
Binary file added ch03/CreateContactTable.sql
Binary file not shown.
Binary file added ch03/SQLAzureSecurity.zip
Binary file not shown.
92 changes: 92 additions & 0 deletions ch03/Security.sql
@@ -0,0 +1,92 @@
/*
Script: Security.sql
Purpose: Create a database for security examples
Copyright: BlueSyntax 2010
Comments: You may reuse, modify and distribute this code at will.
*/

-- ASSUMPTION: YOU MUST HAVE CREATED A DATABASE ALREADY.
-- If you are running in SQL Azure, connect to the master database and run a CREATE DATABASE statement
-- Then reconnect to the new database and run this script.

IF ((SELECT DB_NAME()) = 'master')
BEGIN

Print 'You should not be running this script on the master database.'
Print 'You must be connected to a user database to run this script.'
return
END

-- DROP TABLE UserProperties
IF (NOT Exists(SELECT * FROM sys.sysobjects WHERE Name = 'UserProperties' AND Type = 'U'))
CREATE TABLE UserProperties
(
ID int identity(1,1) PRIMARY KEY, -- identity of the record
PropertyName nvarchar(255) NOT NULL, -- name of the property
Value varbinary(max) NOT NULL, -- encrypted value
Vector binary(16) NOT NULL, -- vector of the encrypted value
LastUpdated datetime NOT NULL, -- date of last modification
Token binary(32) NOT NULL -- record hash
)

GO

IF (Exists(SELECT * FROM sys.sysobjects WHERE Name = 'proc_SaveProperty' AND Type = 'P'))
DROP PROC proc_SaveProperty

GO

-- SELECT * FROM UserProperties
CREATE PROC proc_SaveProperty
@name nvarchar(255),
@value varbinary(max),
@vector binary(16),
@lastUpdated datetime,
@hash binary(32)
AS

IF (Exists(SELECT * FROM UserProperties WHERE PropertyName = @name))
BEGIN
UPDATE UserProperties SET
Value = @value,
Vector = @vector,
LastUpdated = @lastUpdated,
Token = @hash
WHERE
PropertyName = @name
END
ELSE
BEGIN
INSERT INTO UserProperties
(PropertyName, Value, Vector, LastUpdated, Token)
VALUES (
@name,
@value,
@vector,
@lastUpdated,
@hash )
END


SELECT HASHBYTES('sha1', 'MySecret')


/*
-- 1 Create the schema with DBO ownership
CREATE SCHEMA MyReadOnlySchema AUTHORIZATION DBO
-- 2 Move the schema ownership of the table under the new schema
ALTER SCHEMA MyReadOnlySchema TRANSFER DBO.UserProperties
-- 3 Set the default schema of the user to the new schema
ALTER USER MyTestLoginUser WITH DEFAULT_SCHEMA = MyReadOnlySchema
-- 4 GRANT SELECT on the schema to the user
GRANT SELECT ON SCHEMA :: MyReadOnlySchema TO MyTestLoginUser
*/


Binary file added ch05/AWMini.zip
Binary file not shown.
52 changes: 52 additions & 0 deletions ch11/Tuning.sql
@@ -0,0 +1,52 @@

IF (Exists(SELECT * FROM sysobjects WHERE name = 'TestUsers' AND xtype = 'U'))
BEGIN
DROP TABLE TestUsers
DROP TABLE TestAgeGroup
DROP TABLE TestUserType
END
GO

CREATE TABLE TestUsers
(
ID int identity(1,1) PRIMARY KEY,
Name nvarchar(255),
UserType int DEFAULT (0),
AgeGroup int DEFAULT (0)
)
CREATE TABLE TestAgeGroup
(
ID int identity(1,1) PRIMARY KEY,
AgeGroup int NOT NULL,
AgeKey nvarchar(10) NOT NULL
)
CREATE TABLE TestUserType
(
ID int identity(1,1) PRIMARY KEY,
UserType int NOT NULL,
UserTypeKey nvarchar(10) NOT NULL
)
GO

INSERT INTO TestAgeGroup VALUES (0, 'Old')
INSERT INTO TestAgeGroup VALUES (1, 'Young')
INSERT INTO TestUserType VALUES (0, 'Admin')
INSERT INTO TestUserType VALUES (1, 'Manager')
INSERT INTO TestUserType VALUES (2, 'Standard')

DECLARE @i INT
DECLARE @name NVARCHAR(255)
DECLARE @userType INT
DECLARE @ageGroup INT

SET @i = 100

WHILE (@i > 0)
BEGIN
SET @name = 'user ' + CAST(@i AS nvarchar(10))
IF (@i > 75) SET @userType = 1 ELSE SET @userType = 0
IF (@i > 50) SET @ageGroup = 1 ELSE SET @ageGroup = 0
INSERT INTO TestUsers VALUES (@name, @userType, @ageGroup)
SET @i = @i - 1
END

14 changes: 14 additions & 0 deletions contributing.md
@@ -0,0 +1,14 @@
# Contributing to Apress Source Code

Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers.

## How to Contribute

1. Make sure you have a GitHub account.
2. Fork the repository for the relevant book.
3. Create a new branch on which to make your change, e.g.
`git checkout -b my_code_contribution`
4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted.
5. Submit a pull request.

Thank you for your contribution!

0 comments on commit 58b5e7f

Please sign in to comment.