Skip to content

Commit dc7d94b

Browse files
authored
Merge pull request #28659 from WilliamDAssafMSFT/20231004-cls-rls
20231004 fabric CLS RLS
2 parents 620db73 + cb3dbb3 commit dc7d94b

11 files changed

Lines changed: 330 additions & 202 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
author: WilliamDAssafMSFT
3+
ms.author: wiassaf
4+
ms.date: 10/04/2023
5+
ms.service: sql
6+
ms.topic: include
7+
---
8+
9+
[!INCLUDE [Applies to](../../includes/applies-md.md)] [!INCLUDE [SQL Server](_ssnoversion.md)] [!INCLUDE [ASDBMI](_asmi.md)] [!INCLUDE [Azure Synapse Analytics (serverless SQL pool only)](../../includes/applies-to-version/_asa-svrless-sqlpool-only.md)] [!INCLUDE [Fabric SQL Endpoint](../../includes/applies-to-version/_fabric-se.md)] [!INCLUDE [Fabric Data Warehouse](../../includes/applies-to-version/_fabric-dw.md)]
10+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
author: WilliamDAssafMSFT
3+
ms.author: wiassaf
4+
ms.date: 10/04/2023
5+
ms.service: sql
6+
ms.topic: include
7+
---
8+
9+
[!INCLUDE [Applies to](../../includes/applies-md.md)] [!INCLUDE [SQL Server 2016](_ss2016.md)] and later versions [!INCLUDE [Azure SQL Database](_asdb.md)] [!INCLUDE [Azure SQL Managed Instance](_asmi.md)] [!INCLUDE [Fabric SQL Endpoint](../../includes/applies-to-version/_fabric-se.md)] [!INCLUDE [Fabric Data Warehouse](../../includes/applies-to-version/_fabric-dw.md)]

docs/relational-databases/security/row-level-security.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Row-Level security"
3-
description: Learn how Row-Level security uses group membership or execution context to control access to rows in a database table in SQL Server.
2+
title: "Row-level security"
3+
description: Learn how row-level security uses group membership or execution context to control access to rows in a database table in SQL Server.
44
author: VanMSFT
55
ms.author: vanto
66
ms.reviewer: wiassaf
@@ -16,22 +16,25 @@ helpviewer_keywords:
1616
- "predicate based security"
1717
monikerRange: "=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current||=fabric"
1818
---
19-
# Row-Level security
19+
# Row-level security
2020

2121
[!INCLUDE [sql-asdb-asdbmi-asa-fabricse-fabricdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-fabricse-fabricdw.md)]
2222

2323
:::image type="content" source="media/row-level-security/row-level-security-graphic.png" alt-text="Decorative graphic of row level security.":::
2424

25-
Row-Level security enables you to use group membership or execution context to control access to rows in a database table.
25+
Row-level security (RLS) enables you to use group membership or execution context to control access to rows in a database table.
2626

27-
Row-Level security (RLS) simplifies the design and coding of security in your application. RLS helps you implement restrictions on data row access. For example, you can ensure that workers access only those data rows that are pertinent to their department. Another example is to restrict customers' data access to only the data relevant to their company.
27+
Row-level security simplifies the design and coding of security in your application. RLS helps you implement restrictions on data row access. For example, you can ensure that workers access only those data rows that are pertinent to their department. Another example is to restrict customers' data access to only the data relevant to their company.
2828

2929
The access restriction logic is located in the database tier rather than away from the data in another application tier. The database system applies the access restrictions every time that data access is attempted from any tier. This makes your security system more reliable and robust by reducing the surface area of your security system.
3030

3131
Implement RLS by using the [CREATE SECURITY POLICY](../../t-sql/statements/create-security-policy-transact-sql.md) [!INCLUDE [tsql](../../includes/tsql-md.md)] statement, and predicates created as [inline table-valued functions](../../relational-databases/user-defined-functions/create-user-defined-functions-database-engine.md).
3232

3333
Row-level security was first introduced to [!INCLUDE [sssql16-md](../../includes/sssql16-md.md)].
3434

35+
> [!NOTE]
36+
> This article is focused on [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] and Azure SQL platforms. For [!INCLUDE [fabric](../../includes/fabric.md)], see [Row-level security in Microsoft Fabric](/fabric/data-warehouse/row-level-security).
37+
3538
## <a id="Description"></a> Description
3639

3740
Row-level security (RLS) supports two types of security predicates:
@@ -685,7 +688,7 @@ DROP SCHEMA Sample;
685688

