<?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>Database Designing &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/category/database-designing/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>Fri, 08 Feb 2019 18:51:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>Database Design: Please do not use DISTINCT</title>
		<link>https://www.dbrnd.com/2019/02/database-design-please-do-not-use-distinct-keyword-remove-duplicate-data/</link>
					<comments>https://www.dbrnd.com/2019/02/database-design-please-do-not-use-distinct-keyword-remove-duplicate-data/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 04 Feb 2019 16:16:09 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database concept]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database standards]]></category>
		<category><![CDATA[Database Theory]]></category>
		<category><![CDATA[database topic]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DISTINCT]]></category>
		<category><![CDATA[group by]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[RDBMS]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4130</guid>

					<description><![CDATA[<div><img width="336" height="336" src="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct.jpg" class="attachment-post-image size-post-image wp-post-image" alt="database design angry distinct" decoding="async" fetchpriority="high" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct.jpg 336w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct-150x150.jpg 150w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct-300x300.jpg 300w" sizes="(max-width: 336px) 100vw, 336px" /></div>I am telling you personally that I hate the use of DISTINCT. DISTINCT used by those people, who are not sure about their data set or SELECT statement or JOINS. Whenever I get any query with DISTINCT, immediately I suggest to remove it. I asked to many developers that, does it makes sense to use [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="336" height="336" src="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct.jpg" class="attachment-post-image size-post-image wp-post-image" alt="database design angry distinct" decoding="async" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct.jpg 336w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct-150x150.jpg 150w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct-300x300.jpg 300w" sizes="(max-width: 336px) 100vw, 336px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F02%2Fdatabase-design-please-do-not-use-distinct-keyword-remove-duplicate-data%2F&amp;linkname=Database%20Design%3A%20Please%20do%20not%20use%20DISTINCT" 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%2F2019%2F02%2Fdatabase-design-please-do-not-use-distinct-keyword-remove-duplicate-data%2F&amp;linkname=Database%20Design%3A%20Please%20do%20not%20use%20DISTINCT" 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%2F2019%2F02%2Fdatabase-design-please-do-not-use-distinct-keyword-remove-duplicate-data%2F&amp;linkname=Database%20Design%3A%20Please%20do%20not%20use%20DISTINCT" 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%2F2019%2F02%2Fdatabase-design-please-do-not-use-distinct-keyword-remove-duplicate-data%2F&amp;linkname=Database%20Design%3A%20Please%20do%20not%20use%20DISTINCT" 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%2F2019%2F02%2Fdatabase-design-please-do-not-use-distinct-keyword-remove-duplicate-data%2F&amp;linkname=Database%20Design%3A%20Please%20do%20not%20use%20DISTINCT" 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%2F2019%2F02%2Fdatabase-design-please-do-not-use-distinct-keyword-remove-duplicate-data%2F&amp;linkname=Database%20Design%3A%20Please%20do%20not%20use%20DISTINCT" 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%2F2019%2F02%2Fdatabase-design-please-do-not-use-distinct-keyword-remove-duplicate-data%2F&#038;title=Database%20Design%3A%20Please%20do%20not%20use%20DISTINCT" data-a2a-url="https://www.dbrnd.com/2019/02/database-design-please-do-not-use-distinct-keyword-remove-duplicate-data/" data-a2a-title="Database Design: Please do not use DISTINCT"></a></p><p><strong><img decoding="async" class="alignright wp-image-4137 size-medium" title="database design angry distinct" src="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct-300x300.jpg" alt="database design angry distinct" width="300" height="300" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct-300x300.jpg 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct-150x150.jpg 150w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignAngryDistinct.jpg 336w" sizes="(max-width: 300px) 100vw, 300px" />I am telling you personally that I hate the use of DISTINCT.</strong></p>
<blockquote><p>DISTINCT used by those people, who are not sure about their data set or SELECT statement or JOINS.</p></blockquote>
<p><strong>Whenever I get any query with DISTINCT, immediately I suggest to remove it. </strong></p>
<blockquote><p>I asked to many developers that, does it makes sense to use DISTINCT or do we have any alternative?<br />
Second, I asked that Why are you required to use DISTINCT.</p></blockquote>
<p><strong>Guys, what are you thinking? What was that answer?</strong></p>
<blockquote><p>Very simple, they keep quiet for a minute and were telling like: we are using to avoid duplicate result set.</p></blockquote>
<blockquote><p>This is not the correct answer for the use of DISTINCT.</p></blockquote>
<blockquote><p>Actually, most of developers are using DISTINCT because they want to hide their mistakes. They are writing incorrect joins and hiding duplication of data.</p></blockquote>
<blockquote><p>This is not only for database developer, DBA is a same responsible for this. The DBA must stop the duplication of data.</p></blockquote>
<blockquote><p><em>The DBA should give the answer that how duplicates data inserted in the database and who is responsible for that duplication.</em></p></blockquote>
<p><strong>Do you think, the use of DISTINCT is good for query performance?</strong></p>
<blockquote><p>My answer is simply no. Why, because it fetches unnecessary duplicate data and returns unique from it.</p></blockquote>
<blockquote><p>You should know the logical sequence of SQL Query execution. In the logical sequence, DISTINCT execute after SELECT means It checks all the data first and after that It avoids the duplicate data.</p></blockquote>
<p><strong>As I have raised a question for DISTINCT, few developers asked me to use GROUP BY instead of DISTINCT.</strong></p>
<blockquote><p>My simple answer was, Please do not use anything to remove duplicates from your result set.</p></blockquote>
<blockquote><p>Explicitly, you should remove the duplicate data and then also If you require to count few unique master group data, you can use GROUP BY instead of DISTINCT.</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/02/database-design-please-do-not-use-distinct-keyword-remove-duplicate-data/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Implement Table Partition in Non Enterprise Edition (Use Partitioned View)</title>
		<link>https://www.dbrnd.com/2017/09/sql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view/</link>
					<comments>https://www.dbrnd.com/2017/09/sql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 03 Sep 2017 16:16:45 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<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[Partitioned View]]></category>
		<category><![CDATA[SQL Query]]></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[Table Partition]]></category>
		<category><![CDATA[table partitioning]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6022</guid>

					<description><![CDATA[In this post, I am sharing a full demonstration of the concept of Partitioned view in SQL Server. Using Partitioned view, you can implement Table Partitioning in the Non-Enterprise Edition of SQL Server because Table Partition is the feature of SQL Server Enterprise Edition. Many small level companies are searching for this kind of solution, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view%2F&amp;linkname=SQL%20Server%3A%20Implement%20Table%20Partition%20in%20Non%20Enterprise%20Edition%20%28Use%20Partitioned%20View%29" 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%2F09%2Fsql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view%2F&amp;linkname=SQL%20Server%3A%20Implement%20Table%20Partition%20in%20Non%20Enterprise%20Edition%20%28Use%20Partitioned%20View%29" 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%2F09%2Fsql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view%2F&amp;linkname=SQL%20Server%3A%20Implement%20Table%20Partition%20in%20Non%20Enterprise%20Edition%20%28Use%20Partitioned%20View%29" 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%2F09%2Fsql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view%2F&amp;linkname=SQL%20Server%3A%20Implement%20Table%20Partition%20in%20Non%20Enterprise%20Edition%20%28Use%20Partitioned%20View%29" 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%2F09%2Fsql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view%2F&amp;linkname=SQL%20Server%3A%20Implement%20Table%20Partition%20in%20Non%20Enterprise%20Edition%20%28Use%20Partitioned%20View%29" 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%2F09%2Fsql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view%2F&amp;linkname=SQL%20Server%3A%20Implement%20Table%20Partition%20in%20Non%20Enterprise%20Edition%20%28Use%20Partitioned%20View%29" 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%2F09%2Fsql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view%2F&#038;title=SQL%20Server%3A%20Implement%20Table%20Partition%20in%20Non%20Enterprise%20Edition%20%28Use%20Partitioned%20View%29" data-a2a-url="https://www.dbrnd.com/2017/09/sql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view/" data-a2a-title="SQL Server: Implement Table Partition in Non Enterprise Edition (Use Partitioned View)"></a></p><p>In this post, I am sharing a full demonstration of the concept of Partitioned view in SQL Server.</p>
<p>Using Partitioned view, you can implement Table Partitioning in the Non-Enterprise Edition of SQL Server because Table Partition is the feature of SQL Server Enterprise Edition.</p>
<p>Many small level companies are searching for this kind of solution, and the concept of Partitioned view is also giving a good performance. </p>
<blockquote><p>We can also say that this is a manual table partitioning where you must create separate physical tables basis on your require partition ranges and require to apply proper CHECK constraint for validating data ranges. </p>
<p>After this, using one view, you can access all table and accordingly query execution plan also access only require table which reduces the unnecessary load on all or whole table. </p></blockquote>
<p>Please check the below demonstration and try it your self.</p>
<p><strong>Create a SEQUENCE object:</strong></p><pre class="crayon-plain-tag">CREATE SEQUENCE dbo.seq_ProductHistory
    START WITH 1  
    INCREMENT BY 1 ;  
GO</pre><p>
<strong>Create four physical tables:</strong></p><pre class="crayon-plain-tag">CREATE TABLE dbo.tbl_ProductHistory_Q1
(
	ProductID INT
	,ProductName VARCHAR(20)
	,SoldDate DATE
	,ProductSoldQuarter TINYINT CHECK (ProductSoldQuarter = 1)
	,CONSTRAINT pk_tbl_ProductHistory_Q1_ProductID_ProductSoldQuarter PRIMARY KEY(ProductID, ProductSoldQuarter)
)
GO

CREATE TABLE dbo.tbl_ProductHistory_Q2
(
	ProductID INT 
	,ProductName VARCHAR(20)
	,SoldDate DATE
	,ProductSoldQuarter TINYINT CHECK (ProductSoldQuarter = 2)
	,CONSTRAINT pk_tbl_ProductHistory_Q2_ProductID_ProductSoldQuarter PRIMARY KEY(ProductID, ProductSoldQuarter)
)
GO

CREATE TABLE dbo.tbl_ProductHistory_Q3
(
	ProductID INT 
	,ProductName VARCHAR(20)
	,SoldDate DATE
	,ProductSoldQuarter TINYINT CHECK (ProductSoldQuarter = 3)
	,CONSTRAINT pk_tbl_ProductHistory_Q3_ProductID_ProductSoldQuarter PRIMARY KEY(ProductID, ProductSoldQuarter)
)
GO

CREATE TABLE dbo.tbl_ProductHistory_Q4
(
	ProductID INT 
	,ProductName VARCHAR(20)
	,SoldDate DATE
	,ProductSoldQuarter TINYINT CHECK (ProductSoldQuarter = 4)
	,CONSTRAINT pk_tbl_ProductHistory_Q4_ProductID_ProductSoldQuarter PRIMARY KEY(ProductID, ProductSoldQuarter)
)
GO</pre><p>
<strong>Create a Partitioned View:</strong></p><pre class="crayon-plain-tag">CREATE VIEW dbo.vw_ProductHistory
WITH SCHEMABINDING
AS
SELECT ProductID, ProductName, SoldDate, ProductSoldQuarter FROM dbo.tbl_ProductHistory_Q1
UNION ALL
SELECT ProductID, ProductName, SoldDate, ProductSoldQuarter FROM dbo.tbl_ProductHistory_Q2
UNION ALL
SELECT ProductID, ProductName, SoldDate, ProductSoldQuarter FROM dbo.tbl_ProductHistory_Q3
UNION ALL
SELECT ProductID, ProductName, SoldDate, ProductSoldQuarter FROM dbo.tbl_ProductHistory_Q4
GO</pre><p>
<strong>Use view and Insert data into four tables:</strong></p><pre class="crayon-plain-tag">INSERT INTO dbo.vw_ProductHistory 
VALUES (NEXT VALUE FOR dbo.seq_ProductHistory, 'Computer', '2017-01-08', 1)
GO

INSERT INTO dbo.vw_ProductHistory 
VALUES (NEXT VALUE FOR dbo.seq_ProductHistory, 'Laptop', '2017-04-14', 2)
GO

INSERT INTO dbo.vw_ProductHistory 
VALUES (NEXT VALUE FOR dbo.seq_ProductHistory, 'Pendrive', '2017-08-16', 3)
GO

INSERT INTO dbo.vw_ProductHistory 
VALUES (NEXT VALUE FOR dbo.seq_ProductHistory, 'Mobile', '2017-12-26', 4)
GO</pre><p>
<strong>SELECT all records from all four tables via view:</strong><br />
Check the execution plan, where you can see four different access on physical tables.</p><pre class="crayon-plain-tag">SELECT *FROM dbo.vw_ProductHistory</pre><p>
<strong>Result:</strong></p><pre class="crayon-plain-tag">ProductID   ProductName          SoldDate   ProductSoldQuarter
----------- -------------------- ---------- ------------------
1           Computer             2017-01-08 1
2           Laptop               2017-04-14 2
3           Pendrive             2017-08-16 3
4           Mobile               2017-12-26 4</pre><p>
<strong>Check the execution plan: It is accessing all four physical tables</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-6027" src="https://www.dbrnd.com/wp-content/uploads/2017/08/PartitionedViewAllScan.png" alt="" width="539" height="391" /></p>
<p><strong>SELECT few records:</strong><br />
Check the execution plan, where you can find only access of Quarter-4 table because we are selecting data only for it.</p><pre class="crayon-plain-tag">SELECT *FROM dbo.vw_ProductHistory 
WHERE ProductSoldQuarter = 4</pre><p>
<strong>Result:</strong></p><pre class="crayon-plain-tag">ProductID   ProductName          SoldDate   ProductSoldQuarter
----------- -------------------- ---------- ------------------
4           Mobile               2017-12-26 4</pre><p>
<strong>Check the execution plan: It is accessing only Quarter-4 table.</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-6026" src="https://www.dbrnd.com/wp-content/uploads/2017/08/PartitionedViewSingalScan.png" alt="" width="582" height="131" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/09/sql-server-implement-table-partition-in-non-enterprise-edition-use-partitioned-view/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Performance Test &#8211; Problem of mismatched Column Data Type</title>
		<link>https://www.dbrnd.com/2017/07/sql-server-performance-test-problem-of-mismatched-column-data-type/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 16 Jul 2017 16:16:08 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<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[Logical reads]]></category>
		<category><![CDATA[Physical Reads]]></category>
		<category><![CDATA[SQL Query]]></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[Statistics]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5623</guid>

					<description><![CDATA[In this post, I am sharing performance test of the problem of mismatched column data type in SQL Server. The Database Designer is also defining a wrong mismatched column data type by giving different data types to the same column for many tables. For example, empid column -> assigned INT in tbl_emp table and -> [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F07%2Fsql-server-performance-test-problem-of-mismatched-column-data-type%2F&amp;linkname=SQL%20Server%3A%20Performance%20Test%20%E2%80%93%20Problem%20of%20mismatched%20Column%20Data%20Type" 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%2F07%2Fsql-server-performance-test-problem-of-mismatched-column-data-type%2F&amp;linkname=SQL%20Server%3A%20Performance%20Test%20%E2%80%93%20Problem%20of%20mismatched%20Column%20Data%20Type" 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%2F07%2Fsql-server-performance-test-problem-of-mismatched-column-data-type%2F&amp;linkname=SQL%20Server%3A%20Performance%20Test%20%E2%80%93%20Problem%20of%20mismatched%20Column%20Data%20Type" 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%2F07%2Fsql-server-performance-test-problem-of-mismatched-column-data-type%2F&amp;linkname=SQL%20Server%3A%20Performance%20Test%20%E2%80%93%20Problem%20of%20mismatched%20Column%20Data%20Type" 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%2F07%2Fsql-server-performance-test-problem-of-mismatched-column-data-type%2F&amp;linkname=SQL%20Server%3A%20Performance%20Test%20%E2%80%93%20Problem%20of%20mismatched%20Column%20Data%20Type" 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%2F07%2Fsql-server-performance-test-problem-of-mismatched-column-data-type%2F&amp;linkname=SQL%20Server%3A%20Performance%20Test%20%E2%80%93%20Problem%20of%20mismatched%20Column%20Data%20Type" 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%2F07%2Fsql-server-performance-test-problem-of-mismatched-column-data-type%2F&#038;title=SQL%20Server%3A%20Performance%20Test%20%E2%80%93%20Problem%20of%20mismatched%20Column%20Data%20Type" data-a2a-url="https://www.dbrnd.com/2017/07/sql-server-performance-test-problem-of-mismatched-column-data-type/" data-a2a-title="SQL Server: Performance Test – Problem of mismatched Column Data Type"></a></p><p>In this post, I am sharing performance test of the problem of mismatched column data type in SQL Server. </p>
<p>The Database Designer is also defining a wrong mismatched column data type by giving different data types to the same column for many tables. </p>
<blockquote><p>For example, empid column -> assigned INT in tbl_emp table and -> assigned BIGINT in tbl_dept table. Because of this kind of problem, your query will execute slowly, and it requires implicit data conversion for each record. </p></blockquote>
<blockquote><p>Another example is, your column data type is VARCHAR, and you are checking N&#8217;DATA in WHERE clause which is NVARCHAR, so this is also required implicit data conversion. </p></blockquote>
<p><strong>Please check below full demonstration and, test it yourself:</strong></p>
<p><strong>Create a sample table, where [id] column type is varchar:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_DiffDataTypes 
(	id varchar(25)
	,name VARCHAR(25)
	,constraint pk_tbl_DiffDataTypes_id primary key (id)
)
GO</pre> </p>
<p><strong>Insert few dummy records:</strong></p>
<pre class="crayon-plain-tag">DECLARE @i INT,@max INT
SET @i =1 
SET @max =99999
WHILE @i&lt;=@max
BEGIN
   INSERT INTO tbl_DiffDataTypes VALUES(@i,'dbrnd.com')
   SET @i=@i+1
END</pre> </p>
<p><strong>Please enable STATISTICS:</strong></p>
<pre class="crayon-plain-tag">SET STATISTICS IO ON
SET STATISTICS TIME ON</pre> </p>
<p><strong>Test WHERE filter with VARCHAR value: (Only 3 logical reads)</strong></p>
<pre class="crayon-plain-tag">SELECT * FROM tbl_DiffDataTypes WHERE id = '1'</pre> </p>
<p><strong>Result of Statistics:</strong></p>
<pre class="crayon-plain-tag">Table 'tbl_DiffDataTypes'. Scan count 0, logical reads 3, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</pre> </p>
<p><strong>Test WHERE filter with NVARCHAR value: (62 logical reads)</strong></p>
<pre class="crayon-plain-tag">SELECT * FROM tbl_DiffDataTypes WHERE id = N'1'</pre> </p>
<p><strong>Result of Statistics:</strong></p>
<pre class="crayon-plain-tag">Table 'tbl_DiffDataTypes'. Scan count 1, logical reads 62, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</pre> </p>
<p><strong>Test WHERE filter with INTEGER value: (621 logical reads)</strong></p>
<pre class="crayon-plain-tag">SELECT * FROM tbl_DiffDataTypes WHERE id = 1</pre> </p>
<p><strong>Result of Statistics:</strong></p>
<pre class="crayon-plain-tag">Table 'tbl_DiffDataTypes'. Scan count 1, logical reads 621, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Avoid the use of Indexes on VARCHAR columns</title>
		<link>https://www.dbrnd.com/2017/01/sql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 12 Jan 2017 21:08:07 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[clustered index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Database Design]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[Index key size]]></category>
		<category><![CDATA[non clustered index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4301</guid>

					<description><![CDATA[I am also adding a Database Design category for this post, because what I am feeling that you guys must know about this before designing tables or indexes. You can create Indexes on VARCHAR columns, but you should not create indexes on big size of VARCHAR Columns. Indexes also require storing data as key for [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" 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%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" 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%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" 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%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" 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%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" 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%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&amp;linkname=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" 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%2F01%2Fsql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size%2F&#038;title=SQL%20Server%3A%20Avoid%20the%20use%20of%20Indexes%20on%20VARCHAR%20columns" data-a2a-url="https://www.dbrnd.com/2017/01/sql-server-avoid-the-use-of-indexes-on-varchar-columns-clustered-non-clustered-index-size/" data-a2a-title="SQL Server: Avoid the use of Indexes on VARCHAR columns"></a></p><p>I am also adding a Database Design category for this post, because what I am feeling that you guys must know about this before designing tables or indexes. </p>
<p>You can create Indexes on VARCHAR columns, but you should not create indexes on big size of VARCHAR Columns. </p>
<p>Indexes also require storing data as key for accessing associated records. There is a size limitation of index key values. </p>
<blockquote><p>Before SQL Server 2016, Index key size limitation was 900 bytes for Clustered and Non-Clustered index column.<br />
SQL Server 2016 increased this limitation for Non-Clustered Index and now it is up to 1700 bytes, but for Clustered Index column it is still 900 bytes.</p></blockquote>
<p>Let me demonstrate this.</p>
<p><strong>Create a sample table with Nonclustered Index:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestVarcharNonClustered
(
	ID INT
	,Name VARCHAR(2000)
)
GO

CREATE NONCLUSTERED INDEX idx_tbl_TestVarcharNonClustered_Name ON tbl_TestVarcharNonClustered(Name)
GO</pre> </p>
<p><strong>You will get a below warning:</strong><br />
Because we have set Name VARCHAR(2000).</p>
<pre class="crayon-plain-tag">Warning! The maximum key length for a nonclustered index is 1700 bytes. The index 'idx_tbl_TestVarcharNonClustered_Name' has maximum length of 2000 bytes. For some combination of large values, the insert/update operation will fail.</pre> </p>
<p><strong>Try to insert 1701 bytes data:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestVarcharNonClustered 
VALUES (1,REPLICATE('a',1701))
GO</pre> </p>
<p><strong>You will get a below error:</strong></p>
<pre class="crayon-plain-tag">Msg 1946, Level 16, State 3, Line 1
Operation failed. The index entry of length 1701 bytes for the index 'idx_tbl_TestVarcharNonClustered_Name' exceeds the maximum length of 1700 bytes for nonclustered indexes.</pre> </p>
<p><strong>You can successfully run below INSERT, because it inserts only 1700 bytes:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestVarcharNonClustered 
VALUES (1,REPLICATE('a',1700))
GO</pre> </p>
<p><strong>Now, create a sample table with Clustered Index:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestVarcharClustered
(
	ID INT
	,Name VARCHAR(2000)
)
GO

CREATE CLUSTERED INDEX idx_tbl_TestVarcharClustered_Name ON tbl_TestVarcharClustered(Name)
GO</pre> </p>
<p><strong>You will get a below warning:</strong><br />
Because we have set Name VARCHAR(2000) on cluster index column.</p>
<pre class="crayon-plain-tag">Warning! The maximum key length for a clustered index is 900 bytes. The index 'idx_tbl_TestVarcharClustered_Name' has maximum length of 2000 bytes. For some combination of large values, the insert/update operation will fail.</pre> </p>
<p><strong>Try to insert a over size data like more than 900 bytes:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestVarcharClustered 
VALUES (1,REPLICATE('a',1001))
GO</pre> </p>
<p><strong>You will get a below error:</strong></p>
<pre class="crayon-plain-tag">Msg 1946, Level 16, State 3, Line 1
Operation failed. The index entry of length 1001 bytes for the index 'idx_tbl_TestVarcharClustered_Name' exceeds the maximum length of 900 bytes for clustered indexes.</pre> </p>
<p><strong>You can successfully run below INSERT, because it inserts only 900 bytes:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_TestVarcharClustered 
VALUES (1,REPLICATE('a',900))
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Database Design: Common Practices for Database Developers and Application Developers</title>
		<link>https://www.dbrnd.com/2016/12/database-design-common-practices-for-database-developers-and-application-developers/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 26 Dec 2016 17:37:29 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Application Developer]]></category>
		<category><![CDATA[Cluster Index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database concept]]></category>
		<category><![CDATA[Database Design]]></category>
		<category><![CDATA[Database Developer]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database standards]]></category>
		<category><![CDATA[Database Theory]]></category>
		<category><![CDATA[database topic]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Performance Optimization]]></category>
		<category><![CDATA[RDBMS]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4117</guid>

					<description><![CDATA[<div><img width="448" height="318" src="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignBestPractices.jpg" class="attachment-post-image size-post-image wp-post-image" alt="Database Design Best Practices" decoding="async" loading="lazy" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignBestPractices.jpg 448w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignBestPractices-300x213.jpg 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignBestPractices-150x106.jpg 150w" sizes="auto, (max-width: 448px) 100vw, 448px" /></div>In this post, I am sharing the list of common practices for Database Designing which should follow by Database Developers and Application Developers. Foreign keys should have indexes on them, and it should often cover multiple columns base on the queries you need to execute. You should make sure about the referential integrity by enforcing [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="448" height="318" src="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignBestPractices.jpg" class="attachment-post-image size-post-image wp-post-image" alt="Database Design Best Practices" decoding="async" loading="lazy" srcset="https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignBestPractices.jpg 448w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignBestPractices-300x213.jpg 300w, https://www.dbrnd.com/wp-content/uploads/2016/12/DatabaseDesignBestPractices-150x106.jpg 150w" sizes="auto, (max-width: 448px) 100vw, 448px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F12%2Fdatabase-design-common-practices-for-database-developers-and-application-developers%2F&amp;linkname=Database%20Design%3A%20Common%20Practices%20for%20Database%20Developers%20and%20Application%20Developers" 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%2F2016%2F12%2Fdatabase-design-common-practices-for-database-developers-and-application-developers%2F&amp;linkname=Database%20Design%3A%20Common%20Practices%20for%20Database%20Developers%20and%20Application%20Developers" 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%2F2016%2F12%2Fdatabase-design-common-practices-for-database-developers-and-application-developers%2F&amp;linkname=Database%20Design%3A%20Common%20Practices%20for%20Database%20Developers%20and%20Application%20Developers" 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%2F2016%2F12%2Fdatabase-design-common-practices-for-database-developers-and-application-developers%2F&amp;linkname=Database%20Design%3A%20Common%20Practices%20for%20Database%20Developers%20and%20Application%20Developers" 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%2F2016%2F12%2Fdatabase-design-common-practices-for-database-developers-and-application-developers%2F&amp;linkname=Database%20Design%3A%20Common%20Practices%20for%20Database%20Developers%20and%20Application%20Developers" 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%2F2016%2F12%2Fdatabase-design-common-practices-for-database-developers-and-application-developers%2F&amp;linkname=Database%20Design%3A%20Common%20Practices%20for%20Database%20Developers%20and%20Application%20Developers" 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%2F2016%2F12%2Fdatabase-design-common-practices-for-database-developers-and-application-developers%2F&#038;title=Database%20Design%3A%20Common%20Practices%20for%20Database%20Developers%20and%20Application%20Developers" data-a2a-url="https://www.dbrnd.com/2016/12/database-design-common-practices-for-database-developers-and-application-developers/" data-a2a-title="Database Design: Common Practices for Database Developers and Application Developers"></a></p><p>In this post, I am sharing the list of common practices for Database Designing which should follow by Database Developers and Application Developers.</p>
<ul>
<li>Foreign keys should have indexes on them, and it should often cover multiple columns base on the queries you need to execute.</li>
<li>You should make sure about the referential integrity by enforcing the Foreign Keys.<br />
Choose right column for CLUSTER Index.</li>
<li>You should apply proper indexes and do not create duplicate indexes and avoid creation of unnecessary indexes.</li>
<li>You should not put auto-number data type as a PRIMARY KEY to join a FOREIGN KEY in a parent/child table relationship.</li>
<li>If your system is running large number of INSERT/DELETE, you should avoid frequent update of database Statistics.</li>
<li>You should choose the write data-type for your data columns.</li>
<li>Please separate big size of columns from main table and store in a different table.</li>
<li>You should apply proper column name.</li>
<li>Use proper data types for Latitude, Longitude, IP-Address, Network Address, Mac Address.</li>
<li>Use Natural Primary key rather than Surrogate Primary key. Natural Primary keys are keys base on an external meaningful data. Surrogate Primary key are keys base on an auto-increment number or values which have no meaning outside the system.</li>
<li>You must use Stored Procedures or Stored Functions.</li>
<li>Please avoid too much database normalization and try to design your database to achieve Database Normalization + Database Denormalization. You should design this combination to achieve the performance.</li>
<li>Avoid inappropriate or excessive use of cursors.</li>
<li>Avoid inappropriate use of Database Transactions (BEGIN&#8230;COMMIT).</li>
<li>Try to avoid the use of OR condition because an AND condition restricts the data set, whereas an OR condition grows it.</li>
<li>You should do detailed performance analysis on queries.</li>
<li>Try to use the Prepared SQL Statement which caches the compiled query and the execution plan for better performance. It will also better protect you against SQL injection attacks.</li>
<li>Please do not simplify your complex queries through the views.</li>
<li>Please do not use DISTINCT frequently. Many developers are using DISTINCT to hide duplicate data, but you should stop and remove the duplicate data.</li>
<li>Try to avoid Correlated Subqueries.</li>
<li>Do not store comma delimited list in a table.</li>
<li>Do not store JSON data in TEXT COLUMN, you should use JSON data type for it.</li>
<li>Please do not use comma separated table names in SELECT query, use explicit JOINs conditions to avoid internal Cartesian products.</li>
</ul>
<p>&nbsp;<br />
<strong>The list is not final yet, you guys can add/share a comment and make it final&#8230;</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Database Design: Don&#8217;t use, comma separated Tables in SELECT Query, Use Explicit JOINs</title>
		<link>https://www.dbrnd.com/2016/11/database-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 30 Nov 2016 20:00:49 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database concept]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database standards]]></category>
		<category><![CDATA[Database Theory]]></category>
		<category><![CDATA[database topic]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[explicit joins]]></category>
		<category><![CDATA[implicit joins]]></category>
		<category><![CDATA[joins optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[RDBMS]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3952</guid>

					<description><![CDATA[In online forums, I am observing one bad query practice. People are using multiple tables in the SELECT query by separating using commas. Bad Query Like: [crayon-6a8f6fda20b20658782802/] Many of the Database Professionals are thinking that It is working like JOINs. I am writing this article in the &#8220;Database Designing&#8221; category, means It applies to all [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F11%2Fdatabase-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join%2F&amp;linkname=Database%20Design%3A%20Don%E2%80%99t%20use%2C%20comma%20separated%20Tables%20in%20SELECT%20Query%2C%20Use%20Explicit%20JOINs" 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%2F2016%2F11%2Fdatabase-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join%2F&amp;linkname=Database%20Design%3A%20Don%E2%80%99t%20use%2C%20comma%20separated%20Tables%20in%20SELECT%20Query%2C%20Use%20Explicit%20JOINs" 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%2F2016%2F11%2Fdatabase-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join%2F&amp;linkname=Database%20Design%3A%20Don%E2%80%99t%20use%2C%20comma%20separated%20Tables%20in%20SELECT%20Query%2C%20Use%20Explicit%20JOINs" 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%2F2016%2F11%2Fdatabase-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join%2F&amp;linkname=Database%20Design%3A%20Don%E2%80%99t%20use%2C%20comma%20separated%20Tables%20in%20SELECT%20Query%2C%20Use%20Explicit%20JOINs" 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%2F2016%2F11%2Fdatabase-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join%2F&amp;linkname=Database%20Design%3A%20Don%E2%80%99t%20use%2C%20comma%20separated%20Tables%20in%20SELECT%20Query%2C%20Use%20Explicit%20JOINs" 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%2F2016%2F11%2Fdatabase-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join%2F&amp;linkname=Database%20Design%3A%20Don%E2%80%99t%20use%2C%20comma%20separated%20Tables%20in%20SELECT%20Query%2C%20Use%20Explicit%20JOINs" 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%2F2016%2F11%2Fdatabase-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join%2F&#038;title=Database%20Design%3A%20Don%E2%80%99t%20use%2C%20comma%20separated%20Tables%20in%20SELECT%20Query%2C%20Use%20Explicit%20JOINs" data-a2a-url="https://www.dbrnd.com/2016/11/database-design-dont-use-comma-separated-tables-in-select-query-use-explicit-joins-optimized-join/" data-a2a-title="Database Design: Don’t use, comma separated Tables in SELECT Query, Use Explicit JOINs"></a></p><p><strong>In online forums, I am observing one  bad query practice. People are using multiple tables in the SELECT query by separating using commas.</strong><br />
<em>Bad Query Like:</em></p>
<pre class="crayon-plain-tag">SELECT * FROM a, b, c WHERE a.id = b.id AND b.id = c.id;</pre> </p>
<blockquote><p>Many of the Database Professionals are thinking that It is working like JOINs.
</p></blockquote>
<blockquote><p>I am writing this article in the &#8220;Database Designing&#8221; category, means It applies to all database professionals for knowing the truth of this kind of bad SQL Query. </p></blockquote>
<blockquote><p>When you write a query like above sample, internally Query Planner creates a virtual join between these tables and this is not a strait forward joins creation. A Query Planner has to check all possible combinations like: first join A TO B and then join C, join A TO C and then join B, join B TO C and then join A.</p></blockquote>
<blockquote><p>When you write such types of bad queries, Query Planner has to do additional work for joining the tables correctly and return the correct result.<br />
But actually It checks the data by creating a full Cartesian Product between these tables which is very costly and slow down the query performance. </p></blockquote>
<blockquote><p>We have taken example of three tables only, now let&#8217;s assume if we have 10 tables and people wrote a SELECT query using comma separated tables.<br />
So please I am requesting, never use such a bad query and try to write explicit JOINs in the SELECT Query.
</p></blockquote>
<p><strong>Another interesting point is:</strong></p>
<blockquote><p>When I discussed this point with our team, one of database developers said It is good that Query Planner is deciding the order of JOINS. If we give explicit joins, It may not be in the correct order all the times so let&#8217;s Query Planner to do. </p></blockquote>
<blockquote><p>My simple answer was:<br />
I am 5% agree with you, but do not forget that we are enough professional and can define the JOINs order correctly. We should not rely on Query Planner because It requires more internal I/O to just prepare a joins of the table.
</p></blockquote>
<p><strong>Correct Query should like:</strong></p>
<pre class="crayon-plain-tag">SELECT a.* FROM a JOIN b ON a.id=b.id JOIN c ON b.id=c.id</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: What happened, when Row Overflow and Data Exceeding 8KB?</title>
		<link>https://www.dbrnd.com/2016/04/sql-server-what-happened-when-row-overflow-and-data-exceeding-8kb/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 14 Apr 2016 20:50:26 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[data exceeding]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[IN_ROW_DATA]]></category>
		<category><![CDATA[ROW OVERFLOW]]></category>
		<category><![CDATA[ROW_OVERFLOW_DATA]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2292</guid>

					<description><![CDATA[In the previous article, I discussed the 8KB data page of the SQL Server, but what happened when the row is larger and cannot fit into a single 8KB page? Each row is strictly prohibited to use only 8KB size per data page, but the data type like char, varchar, nvarchar, and varbinary require more [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fsql-server-what-happened-when-row-overflow-and-data-exceeding-8kb%2F&amp;linkname=SQL%20Server%3A%20What%20happened%2C%20when%20Row%20Overflow%20and%20Data%20Exceeding%208KB%3F" 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%2F2016%2F04%2Fsql-server-what-happened-when-row-overflow-and-data-exceeding-8kb%2F&amp;linkname=SQL%20Server%3A%20What%20happened%2C%20when%20Row%20Overflow%20and%20Data%20Exceeding%208KB%3F" 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%2F2016%2F04%2Fsql-server-what-happened-when-row-overflow-and-data-exceeding-8kb%2F&amp;linkname=SQL%20Server%3A%20What%20happened%2C%20when%20Row%20Overflow%20and%20Data%20Exceeding%208KB%3F" 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%2F2016%2F04%2Fsql-server-what-happened-when-row-overflow-and-data-exceeding-8kb%2F&amp;linkname=SQL%20Server%3A%20What%20happened%2C%20when%20Row%20Overflow%20and%20Data%20Exceeding%208KB%3F" 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%2F2016%2F04%2Fsql-server-what-happened-when-row-overflow-and-data-exceeding-8kb%2F&amp;linkname=SQL%20Server%3A%20What%20happened%2C%20when%20Row%20Overflow%20and%20Data%20Exceeding%208KB%3F" 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%2F2016%2F04%2Fsql-server-what-happened-when-row-overflow-and-data-exceeding-8kb%2F&amp;linkname=SQL%20Server%3A%20What%20happened%2C%20when%20Row%20Overflow%20and%20Data%20Exceeding%208KB%3F" 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%2F2016%2F04%2Fsql-server-what-happened-when-row-overflow-and-data-exceeding-8kb%2F&#038;title=SQL%20Server%3A%20What%20happened%2C%20when%20Row%20Overflow%20and%20Data%20Exceeding%208KB%3F" data-a2a-url="https://www.dbrnd.com/2016/04/sql-server-what-happened-when-row-overflow-and-data-exceeding-8kb/" data-a2a-title="SQL Server: What happened, when Row Overflow and Data Exceeding 8KB?"></a></p><p><em>In the previous article, I discussed the <a href="https://www.dbrnd.com/2016/04/sql-server-the-internal-structure-of-the-data-page/" target="_blank"><strong>8KB data page of the SQL Server</strong></a>, but what happened when the row is larger and cannot fit into a single 8KB page?</em></p>
<blockquote><p>Each row is strictly prohibited to use only 8KB size per data page, but the data type like char, varchar, nvarchar, and varbinary require more space to store data into data page. </p></blockquote>
<blockquote><p>Sometimes, the individual column may fit in the limit of 8KB, but if we have multiple columns and the combination of all these types of columns exceeds the limit of 8KB, SQL Server moves data in different allocation unit or raise an error. </p>
<p>e.g. we have three separate columns like VARCHAR(MAX), CHAR(6000) and TEXT so combination of these all columns cannot fit in the 8KB size.</p></blockquote>
<blockquote><p>The SQL Server Database Engine moves the record column with the largest width to another page in the ROW_OVERFLOW_DATA allocation unit, and it is maintaining a 24-byte pointer on the original page. </p></blockquote>
<blockquote><p>To moving of the large records to another page is a dynamic process because records can become a larger at any point of time while executing UPDATE operations. </p>
<p>If the UPDATE operation makes a small size of the record, it backs to the original page in the IN_ROW_DATA allocation unit.</p></blockquote>
<blockquote><p>Whenever we are combining VARCHAR, NVARCHAR, BLOB, VARBINARY kind of data column in a table, internally SQL Server separates the data pages because it may exceed the 8KB row size.
</p></blockquote>
<blockquote><p><em><strong>My suggestion is:</strong> if we have large size of data columns, we should create a separate table for those columns. Because asynchronously, we can perform JOIN operations, which is performing better than selecting data from internal fragmented pages. </em>
</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Database Design: The Ultimate Strategies to avoid Deadlock</title>
		<link>https://www.dbrnd.com/2016/04/database-design-the-ultimate-strategies-to-avoid-deadlock/</link>
					<comments>https://www.dbrnd.com/2016/04/database-design-the-ultimate-strategies-to-avoid-deadlock/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 11 Apr 2016 21:11:21 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database concept]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database standards]]></category>
		<category><![CDATA[Database Theory]]></category>
		<category><![CDATA[database topic]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[RDBMS]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2386</guid>

					<description><![CDATA[What should be our precautions and strategies to avoid a Deadlock in a Database System. We should use clustered index maximum for all types of transaction. The clustered key stored in the same data page so whenever we are updating or deleting data, it saves the data searching time. You should always write UPDATE and [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fdatabase-design-the-ultimate-strategies-to-avoid-deadlock%2F&amp;linkname=Database%20Design%3A%20The%20Ultimate%20Strategies%20to%20avoid%20Deadlock" 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%2F2016%2F04%2Fdatabase-design-the-ultimate-strategies-to-avoid-deadlock%2F&amp;linkname=Database%20Design%3A%20The%20Ultimate%20Strategies%20to%20avoid%20Deadlock" 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%2F2016%2F04%2Fdatabase-design-the-ultimate-strategies-to-avoid-deadlock%2F&amp;linkname=Database%20Design%3A%20The%20Ultimate%20Strategies%20to%20avoid%20Deadlock" 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%2F2016%2F04%2Fdatabase-design-the-ultimate-strategies-to-avoid-deadlock%2F&amp;linkname=Database%20Design%3A%20The%20Ultimate%20Strategies%20to%20avoid%20Deadlock" 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%2F2016%2F04%2Fdatabase-design-the-ultimate-strategies-to-avoid-deadlock%2F&amp;linkname=Database%20Design%3A%20The%20Ultimate%20Strategies%20to%20avoid%20Deadlock" 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%2F2016%2F04%2Fdatabase-design-the-ultimate-strategies-to-avoid-deadlock%2F&amp;linkname=Database%20Design%3A%20The%20Ultimate%20Strategies%20to%20avoid%20Deadlock" 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%2F2016%2F04%2Fdatabase-design-the-ultimate-strategies-to-avoid-deadlock%2F&#038;title=Database%20Design%3A%20The%20Ultimate%20Strategies%20to%20avoid%20Deadlock" data-a2a-url="https://www.dbrnd.com/2016/04/database-design-the-ultimate-strategies-to-avoid-deadlock/" data-a2a-title="Database Design: The Ultimate Strategies to avoid Deadlock"></a></p><p>What should be our precautions and strategies to avoid a <a href="https://www.dbrnd.com/2016/04/database-theory-what-is-timeout-lock-block-and-deadlock-in-a-database-system/" target="_blank"><strong>Deadlock</strong></a> in a Database System. </p>
<blockquote><p>We should use clustered index maximum for all types of transaction. The clustered key stored in the same data page so whenever we are updating or deleting data, it saves the data searching time.<br />
You should always write UPDATE and DELETE statement with the filter of a clustered key. </p></blockquote>
<blockquote><p>The RDBMS systems provide different types of isolation level, you should write your transactions under the proper isolation level.<br />
If your system is ok with dirty read, you can SELECT uncommitted data which never block another transaction. You can also use MVCC architecture for this. </p></blockquote>
<blockquote><p>You should avoid high row count SQL statements that can cause a table lock. For example, instead of inserting all rows from one table to another at a time, do the batchwise insertion.
</p></blockquote>
<blockquote><p>You should break the long transaction into small parts and arrange the proper sequence for that sorter transaction and also write properly COMMIT and ROLLBACK statement. </p></blockquote>
<blockquote><p>You should try to avoid unnecessarily hidden triggers which are manipulating transaction for another table. Many times, I found that Deadlock occurs because of trigger hold a lock on another table.
</p></blockquote>
<blockquote><p>You should avoid SELECT * and specify the only require column list. You can visit this article for more detail. <a href="https://www.dbrnd.com/2015/09/select-all-columns-to-be-good-or-bad-in-database-system/" target="_blank"><strong>&#8220;SELECT all columns to be good or bad in database system&#8221;</strong></a></p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/04/database-design-the-ultimate-strategies-to-avoid-deadlock/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Database Design: Storing a comma separated list in a Database, Is a Bad Practice?</title>
		<link>https://www.dbrnd.com/2016/01/database-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice/</link>
					<comments>https://www.dbrnd.com/2016/01/database-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 28 Jan 2016 19:56:25 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[comma separated]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database concept]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database standards]]></category>
		<category><![CDATA[Database Theory]]></category>
		<category><![CDATA[database topic]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[delimited list]]></category>
		<category><![CDATA[RDBMS]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1404</guid>

					<description><![CDATA[Should we store comma &#8211; separated list in a database? My suggestion and answer are: Never store comma &#8211; separated or delimited list in a Database. I found this discussion in many forums and blogs so, in this post, I would like to share my opinions and views on this topic. Why we should not [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fdatabase-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice%2F&amp;linkname=Database%20Design%3A%20Storing%20a%20comma%20separated%20list%20in%20a%20Database%2C%20Is%20a%20Bad%20Practice%3F" 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%2F2016%2F01%2Fdatabase-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice%2F&amp;linkname=Database%20Design%3A%20Storing%20a%20comma%20separated%20list%20in%20a%20Database%2C%20Is%20a%20Bad%20Practice%3F" 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%2F2016%2F01%2Fdatabase-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice%2F&amp;linkname=Database%20Design%3A%20Storing%20a%20comma%20separated%20list%20in%20a%20Database%2C%20Is%20a%20Bad%20Practice%3F" 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%2F2016%2F01%2Fdatabase-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice%2F&amp;linkname=Database%20Design%3A%20Storing%20a%20comma%20separated%20list%20in%20a%20Database%2C%20Is%20a%20Bad%20Practice%3F" 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%2F2016%2F01%2Fdatabase-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice%2F&amp;linkname=Database%20Design%3A%20Storing%20a%20comma%20separated%20list%20in%20a%20Database%2C%20Is%20a%20Bad%20Practice%3F" 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%2F2016%2F01%2Fdatabase-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice%2F&amp;linkname=Database%20Design%3A%20Storing%20a%20comma%20separated%20list%20in%20a%20Database%2C%20Is%20a%20Bad%20Practice%3F" 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%2F2016%2F01%2Fdatabase-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice%2F&#038;title=Database%20Design%3A%20Storing%20a%20comma%20separated%20list%20in%20a%20Database%2C%20Is%20a%20Bad%20Practice%3F" data-a2a-url="https://www.dbrnd.com/2016/01/database-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice/" data-a2a-title="Database Design: Storing a comma separated list in a Database, Is a Bad Practice?"></a></p><p><strong>Should we store comma &#8211; separated list in a database?<br />
My suggestion and answer are: Never store comma &#8211; separated or delimited list in a Database. </strong></p>
<p>I found this discussion in many forums and blogs so, in this post, I would like to share my opinions and views on this topic.</p>
<p><strong>Why we should not store comma &#8211; separated or delimited list?</strong></p>
<blockquote><p>We cannot enforce uniqueness inside the list, e.g. list can be like this: 5, 4, 8, 8, 8, 6.</p></blockquote>
<blockquote><p>We cannot ensure right data-type for all the values, e.g. list can be like this: 5, 8, 7, temp, abc, $, 8.</p></blockquote>
<blockquote><p>Do not possible to check referential integrity.</p></blockquote>
<blockquote><p>It is tough to search any data or value from the list and sometimes we have to use regular expressions to search the string.</p></blockquote>
<blockquote><p>We cannot perform any DML operation on a single value from the list without fetching the whole list.</p></blockquote>
<blockquote><p>Getting all the records in sorted order is tough.</p></blockquote>
<blockquote><p>Counting elements from the list is terrible.</p></blockquote>
<blockquote><p>When we are storing integer data into the list, it takes twice the space than binary integers.</p></blockquote>
<blockquote><p>We cannot use list value in the join conditions.</p></blockquote>
<blockquote><p>When we store the comma separated value, the overall maintenance of this list and data is complicated.</p></blockquote>
<p><strong>The simplest solution of this problem,</strong> is to create a separate table, or you can use data type like XML, JSON. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/01/database-design-storing-a-comma-separated-list-in-a-database-is-a-bad-practice/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Database Design: Should we allow NULL or We should apply NOT NULL ?</title>
		<link>https://www.dbrnd.com/2016/01/database-design-should-we-allow-null-or-we-should-apply-not-null/</link>
					<comments>https://www.dbrnd.com/2016/01/database-design-should-we-allow-null-or-we-should-apply-not-null/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 26 Jan 2016 19:03:56 +0000</pubDate>
				<category><![CDATA[Database Designing]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database concept]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database standards]]></category>
		<category><![CDATA[Database Theory]]></category>
		<category><![CDATA[database topic]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[NOT NULL]]></category>
		<category><![CDATA[NULL]]></category>
		<category><![CDATA[RDBMS]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1394</guid>

					<description><![CDATA[Should we allow NULL or We should apply NOT NULL ? As a Database Architect, I would also like to express my opinions and views on this topic. First single line statement, Should NULL or Should NOT NULL is depending on the situation and importance of data. NULL means the pointer set to 0x00 in [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F01%2Fdatabase-design-should-we-allow-null-or-we-should-apply-not-null%2F&amp;linkname=Database%20Design%3A%20Should%20we%20allow%20NULL%20or%20We%20should%20apply%20NOT%20NULL%20%3F" 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%2F2016%2F01%2Fdatabase-design-should-we-allow-null-or-we-should-apply-not-null%2F&amp;linkname=Database%20Design%3A%20Should%20we%20allow%20NULL%20or%20We%20should%20apply%20NOT%20NULL%20%3F" 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%2F2016%2F01%2Fdatabase-design-should-we-allow-null-or-we-should-apply-not-null%2F&amp;linkname=Database%20Design%3A%20Should%20we%20allow%20NULL%20or%20We%20should%20apply%20NOT%20NULL%20%3F" 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%2F2016%2F01%2Fdatabase-design-should-we-allow-null-or-we-should-apply-not-null%2F&amp;linkname=Database%20Design%3A%20Should%20we%20allow%20NULL%20or%20We%20should%20apply%20NOT%20NULL%20%3F" 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%2F2016%2F01%2Fdatabase-design-should-we-allow-null-or-we-should-apply-not-null%2F&amp;linkname=Database%20Design%3A%20Should%20we%20allow%20NULL%20or%20We%20should%20apply%20NOT%20NULL%20%3F" 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%2F2016%2F01%2Fdatabase-design-should-we-allow-null-or-we-should-apply-not-null%2F&amp;linkname=Database%20Design%3A%20Should%20we%20allow%20NULL%20or%20We%20should%20apply%20NOT%20NULL%20%3F" 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%2F2016%2F01%2Fdatabase-design-should-we-allow-null-or-we-should-apply-not-null%2F&#038;title=Database%20Design%3A%20Should%20we%20allow%20NULL%20or%20We%20should%20apply%20NOT%20NULL%20%3F" data-a2a-url="https://www.dbrnd.com/2016/01/database-design-should-we-allow-null-or-we-should-apply-not-null/" data-a2a-title="Database Design: Should we allow NULL or We should apply NOT NULL ?"></a></p><p><strong>Should we allow NULL or We should apply NOT NULL ?</strong></p>
<blockquote><p>As a Database Architect, I would also like to express my opinions and views on this topic.</p></blockquote>
<blockquote><p>First single line statement, Should NULL or Should NOT NULL is depending on the situation and importance of data.</p></blockquote>
<blockquote><p>NULL means the pointer set to 0x00 in the row header that means no data to access.<br />
Any search query or engine can easily identify a data which has a NULL.</p></blockquote>
<blockquote><p>As per ANSI Standard NULL means UNKNOWN value whatever data-type like, integer, varchar or datetime. </p></blockquote>
<blockquote><p>I read many articles and found that many database professionals are suggesting that never go with NULL.<br />
Means, you have to enter a value in each column or else they will allow (&#8221;) empty string as NULL values.<br />
e.g. In SQL Server if you enter an empty string in datetime column, it inserts the default value like &#8216;1900-01-01 00:00:00.000&#8217;. &#8211; Which is wrong.<br />
In this type of column NOT NULL will not work and we should allow NULL.</p></blockquote>
<blockquote><p>Another example is, CHAR data-type column. If we apply NOT NULL and someone enters empty string because of NOT NULL, it occupies the same size of bytes like other rows and which is wrong. </p></blockquote>
<blockquote><p>We have to identify all columns and take decisions that in which columns we should allow NULL and in which columns we should apply NOT NULL. </p></blockquote>
<blockquote><p>The Next is about performance,<br />
IS NULL or IS NOT NULL condition is always faster than any other string operation. </p></blockquote>
<blockquote><p>We should also apply NOT NULL constraint on a required column like Password column, but it doesn&#8217;t mean that user can enter (&#8221;) empty string again. </p></blockquote>
<blockquote><p>Many programming languages don&#8217;t recognize a NULL value so for that reason, many Database Professionals applied NOT NULL constraint and putting (&#8221;)Empty string as a NULL value.<br />
But this is not an enough reason to avoid a NULL because NULL is created for a purpose to express the unknown data which can be valid. </p></blockquote>
<p><strong>Don&#8217;t make all columns nullable, and Don&#8217;t make them all NOT NULL. Use NULL only when necessary where the unknown is a valid condition. Everywhere else, use NOT NULL.</strong></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/01/database-design-should-we-allow-null-or-we-should-apply-not-null/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
