<?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>sql | KC's Blog</title>
	<atom:link href="https://www.kjctech.net/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kjctech.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2023 18:21:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.kjctech.net/wp-content/uploads/2016/12/cropped-KC-Logo.png?fit=32%2C32&#038;ssl=1</url>
	<title>sql | KC's Blog</title>
	<link>https://www.kjctech.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">24634607</site>	<item>
		<title>SQL Indexing and Tuning eBook</title>
		<link>https://www.kjctech.net/sql-indexing-and-tuning-ebook/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sql-indexing-and-tuning-ebook</link>
					<comments>https://www.kjctech.net/sql-indexing-and-tuning-ebook/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Wed, 11 Apr 2018 23:42:41 +0000</pubDate>
				<category><![CDATA[Stuff in General]]></category>
		<category><![CDATA[ebook]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=3867</guid>

					<description><![CDATA[<p>It&#8217;s the free web-edition of SQL Performance Explained, regarding SQL indexing and tuning for DB2, MySQL, Oracle, PostgreSQL, and SQL Server. SQL indexing is the most effective tuning method—yet it is often neglected during development. Use The Index, Luke explains SQL indexing from grounds up and doesn&#8217;t stop at ORM tools like Hibernate. Use The Index, Luke is the free [&#8230;]</p>
The post <a href="https://www.kjctech.net/sql-indexing-and-tuning-ebook/">SQL Indexing and Tuning eBook</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><a href="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?ssl=1" data-rel="lightbox-image-0" data-rl_title="" data-rl_caption="" title=""><img data-recalc-dims="1" fetchpriority="high" decoding="async" class="alignnone size-large wp-image-3868" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained-600x188.png?resize=600%2C188&#038;ssl=1" alt="" width="600" height="188" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?resize=600%2C188&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?resize=250%2C78&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?resize=450%2C141&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?resize=700%2C219&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?resize=520%2C163&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?resize=360%2C113&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?resize=100%2C31&amp;ssl=1 100w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/04/sql-performance-explained.png?w=735&amp;ssl=1 735w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<p>It&#8217;s the free web-edition of <a href="https://sql-performance-explained.com/">SQL Performance Explained</a>, regarding SQL indexing and tuning for DB2, MySQL, Oracle, PostgreSQL, and SQL Server.</p>
<blockquote><p>SQL indexing is the most effective tuning method—yet it is often neglected during development. <em>Use The Index, Luke</em> explains SQL indexing from grounds up and doesn&#8217;t stop at ORM tools like Hibernate.</p>
<p><em>Use The Index, Luke</em> is the free web-edition of <a href="https://sql-performance-explained.com/?utm_source=use-the-index-luke.com&amp;utm_campaign=front&amp;utm_medium=web">SQL Performance Explained</a>. If you like this site, consider getting the book. Also have a look at the <a href="https://use-the-index-luke.com/shop">shop for other cool stuff that supports this site</a>.</p></blockquote>
<p>/via <a href="https://use-the-index-luke.com/" target="_blank" rel="noopener">Use the Index, Luke</a>/</p>The post <a href="https://www.kjctech.net/sql-indexing-and-tuning-ebook/">SQL Indexing and Tuning eBook</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/sql-indexing-and-tuning-ebook/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3867</post-id>	</item>
		<item>
		<title>Document SQL Server with Database Note Taker</title>
		<link>https://www.kjctech.net/document-sql-server-with-database-note-taker/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=document-sql-server-with-database-note-taker</link>
					<comments>https://www.kjctech.net/document-sql-server-with-database-note-taker/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Wed, 07 Mar 2018 20:30:38 +0000</pubDate>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[Tools]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=3842</guid>

					<description><![CDATA[<p>Database Note Taker is a free note-taking app made specifically for SQL databases. It makes a database schema and structures a lot easier to capture and document, and definitely simplifies the database documentation and takes the guesswork out of everyday development with databases. How does it work? More specifically, Connect to your database. Refresh with the current structure of your database. [&#8230;]</p>
The post <a href="https://www.kjctech.net/document-sql-server-with-database-note-taker/">Document SQL Server with Database Note Taker</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><a href="http://databasenotetaker.com/" target="_blank" rel="noopener">Database Note Taker</a> is a free note-taking app made specifically for SQL databases. It makes a database schema and structures a lot easier to capture and document, and definitely simplifies the database documentation and takes the guesswork out of everyday development with databases.</p>
<h2>How does it work?</h2>
<p><a href="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/homeDiagram.png?ssl=1" data-rel="lightbox-image-0" data-rl_title="" data-rl_caption="" title=""><img data-recalc-dims="1" decoding="async" class="alignnone size-full wp-image-3843" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/homeDiagram.png?resize=184%2C270&#038;ssl=1" alt="" width="184" height="270" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/homeDiagram.png?w=184&amp;ssl=1 184w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/homeDiagram.png?resize=100%2C147&amp;ssl=1 100w" sizes="(max-width: 184px) 100vw, 184px" /></a></p>
<p>More specifically,</p>
<ul class="bullets">
<li><b>Connect</b> to your database.</li>
<li><b>Refresh</b> with the current structure of your database.</li>
<li>Database Note Taker shows where documentation is missing.</li>
<li><b>Add and edit notes</b> for tables, columns, stored procedures and so on.</li>
<li><b>Publish</b> and distribute the documentation.</li>
<li>When your database has changed, refresh and add new notes.</li>
</ul>
<p><a href="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?ssl=1" data-rel="lightbox-image-1" data-rl_title="" data-rl_caption="" title=""><img data-recalc-dims="1" decoding="async" class="alignnone size-large wp-image-3844" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=600%2C278&#038;ssl=1" alt="" width="600" height="278" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=600%2C278&amp;ssl=1 600w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=250%2C116&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=450%2C209&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=768%2C356&amp;ssl=1 768w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=700%2C324&amp;ssl=1 700w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=520%2C241&amp;ssl=1 520w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=360%2C167&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?resize=100%2C46&amp;ssl=1 100w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/03/Database-Note-Taker.png?w=960&amp;ssl=1 960w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<h2>Features</h2>
<p>Here are a few features worth mentioning:</p>
<ul>
<li>Separate documentation</li>
<li>Work offline &#8211; a live database connection is only required to refresh the database.</li>
<li>Publish to HTML</li>
<li>Database platform independent</li>
<li>Source control friendly</li>
<li>Search</li>
<li>Multiple developers friendly</li>
<li>History tracking</li>
<li>etc.</li>
</ul>
<p>Not enough and looking for more database documentation options? Check out <a href="https://www.sqlshack.com/sql-server-documentation-tools/" target="_blank" rel="noopener">this list</a> compiled by SQLShark.</p>The post <a href="https://www.kjctech.net/document-sql-server-with-database-note-taker/">Document SQL Server with Database Note Taker</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/document-sql-server-with-database-note-taker/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3842</post-id>	</item>
		<item>
		<title>3 SQL Statements to Get A Picture of Database Structure</title>
		<link>https://www.kjctech.net/3-sql-statements-to-get-a-picture-of-database-structure/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=3-sql-statements-to-get-a-picture-of-database-structure</link>
					<comments>https://www.kjctech.net/3-sql-statements-to-get-a-picture-of-database-structure/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Tue, 14 Jul 2015 18:24:12 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">http://www.kjctech.net/?p=2745</guid>

					<description><![CDATA[<p>When you have the needs to figure out a MS SQL database&#8217;s structure, here are 3 SQL statements that would give you a quick start. While they won&#8217;t give you a full picture of the whole database they are definitely going to lead you in a right direction with a quick view of what&#8217;s in there right now. List the name [&#8230;]</p>
The post <a href="https://www.kjctech.net/3-sql-statements-to-get-a-picture-of-database-structure/">3 SQL Statements to Get A Picture of Database Structure</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>When you have the needs to figure out a MS SQL database&#8217;s structure, here are 3 SQL statements that would give you a quick start. While they won&#8217;t give you a full picture of the whole database they are definitely going to lead you in a right direction with a quick view of what&#8217;s in there right now.</p>
<h2>List the name of all the tables in a database</h2>
<pre class="lang:default decode:true">USE databasename
SELECT * FROM information_schema.tables ORDER BY TABLE_NAME</pre>
<p>Replace the real database name in, you are off to go to get a list of tables in that database in the order of the table name.</p>
<h2>List the column names of all the tables in a database</h2>
<p>Now since we know how many tables in a database, let&#8217;s find out what the columns are in each table.</p>
<pre class="lang:default decode:true ">USE databasename
SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID 
ORDER BY schema_name, table_name;</pre>
<p>If you need to know the column details in each table, do the following to each table:</p>
<pre class="lang:default decode:true ">exec sp_columns 'table1'
exec sp_columns 'table2'
...
...</pre>
<h2>List the tables with row counts and space consumption</h2>
<p>If you are investigating a fairly large database, it would be helpful knowing what tables to look first. Execute the following statements and you will get a more clear picture of what you should look into first.</p>
<pre class="lang:default decode:true ">Use databasename
SELECT 
    t.NAME AS billings,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB, 
    SUM(a.used_pages) * 8 AS UsedSpaceKB, 
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM 
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN 
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN 
    sys.schemas s ON t.schema_id = s.schema_id
WHERE 
    t.NAME NOT LIKE 'dt%' 
    AND t.is_ms_shipped = 0
    AND i.OBJECT_ID &gt; 255 
GROUP BY 
    t.Name, s.Name, p.Rows
ORDER BY 
    t.Name</pre>
<p>That&#8217;s about it. These statements have helped me a lot in number of occasions where I need to figure out a new database in order to do some customization. I hope they will help you too down the road.</p>The post <a href="https://www.kjctech.net/3-sql-statements-to-get-a-picture-of-database-structure/">3 SQL Statements to Get A Picture of Database Structure</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/3-sql-statements-to-get-a-picture-of-database-structure/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2745</post-id>	</item>
		<item>
		<title>How to remove duplicate records from a table in SQL database</title>
		<link>https://www.kjctech.net/how-to-remove-duplicate-records-from-a-table-in-sql-database/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-remove-duplicate-records-from-a-table-in-sql-database</link>
					<comments>https://www.kjctech.net/how-to-remove-duplicate-records-from-a-table-in-sql-database/#respond</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Thu, 10 Dec 2009 22:27:57 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[sql]]></category>
		<guid isPermaLink="false">http://www.kjctech.net/2009/12/10/how-to-remove-duplicate-records-from-a-table-in-sql-database/</guid>

					<description><![CDATA[<p>Scenario 1, one record is completely identical to another Meaning that there is no way of identifying them who is who. Usually, it happens when the table doesn&#8217;t have a unique id field due to the poor database design. Because of that, there is no way in SQL to delete one of these duplications without deleting them all first. You [&#8230;]</p>
The post <a href="https://www.kjctech.net/how-to-remove-duplicate-records-from-a-table-in-sql-database/">How to remove duplicate records from a table in SQL database</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<h2>Scenario 1, one record is completely identical to another</h2>
<p>Meaning that there is no way of identifying them who is who. Usually, it happens when the table doesn&#8217;t have a unique id field due to the poor database design. Because of that, there is no way in SQL to delete one of these duplications without deleting them all first.</p>
<p>You can copy the whole table into a new table first,</p>
<blockquote>
<p>SELECT DISTINCT * INTO newTable FROM oldTable</p>
</blockquote>
<p>And then, delete the old table and move all the records back but this time make sure you have the unique identifier set up as one field.</p>
<h2>Scenario 2, similar records</h2>
<p>The records have one field that is the same each other and only one copy needs to be preserved. Usually, they have the unique identifier set up to identify one to another. Then, try</p>
<blockquote>
<p>DELETE t1 FROM oldTable AS t1, oldTable AS t2      <br />WHERE (t1.duplicateField = t2.duplicateField )       <br />AND (t1.uniqueidentifier &gt; t2.uniqueidentifier)</p>
</blockquote>
<p>As a side note, if you run into a program in which you keep getting message telling you that</p>
<blockquote>
<p>If this is intended as a part of a table hint, A WITH keyword and parenthesis are now required. </p>
</blockquote>
<p>that&#8217;s because one of the fields has the same name reserved as keywords in SQL server. You should put â€œ[â€œ and â€œ]â€ around it to tell the server that this is not a reserved keyword.</p>The post <a href="https://www.kjctech.net/how-to-remove-duplicate-records-from-a-table-in-sql-database/">How to remove duplicate records from a table in SQL database</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/how-to-remove-duplicate-records-from-a-table-in-sql-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1031</post-id>	</item>
	</channel>
</rss>