686689
We can demonstrate row-level security [!INCLUDE [fabricdw](../../includes/fabric-dw.md)] and [!INCLUDE [fabricse](../../includes/fabric-se.md)] in [!INCLUDE [fabric](../../includes/fabric.md)].
687690

688-
The following example creates sample tables that will work with [!INCLUDE [fabricdw](../../includes/fabric-dw.md)] in [!INCLUDE [fabric](../../includes/fabric.md)], but in [!INCLUDE [fabricse](../../includes/fabric-se.md)] use existing tables. In the [!INCLUDE [fabricse](../../includes/fabric-se.md)], you cannot `CREATE TABLE`, you can `CREATE SCHEMA`, `CREATE FUNCTION`, and `CREATE SECURITY POLICY`.
691+
The following example creates sample tables that will work with [!INCLUDE [fabricdw](../../includes/fabric-dw.md)] in [!INCLUDE [fabric](../../includes/fabric.md)], but in [!INCLUDE [fabricse](../../includes/fabric-se.md)] use existing tables. In the [!INCLUDE [fabricse](../../includes/fabric-se.md)], you cannot use `CREATE TABLE`, but you can use `CREATE SCHEMA`, `CREATE FUNCTION`, and `CREATE SECURITY POLICY`.
689692

690693
In this example, first create a schema `sales`, a table `sales.Orders`.
691694

