<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Row level scrity &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/row-level-scrity/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Wed, 09 Aug 2017 06:55:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server 2016: Row Level Security by Example</title>
		<link>https://www.dbrnd.com/2017/08/sql-server-2016-row-level-security-by-example/</link>
					<comments>https://www.dbrnd.com/2017/08/sql-server-2016-row-level-security-by-example/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 16 Aug 2017 16:16:30 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[FILTER PREDICAT]]></category>
		<category><![CDATA[Row level scrity]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5876</guid>

					<description><![CDATA[<div><img width="573" height="255" src="https://www.dbrnd.com/wp-content/uploads/2016/08/PostgreSQLRowLevelSecurity.png" class="attachment-post-image size-post-image wp-post-image" alt="Postgre SQL Row Level Security" decoding="async" fetchpriority="high" srcset="https://www.dbrnd.com/wp-content/uploads/2016/08/PostgreSQLRowLevelSecurity.png 573w, https://www.dbrnd.com/wp-content/uploads/2016/08/PostgreSQLRowLevelSecurity-300x134.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/08/PostgreSQLRowLevelSecurity-150x67.png 150w" sizes="(max-width: 573px) 100vw, 573px" /></div>In this post, I am going to publish about The Row Level Security which is now a common feature of all new version of RDBMSs like SQL Server 2016, PostgreSQL 9.5. With the concept of Row Level Security, we can restrict the user for a particular set of records. Previously, we are doing this kind [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="573" height="255" src="https://www.dbrnd.com/wp-content/uploads/2016/08/PostgreSQLRowLevelSecurity.png" class="attachment-post-image size-post-image wp-post-image" alt="Postgre SQL Row Level Security" decoding="async" srcset="https://www.dbrnd.com/wp-content/uploads/2016/08/PostgreSQLRowLevelSecurity.png 573w, https://www.dbrnd.com/wp-content/uploads/2016/08/PostgreSQLRowLevelSecurity-300x134.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/08/PostgreSQLRowLevelSecurity-150x67.png 150w" sizes="(max-width: 573px) 100vw, 573px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-row-level-security-by-example%2F&amp;linkname=SQL%20Server%202016%3A%20Row%20Level%20Security%20by%20Example" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-row-level-security-by-example%2F&amp;linkname=SQL%20Server%202016%3A%20Row%20Level%20Security%20by%20Example" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-row-level-security-by-example%2F&amp;linkname=SQL%20Server%202016%3A%20Row%20Level%20Security%20by%20Example" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-row-level-security-by-example%2F&amp;linkname=SQL%20Server%202016%3A%20Row%20Level%20Security%20by%20Example" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-row-level-security-by-example%2F&amp;linkname=SQL%20Server%202016%3A%20Row%20Level%20Security%20by%20Example" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-row-level-security-by-example%2F&amp;linkname=SQL%20Server%202016%3A%20Row%20Level%20Security%20by%20Example" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2016-row-level-security-by-example%2F&#038;title=SQL%20Server%202016%3A%20Row%20Level%20Security%20by%20Example" data-a2a-url="https://www.dbrnd.com/2017/08/sql-server-2016-row-level-security-by-example/" data-a2a-title="SQL Server 2016: Row Level Security by Example"></a></p><p>In this post, I am going to publish about The Row Level Security which is now a common feature of all new version of RDBMSs like SQL Server 2016, PostgreSQL 9.5.</p>
<blockquote><p>With the concept of Row Level Security, we can restrict the user for a particular set of records.<br />
Previously, we are doing this kind of restriction using by creating filtered VIEWS and assign related VIEWS to relevant Users.</p></blockquote>
<p>SQL Server 2016 has this Row Level Security feature which extends the overall security policy of the SQL Server.</p>
<blockquote class="wp-embedded-content" data-secret="uBuwPD5cuC"><p><a href="https://www.dbrnd.com/2016/08/postgresql-9-5-row-level-security-by-example-restrict-records-for-user/">PostgreSQL 9.5: Row Level Security by Example</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/08/postgresql-9-5-row-level-security-by-example-restrict-records-for-user/embed/#?secret=uBuwPD5cuC" data-secret="uBuwPD5cuC" width="600" height="338" title="&#8220;PostgreSQL 9.5: Row Level Security by Example&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>Please check the below full demonstration on this.</p>
<p><strong>Create a test database:</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE CheckRowSecurity;
GO 
USE CheckRowSecurity;
GO</pre> </p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_employeeSalary
(
	empcode VARCHAR(10)
	,empname VARCHAR(10)
	,empsalary BIGINT
	,[month] INT
)
GO
 
INSERT  INTO tbl_employeeSalary
VALUES 
('Anv','Anvesh',150000,1)
,('Anv','Anvesh',120000,2)
,('Anv','Anvesh',160000,3)
,('Anv','Anvesh',170000,4)
,('Mar','Martin',90000,1)
,('Mar','Martin',100000,2)
,('Mar','Martin',120000,3)
,('Mar','Martin',130000,4)
GO</pre> </p>
<p><strong>Create two test users and assign SELECT permission on the table:</strong></p>
<pre class="crayon-plain-tag">CREATE USER Anv WITHOUT LOGIN;
CREATE USER Mar WITHOUT LOGIN;
GO

GRANT SELECT ON tbl_employeeSalary TO Anv
GRANT SELECT ON tbl_employeeSalary TO Mar
GO</pre> </p>
<p><strong>Create filter predicate function:</strong></p>
<pre class="crayon-plain-tag">CREATE FUNCTION rowLevelSecurity(@userName as sysname)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN SELECT 1 AS rowLevelSecurityResult
WHERE @userName = USER_NAME();
GO</pre> </p>
<p><strong>Add filter predicate to the table:</strong></p>
<pre class="crayon-plain-tag">CREATE SECURITY POLICY UserFilter
ADD FILTER PREDICATE dbo.rowLevelSecurity(empcode)
ON dbo.tbl_employeeSalary
WITH (STATE = ON);
GO</pre> </p>
<p><strong>Select table without any user:</strong><br />
You will get a blank result set because we alter the security policy of this table.</p>
<pre class="crayon-plain-tag">SELECT * FROM tbl_employeeSalary</pre> </p>
<p><strong>Check for User &#8216;Anv&#8217;:</strong></p>
<pre class="crayon-plain-tag">EXECUTE AS USER = 'Anv'
SELECT * FROM tbl_employeeSalary
REVERT
GO</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">empcode    empname    empsalary            month
---------- ---------- -------------------- -----------
Anv        Anvesh     150000               1
Anv        Anvesh     120000               2
Anv        Anvesh     160000               3
Anv        Anvesh     170000               4</pre> </p>
<p><strong>Check for User &#8216;Mar&#8217;:</strong></p>
<pre class="crayon-plain-tag">EXECUTE AS USER = 'Mar'
SELECT * FROM tbl_employeeSalary
REVERT
GO</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">empcode    empname    empsalary            month
---------- ---------- -------------------- -----------
Mar        Martin     90000                1
Mar        Martin     100000               2
Mar        Martin     120000               3
Mar        Martin     130000               4</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/08/sql-server-2016-row-level-security-by-example/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
