Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit c0a63e7

Browse files
authored
Merge pull request #6937 from MashaMSFT/20180823_chainstutorial
refreshed with adw2017 content (vsts 1223758)
2 parents aef6490 + 0cd94f5 commit c0a63e7

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

docs/relational-databases/tutorial-ownership-chains-and-context-switching.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,54 @@ helpviewer_keywords:
1818
- "ownership chains [SQL Server]"
1919
ms.assetid: db5d4cc3-5fc5-4cf5-afc1-8d4edc1d512b
2020
caps.latest.revision: 16
21-
author: "rothja"
22-
ms.author: "jroth"
21+
author: "MashaMSFT"
22+
ms.author: "mathoma"
2323
manager: craigg
2424
---
2525
# Tutorial: Ownership Chains and Context Switching
2626
[!INCLUDE[appliesto-ss-xxxx-xxxx-xxx-md](../includes/appliesto-ss-xxxx-xxxx-xxx-md.md)]
2727
This tutorial uses a scenario to illustrate [!INCLUDE[ssNoVersion](../includes/ssnoversion-md.md)] security concepts involving ownership chains and user context switching.
2828

2929
> [!NOTE]
30-
> To run the code in this tutorial you must have both Mixed Mode security configured and the [!INCLUDE[ssSampleDBobject](../includes/sssampledbobject-md.md)] database installed. For more information about Mixed Mode security, see [Choose an Authentication Mode](../relational-databases/security/choose-an-authentication-mode.md).
30+
> To run the code in this tutorial you must have both Mixed Mode security configured and the AdventureWorks2017 database installed. For more information about Mixed Mode security, see [Choose an Authentication Mode](../relational-databases/security/choose-an-authentication-mode.md).
3131
3232
## Scenario
33-
In this scenario, two users need accounts to access purchase order data stored in the [!INCLUDE[ssSampleDBobject](../includes/sssampledbobject-md.md)] database. The requirements are as follows:
33+
In this scenario, two users need accounts to access purchase order data stored in the AdventureWorks2017 database. The requirements are as follows:
3434

3535
- The first account (TestManagerUser) must be able to see all details in every purchase order.
36-
3736
- The second account (TestEmployeeUser) must be able to see the purchase order number, order date, shipping date, product ID numbers, and the ordered and received items per purchase order, by purchase order number, for items where partial shipments have been received.
38-
39-
- All other accounts must retain their current permissions.
40-
37+
- All other accounts must retain their current permissions.
4138
To fulfill the requirements of this scenario, the example is broken into four parts that demonstrate the concepts of ownership chains and context switching:
4239

43-
1. Configuring the environment.
44-
45-
2. Creating a stored procedure to access data by purchase order.
46-
40+
1. Configuring the environment.
41+
2. Creating a stored procedure to access data by purchase order.
4742
3. Accessing the data through the stored procedure.
48-
4943
4. Resetting the environment.
5044

51-
Each code block in this example is explained in line. To copy the complete example, see [Complete Example](#CompleteExample) at the end of this tutorial.
45+
Each code block in this example is explained in line. To copy the complete example, see [Complete Example](#CompleteExample) at the end of this tutorial.
46+
47+
## Prerequisites
48+
To complete this tutorial, you need SQL Server Management Studio, access to a server that's running SQL Server, and an AdventureWorks database.
49+
50+
- Install [SQL Server Management Studio](https://docs.microsoft.com/sql/ssms/download-sql-server-management-studio-ssms).
51+
- Install [SQL Server 2017 Developer Edition](https://www.microsoft.com/sql-server/sql-server-downloads).
52+
- Download [AdventureWorks2017 sample databases](https://docs.microsoft.com/sql/samples/adventureworks-install-configure).
53+
54+
For instructions on restoring a database in SQL Server Management Studio, see [Restore a database](https://docs.microsoft.com/sql/relational-databases/backup-restore/restore-a-database-backup-using-ssms).
5255

5356
## 1. Configure the Environment
54-
Use [!INCLUDE[ssManStudioFull](../includes/ssmanstudiofull-md.md)] and the following code to open the `AdventureWorks2012` database, and use the `CURRENT_USER` [!INCLUDE[tsql](../includes/tsql-md.md)] statement to check that the dbo user is displayed as the context.
57+
Use [!INCLUDE[ssManStudioFull](../includes/ssmanstudiofull-md.md)] and the following code to open the `AdventureWorks2017` database, and use the `CURRENT_USER` [!INCLUDE[tsql](../includes/tsql-md.md)] statement to check that the dbo user is displayed as the context.
5558

5659
```sql
57-
USE AdventureWorks2012;
60+
USE AdventureWorks2017;
5861
GO
5962
SELECT CURRENT_USER AS 'Current User Name';
6063
GO
6164
```
6265

6366
For more information about the CURRENT_USER statement, see [CURRENT_USER (Transact-SQL)](../t-sql/functions/current-user-transact-sql.md).
6467

65-
Use this code as the dbo user to create two users on the server and in the [!INCLUDE[ssSampleDBobject](../includes/sssampledbobject-md.md)] database.
68+
Use this code as the dbo user to create two users on the server and in the AdventureWorks2017 database.
6669

6770
```sql
6871
CREATE LOGIN TestManagerUser
@@ -174,6 +177,12 @@ SELECT *
174177
FROM Purchasing.PurchaseOrderDetail;
175178
GO
176179
```
180+
181+
The error that's returned:
182+
```
183+
Msg 229, Level 14, State 5, Line 6
184+
The SELECT permission was denied on the object 'PurchaseOrderHeader', database 'AdventureWorks2017', schema 'Purchasing'.
185+
```
177186

178187
Because the objects referenced by the stored procedure created in the last section are owned by `TestManagerUser` by virtue of the `Purchasing` schema ownership, `TestEmployeeUser` can access the base tables through the stored procedure. The following code, still using the `TestEmployeeUser` context, passes purchase order 952 as a parameter.
179188

@@ -217,7 +226,7 @@ Last Updated: Books Online
217226
Conditions: Execute as DBO or sysadmin in the AdventureWorks database
218227
Section 1: Configure the Environment
219228
*/
220-
USE AdventureWorks2012;
229+
USE AdventureWorks2017;
221230
GO
222231
SELECT CURRENT_USER AS 'Current User Name';
223232
GO

docs/relational-databases/tutorial-signing-stored-procedures-with-a-certificate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ To complete this tutorial, you need SQL Server Management Studio, access to a se
4343
- Install [SQL Server 2017 Developer Edition](https://www.microsoft.com/sql-server/sql-server-downloads).
4444
- Download [AdventureWorks2017 sample databases](https://docs.microsoft.com/sql/samples/adventureworks-install-configure).
4545

46-
Instructions for restoring databases in SSMS are here: [Restore a database](https://docs.microsoft.com/sql/relational-databases/backup-restore/restore-a-database-backup-using-ssms).
46+
For instructions on restoring a database in SQL Server Management Studio, see [Restore a database](https://docs.microsoft.com/sql/relational-databases/backup-restore/restore-a-database-backup-using-ssms).
4747

4848
## 1. Configure the Environment
4949
To set the initial context of the example, in [!INCLUDE[ssManStudioFull](../includes/ssmanstudiofull-md.md)] open a new Query and run the following code to open the Adventureworks2017 database. This code changes the database context to `AdventureWorks2012` and creates a new server login and database user account (`TestCreditRatingUser`), using a password.

0 commit comments

Comments
 (0)