@@ -723,7 +726,7 @@ Create a `Security` schema, a function `Security.tvf_securitypredicate`, and a s
723726
-- Creating schema for Security
724727
CREATE SCHEMA Security;
725728
GO
726-
729+
727730
-- Creating a function for the SalesRep evaluation
728731
CREATE FUNCTION Security.tvf_securitypredicate(@SalesRep AS nvarchar(50))
729732
RETURNS TABLE
@@ -745,13 +748,13 @@ After applying the security policy and creating the function, the users `Sales1@
745748

746749
## Related content
747750

748-
- [CREATE SECURITY POLICY (Transact-SQL)](../../t-sql/statements/create-security-policy-transact-sql.md)</br>
749-
- [ALTER SECURITY POLICY (Transact-SQL)](../../t-sql/statements/alter-security-policy-transact-sql.md)</br>
750-
- [DROP SECURITY POLICY (Transact-SQL)](../../t-sql/statements/drop-security-policy-transact-sql.md)</br>
751-
- [CREATE FUNCTION (Transact-SQL)](../../t-sql/statements/create-function-transact-sql.md)</br>
752-
- [SESSION_CONTEXT (Transact-SQL)](../../t-sql/functions/session-context-transact-sql.md)</br>
753-
- [sp_set_session_context (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-set-session-context-transact-sql.md)</br>
754-
- [sys.security_policies (Transact-SQL)](../../relational-databases/system-catalog-views/sys-security-policies-transact-sql.md)</br>
755-
- [sys.security_predicates (Transact-SQL)](../../relational-databases/system-catalog-views/sys-security-predicates-transact-sql.md)</br>
751+
- [CREATE SECURITY POLICY (Transact-SQL)](../../t-sql/statements/create-security-policy-transact-sql.md)
752+
- [ALTER SECURITY POLICY (Transact-SQL)](../../t-sql/statements/alter-security-policy-transact-sql.md)
753+
- [DROP SECURITY POLICY (Transact-SQL)](../../t-sql/statements/drop-security-policy-transact-sql.md)
754+
- [CREATE FUNCTION (Transact-SQL)](../../t-sql/statements/create-function-transact-sql.md)
755+
- [SESSION_CONTEXT (Transact-SQL)](../../t-sql/functions/session-context-transact-sql.md)
756+
- [sp_set_session_context (Transact-SQL)](../../relational-databases/system-stored-procedures/sp-set-session-context-transact-sql.md)
757+
- [sys.security_policies (Transact-SQL)](../../relational-databases/system-catalog-views/sys-security-policies-transact-sql.md)
758+
- [sys.security_predicates (Transact-SQL)](../../relational-databases/system-catalog-views/sys-security-predicates-transact-sql.md)
756759
- [Create User-defined Functions (Database Engine)](../../relational-databases/user-defined-functions/create-user-defined-functions-database-engine.md)
757760
- [GRANT Object Permissions (Transact-SQL)](../../t-sql/statements/grant-object-permissions-transact-sql.md)

docs/relational-databases/views/views.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,42 @@ title: "Views"
33
description: "Views"
44
author: WilliamDAssafMSFT
55
ms.author: wiassaf
6-
ms.date: "03/14/2017"
6+
ms.date: 10/04/2023
77
ms.service: sql
88
ms.subservice: table-view-index
99
ms.topic: conceptual
1010
helpviewer_keywords:
1111
- "views [SQL Server], about views"
12-
monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
12+
monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current||=fabric"
1313
---
1414
# Views
15-
[!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)]
15+
16+
[!INCLUDE [sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw.md)]
17+
1618
A view is a virtual table whose contents are defined by a query. Like a table, a view consists of a set of named columns and rows of data. Unless indexed, a view does not exist as a stored set of data values in a database. The rows and columns of data come from tables referenced in the query defining the view and are produced dynamically when the view is referenced.
1719

1820
A view acts as a filter on the underlying tables referenced in the view. The query that defines the view can be from one or more tables or from other views in the current or other databases. Distributed queries can also be used to define views that use data from multiple heterogeneous sources. This is useful, for example, if you want to combine similarly structured data from different servers, each of which stores data for a different region of your organization.
1921

20-
Views are generally used to focus, simplify, and customize the perception each user has of the database. Views can be used as security mechanisms by letting users access data through the view, without granting the users permissions to directly access the underlying base tables of the view. Views can be used to provide a backward compatible interface to emulate a table that used to exist but whose schema has changed. Views can also be used when you copy data to and from [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] to improve performance and to partition data.
22+
Views are generally used to focus, simplify, and customize the perception each user has of the database. Views can be used as security mechanisms by letting users access data through the view, without granting the users permissions to directly access the underlying base tables of the view. Views can be used to provide a backward compatible interface to emulate a table that used to exist but whose schema has changed. Views can also be used when you copy data to and from [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] to improve performance and to partition data.
2123

22-
## Types of Views
23-
Besides the standard role of basic user-defined views, [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] provides the following types of views that serve special purposes in a database.
24+
## Types of views
25+
26+
Besides the standard role of basic user-defined views, [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] provides the following types of views that serve special purposes in a database.
2427

25-
Indexed Views
28+
### Indexed views
29+
2630
An indexed view is a view that has been materialized. This means the view definition has been computed and the resulting data stored just like a table. You index a view by creating a unique clustered index on it. Indexed views can dramatically improve the performance of some types of queries. Indexed views work best for queries that aggregate many rows. They are not well-suited for underlying data sets that are frequently updated.
2731

28-
Partitioned Views
29-
A partitioned view joins horizontally partitioned data from a set of member tables across one or more servers. This makes the data appear as if from one table. A view that joins member tables on the same instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] is a local partitioned view.
32+
### Partitioned views
33+
34+
A partitioned view joins horizontally partitioned data from a set of member tables across one or more servers. This makes the data appear as if from one table. A view that joins member tables on the same instance of [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] is a local partitioned view.
3035

31-
System Views
32-
System views expose catalog metadata. You can use system views to return information about the instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] or the objects defined in the instance. For example, you can query the sys.databases catalog view to return information about the user-defined databases available in the instance. For more information, see [System Views &#40;Transact-SQL&#41;](../../t-sql/language-reference.md)
36+
### System views
37+
38+
System views expose catalog metadata. You can use system views to return information about the instance of [!INCLUDE [ssNoVersion](../../includes/ssnoversion-md.md)] or the objects defined in the instance. For example, you can query the `sys.databases` catalog view to return information about the user-defined databases available in the instance. For more information, see [System Views (Transact-SQL)](../../t-sql/language-reference.md).
3339

34-
## Common View Tasks
40+
## Common view tasks
41+
3542
The following table provides links to common tasks associated with creating or modifying a view.
3643

3744
|View Tasks|Topic|
@@ -44,7 +51,9 @@ monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-s
4451
|Describes how to return information about a view such as the view definition.|[Get Information About a View](../../relational-databases/views/get-information-about-a-view.md)|
4552
|Describes how to rename a view.|[Rename Views](../../relational-databases/views/rename-views.md)|
4653

47-
## See Also
48-
[Create Views over XML Columns](../../relational-databases/xml/create-views-over-xml-columns.md)
49-
[CREATE VIEW &#40;Transact-SQL&#41;](../../t-sql/statements/create-view-transact-sql.md)
50-
54+
## Related content
55+
56+
- [Create Views over XML Columns](../../relational-databases/xml/create-views-over-xml-columns.md)
57+
- [CREATE VIEW (Transact-SQL)](../../t-sql/statements/create-view-transact-sql.md)
58+
- [GRANT Object Permissions (Transact-SQL)](../../t-sql/statements/grant-object-permissions-transact-sql.md)
59+
- [Row-level security](../security/row-level-security.md)

docs/t-sql/functions/suser-name-transact-sql.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "SUSER_NAME returns the login identification name of the user."
44
author: VanMSFT
55
ms.author: vanto
66
ms.reviewer: randolphwest
7-
ms.date: 12/21/2022
7+
ms.date: 10/04/2023
88
ms.service: sql
99
ms.subservice: t-sql
1010
ms.topic: reference
@@ -21,11 +21,11 @@ helpviewer_keywords:
2121
- "names [SQL Server], logins"
2222
dev_langs:
2323
- "TSQL"
24-
monikerRange: "= azure-sqldw-latest || >= sql-server-2016 || >= sql-server-linux-2017 || = azuresqldb-mi-current"
24+
monikerRange: "= azure-sqldw-latest || >= sql-server-2016 || >= sql-server-linux-2017 || = azuresqldb-mi-current || =fabric"
2525
---
2626
# SUSER_NAME (Transact-SQL)
2727

28-
[!INCLUDE [SQL Server Azure SQL Managed Instance](../../includes/applies-to-version/sql-asdbmi-asa-svrless-poolonly.md)]
28+
[!INCLUDE [SQL Server Azure SQL Managed Instance fabricse fabricdw](../../includes/applies-to-version/sql-asdbmi-asa-svrless-poolonly-fabricse-fabricdw.md)]
2929

3030
Returns the login identification name of the user.
3131

@@ -43,15 +43,15 @@ SUSER_NAME ( [ server_user_id ] )
4343

4444
#### *server_user_id*
4545

46-
The login identification number of the user. *server_user_id*, which is optional, is **int**. *server_user_id* can be the login identification number of any [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] login or Windows user or group that has permission to connect to an instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. When *server_user_id* isn't specified, the login identification name for the current user is returned. If the parameter contains the word NULL, it will return NULL.
46+
The login identification number of the user. *server_user_id*, which is optional, is **int**. *server_user_id* can be the login identification number of any [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] login or Windows user or group that has permission to connect to an instance of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. When *server_user_id* isn't specified, the login identification name for the current user is returned. If the parameter contains the word `NULL`, it returns `NULL`.
4747

4848
## Return type
4949

5050
**nvarchar(128)**
5151

5252
## Remarks
5353

54-
`SUSER_NAME` returns a login name only for a login that has an entry in the `syslogins` system table.
54+
`SUSER_NAME` returns a login name only for a login that has an entry in the `sys.server_principals` or `sys.sql_logins` catalog views.
5555

5656
`SUSER_NAME` can be used in a select list, in a WHERE clause, and anywhere an expression is allowed. Use parentheses after `SUSER_NAME`, even if no parameter is specified.
5757

@@ -60,13 +60,40 @@ The login identification number of the user. *server_user_id*, which is optional
6060
6161
## Examples
6262

63+
### A. Use SUSER_NAME
64+
6365
The following example returns the login identification name of the user with a login identification number of `1`.
6466

6567
```sql
6668
SELECT SUSER_NAME(1);
6769
```
6870

69-
## See also
71+
### B. Use SUSER_NAME without an ID
72+
73+
The following example finds the name of the current user without specifying an ID.
74+
75+
```sql
76+
SELECT SUSER_NAME();
77+
GO
78+
```
79+
80+
In SQL Server, here is the result set for a Microsoft Entra ID authenticated login:
81+
82+
```output
83+
contoso\username
84+
```
85+
86+
In Azure SQL Database and Microsoft Fabric, here is the result set for a Microsoft Entra ID authenticated login:
87+
88+
```output
89+
username@contoso.com
90+
```
91+
92+
## Related content
7093

94+
- [USER_NAME (Transact-SQL)](user-name-transact-sql.md)
95+
- [SUSER_SNAME (Transact-SQL)](suser-sname-transact-sql.md)
7196
- [SUSER_ID (Transact-SQL)](../../t-sql/functions/suser-id-transact-sql.md)
7297
- [Principals (Database Engine)](../../relational-databases/security/authentication-access/principals-database-engine.md)
98+
- [sys.server_principals (Transact-SQL)](../../relational-databases/system-catalog-views/sys-server-principals-transact-sql.md)
99+
- [sys.sql_logins (Transact-SQL)](../../relational-databases/system-catalog-views/sys-sql-logins-transact-sql.md)

0 commit comments

Comments
 (0)