<?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>UUID &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/uuid/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>Mon, 09 Oct 2017 14:28:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: How to SELECT Random records from a Table?</title>
		<link>https://www.dbrnd.com/2017/03/sql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 03 Mar 2017 16:16:25 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Random Data]]></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[TSQL]]></category>
		<category><![CDATA[uniqueidentifier]]></category>
		<category><![CDATA[UUID]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4677</guid>

					<description><![CDATA[In this post, I am sharing a small demonstration to get the random result of your SELECT statement in SQL Server. We can use NEWID() which creates a unique value type of uniqueidentifier. You just need to ORDER BY your result set using NEWID() and you will get the random result every time. You should [&#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%2F03%2Fsql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier%2F&amp;linkname=SQL%20Server%3A%20How%20to%20SELECT%20Random%20records%20from%20a%20Table%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%2F2017%2F03%2Fsql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier%2F&amp;linkname=SQL%20Server%3A%20How%20to%20SELECT%20Random%20records%20from%20a%20Table%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%2F2017%2F03%2Fsql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier%2F&amp;linkname=SQL%20Server%3A%20How%20to%20SELECT%20Random%20records%20from%20a%20Table%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%2F2017%2F03%2Fsql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier%2F&amp;linkname=SQL%20Server%3A%20How%20to%20SELECT%20Random%20records%20from%20a%20Table%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%2F2017%2F03%2Fsql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier%2F&amp;linkname=SQL%20Server%3A%20How%20to%20SELECT%20Random%20records%20from%20a%20Table%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%2F2017%2F03%2Fsql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier%2F&amp;linkname=SQL%20Server%3A%20How%20to%20SELECT%20Random%20records%20from%20a%20Table%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%2F2017%2F03%2Fsql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier%2F&#038;title=SQL%20Server%3A%20How%20to%20SELECT%20Random%20records%20from%20a%20Table%3F" data-a2a-url="https://www.dbrnd.com/2017/03/sql-server-how-to-select-random-records-from-a-table-uuid-unique-identifier/" data-a2a-title="SQL Server: How to SELECT Random records from a Table?"></a></p><p>In this post, I am sharing a small demonstration to get the random result of your SELECT statement in SQL Server. </p>
<p>We can use NEWID() which creates a unique value type of uniqueidentifier. You just need to ORDER BY your result set using NEWID() and you will get the random result every time. </p>
<p>You should also know about the UUID:</p>
<blockquote class="wp-embedded-content" data-secret="ukomHaKfmu"><p><a href="https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/">Database Theory: The truth about Universally Unique Identifier &#8211; UUID</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/embed/#?secret=ukomHaKfmu" data-secret="ukomHaKfmu" width="600" height="338" title="&#8220;Database Theory: The truth about Universally Unique Identifier &#8211; UUID&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Create a sample table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	Rno INT PRIMARY KEY
	,STudName VARCHAR(20)
	,ClassName CHAR(1)
)
GO</pre> </p>
<p><strong>Insert a few sample records:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_Students 
VALUES 
(1,'Anvesh','A'),(2,'Neevan','B'),(3,'Toby','C')
,(5,'Roy','A'),(4,'Jenny','B'),(6,'Kaviy','C')
,(7,'Martin','A'),(8,'Laxmi','B'),(9,'Nion','C')
GO</pre> </p>
<p><strong>Use NEWID() in ORDER BY to get random results:</strong><br />
I executed below query three times, below you can find three random results. </p>
<pre class="crayon-plain-tag">SELECT *FROM 
tbl_Students
ORDER BY NEWID()
GO</pre> </p>
<pre class="crayon-plain-tag">#1
Rno         STudName             ClassName
----------- -------------------- ---------
2           Neevan               B
6           Kaviy                C
1           Anvesh               A
3           Toby                 C
8           Laxmi                B
9           Nion                 C
4           Jenny                B
5           Roy                  A
7           Martin               A

#2
Rno         STudName             ClassName
----------- -------------------- ---------
1           Anvesh               A
2           Neevan               B
8           Laxmi                B
9           Nion                 C
7           Martin               A
4           Jenny                B
6           Kaviy                C
5           Roy                  A
3           Toby                 C

#3
Rno         STudName             ClassName
----------- -------------------- ---------
3           Toby                 C
1           Anvesh               A
6           Kaviy                C
8           Laxmi                B
5           Roy                  A
4           Jenny                B
2           Neevan               B
9           Nion                 C
7           Martin               A</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Optimized way to populate new Column (UUID) in a Large Table</title>
		<link>https://www.dbrnd.com/2016/08/postgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 21 Aug 2016 14:27:16 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[large column]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[Universally Unique Identifier]]></category>
		<category><![CDATA[UUID]]></category>
		<category><![CDATA[UUID Data type]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3547</guid>

					<description><![CDATA[The default nature of PostgreSQL is based on MVCC architecture which managed by different type of ROW versions. You can read more about MVCC, What is Multi Version Concurrency Control (MVCC) Why I have started this article with MVCC because whenever we update data into the table, it creates a new record and marked the [&#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%2F08%2Fpostgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier%2F&amp;linkname=PostgreSQL%3A%20Optimized%20way%20to%20populate%20new%20Column%20%28UUID%29%20in%20a%20Large%20Table" 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%2F08%2Fpostgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier%2F&amp;linkname=PostgreSQL%3A%20Optimized%20way%20to%20populate%20new%20Column%20%28UUID%29%20in%20a%20Large%20Table" 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%2F08%2Fpostgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier%2F&amp;linkname=PostgreSQL%3A%20Optimized%20way%20to%20populate%20new%20Column%20%28UUID%29%20in%20a%20Large%20Table" 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%2F08%2Fpostgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier%2F&amp;linkname=PostgreSQL%3A%20Optimized%20way%20to%20populate%20new%20Column%20%28UUID%29%20in%20a%20Large%20Table" 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%2F08%2Fpostgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier%2F&amp;linkname=PostgreSQL%3A%20Optimized%20way%20to%20populate%20new%20Column%20%28UUID%29%20in%20a%20Large%20Table" 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%2F08%2Fpostgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier%2F&amp;linkname=PostgreSQL%3A%20Optimized%20way%20to%20populate%20new%20Column%20%28UUID%29%20in%20a%20Large%20Table" 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%2F08%2Fpostgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier%2F&#038;title=PostgreSQL%3A%20Optimized%20way%20to%20populate%20new%20Column%20%28UUID%29%20in%20a%20Large%20Table" data-a2a-url="https://www.dbrnd.com/2016/08/postgresql-optimized-way-to-populate-new-large-column-in-a-table-uuid-universally-unique-identifier/" data-a2a-title="PostgreSQL: Optimized way to populate new Column (UUID) in a Large Table"></a></p><p>The default nature of PostgreSQL is based on MVCC architecture which managed by different type of ROW versions.<br />
You can read more about MVCC,</p>
<blockquote class="wp-embedded-content" data-secret="bpjesSACk4"><p><a href="https://www.dbrnd.com/2015/05/what-is-mvcc-multi-version-concurrency-control/">What is Multi Version Concurrency Control (MVCC)</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/05/what-is-mvcc-multi-version-concurrency-control/embed/#?secret=bpjesSACk4" data-secret="bpjesSACk4" width="600" height="338" title="&#8220;What is Multi Version Concurrency Control (MVCC)&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>Why I have started this article with MVCC because whenever we update data into the table, it creates a new record and marked the old record as an old version or dead tuple.</p></blockquote>
<p>You can visit UUID related article here,</p>
<blockquote class="wp-embedded-content" data-secret="HcGrULmlEJ"><p><a href="https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/">Database Theory: The truth about Universally Unique Identifier &#8211; UUID</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/embed/#?secret=HcGrULmlEJ" data-secret="HcGrULmlEJ" width="600" height="338" title="&#8220;Database Theory: The truth about Universally Unique Identifier &#8211; UUID&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="cFzokz062d"><p><a href="https://www.dbrnd.com/2016/03/postgresql-working-with-universally-unique-identifier-uuid-data-type/">PostgreSQL: Working with Universally Unique Identifier &#8211; UUID Data type</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/03/postgresql-working-with-universally-unique-identifier-uuid-data-type/embed/#?secret=cFzokz062d" data-secret="cFzokz062d" width="600" height="338" title="&#8220;PostgreSQL: Working with Universally Unique Identifier &#8211; UUID Data type&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>My problem:</strong></p>
<blockquote><p>One of our table size is more than 30gb and I got one requirement to add one new column with default UUID data. This table is already loaded by bulk insertion and exclusive lock never work in this situation. </p></blockquote>
<blockquote><p>While adding a column with default value requires PostgreSQL to make new versions of all rows, rewritten the entire table &#8211; indexes and store them on the disk and during that time Table will be locked.</p></blockquote>
<p><strong>The Solution should be like:</strong></p>
<blockquote><p>This task is required to perform on Production report server so it is very much important to take care about everything like: no exclusive lock, within given time frame limit, data should not be fragmented.<br />
I have tried different approaches which are, I am going to share in this article.</p></blockquote>
<p><strong>Option 1: </strong></p>
<blockquote><p>Add new column with NULL value, do not assign any default value in ALTER statement. </p></blockquote>
<blockquote><p>After adding a new column, we should run different small batches to update the newly created column.</p></blockquote>
<blockquote><p>Find out data fragmentation, dead tuples and try to optimize and remove using VACUUM &#8211; ANALYZE.</p></blockquote>
<p><strong>Option 2:</strong></p>
<blockquote><p>CREATE one new blank table with require all old and new columns.<br />
Create different small batches and move data from Old table to the newly created table. </p></blockquote>
<blockquote><p>While transferring the data, populate default value of the new column. (In my case, I have generated UUID on the fly)<br />
ADD all require constraint and indexes on the newly created table.<br />
Stop all the running data insertion queues for a while, drop the old table and rename a  new table to require an original table name. </p></blockquote>
<p>Yet, I am not 100% sure about these approaches, but I have done my task without any locking issue and completed within given time frame. </p>
<p><strong>If you have any other optimized way, Please share your ideas.</strong></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Working with Universally Unique Identifier &#8211; UUID Data type</title>
		<link>https://www.dbrnd.com/2016/03/postgresql-working-with-universally-unique-identifier-uuid-data-type/</link>
					<comments>https://www.dbrnd.com/2016/03/postgresql-working-with-universally-unique-identifier-uuid-data-type/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 03 Mar 2016 18:26:32 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[gen_random_uuid()]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[Universally Unique Identifier]]></category>
		<category><![CDATA[UUID]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1893</guid>

					<description><![CDATA[The PostgreSQL provides Universally Unique Identifier -UUID data type and related functions. In the previous post, I shared the truth about Universally Unique Identifier - UUID. You can visit this article here. PostgreSQL provides two extensions. 1. uuid-ossp 2. pgcrypto. You can install above extension using below script. [crayon-6ab61d8ee7291614229976/] I am using pgcrypto extension 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%2F2016%2F03%2Fpostgresql-working-with-universally-unique-identifier-uuid-data-type%2F&amp;linkname=PostgreSQL%3A%20Working%20with%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID%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%2F2016%2F03%2Fpostgresql-working-with-universally-unique-identifier-uuid-data-type%2F&amp;linkname=PostgreSQL%3A%20Working%20with%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID%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%2F2016%2F03%2Fpostgresql-working-with-universally-unique-identifier-uuid-data-type%2F&amp;linkname=PostgreSQL%3A%20Working%20with%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID%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%2F2016%2F03%2Fpostgresql-working-with-universally-unique-identifier-uuid-data-type%2F&amp;linkname=PostgreSQL%3A%20Working%20with%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID%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%2F2016%2F03%2Fpostgresql-working-with-universally-unique-identifier-uuid-data-type%2F&amp;linkname=PostgreSQL%3A%20Working%20with%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID%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%2F2016%2F03%2Fpostgresql-working-with-universally-unique-identifier-uuid-data-type%2F&amp;linkname=PostgreSQL%3A%20Working%20with%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID%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%2F2016%2F03%2Fpostgresql-working-with-universally-unique-identifier-uuid-data-type%2F&#038;title=PostgreSQL%3A%20Working%20with%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID%20Data%20type" data-a2a-url="https://www.dbrnd.com/2016/03/postgresql-working-with-universally-unique-identifier-uuid-data-type/" data-a2a-title="PostgreSQL: Working with Universally Unique Identifier – UUID Data type"></a></p><p>The PostgreSQL provides Universally Unique Identifier -UUID data type and related functions.</p>
<p><strong><code>In the previous post, I shared the truth about Universally Unique Identifier - UUID.<br />
<a href="https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/" target="_blank">You can visit this article here</a>.</code></strong></p>
<p>PostgreSQL provides two extensions.</p>
<blockquote><p>1. uuid-ossp<br />
2. pgcrypto.</p></blockquote>
<p>You can install above extension using below script.</p><pre class="crayon-plain-tag">CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS pgcrypto;</pre><p>
I am using pgcrypto extension for generating an UUID.</p>
<p><strong>Below is a small demonstration:</strong></p>
<p><strong>Generate UUID using gen_random_uuid():</strong></p><pre class="crayon-plain-tag">SELECT gen_random_uuid();</pre><p>
<p><strong>Create a sample table with UUID Data type:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_UUIDSample
(  
   MyUUID UUID PRIMARY KEY DEFAULT gen_random_uuid()
   ,Name TEXT   
);</pre><p>
<p><strong>Insert sample data:</strong></p><pre class="crayon-plain-tag">INSERT INTO tbl_UUIDSample (Name)
VALUES
('Anvesh'),('Martin')
,('Roy'),('Jenny')
,('Ronic'),('Monika');</pre><p>
<p><strong>The Result:</strong></p><pre class="crayon-plain-tag">SELECT *FROM tbl_UUIDSample;</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUUID.png" rel="attachment wp-att-1897"><img loading="lazy" decoding="async" class="alignnone wp-image-1897 size-full" title="PostgreSQL UUID" src="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUUID.png" alt="PostgreSQL UUID" width="311" height="147" srcset="https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUUID.png 311w, https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUUID-300x142.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/03/PostgreSQLUUID-150x71.png 150w" sizes="auto, (max-width: 311px) 100vw, 311px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/03/postgresql-working-with-universally-unique-identifier-uuid-data-type/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Database Theory: The truth about Universally Unique Identifier &#8211; UUID</title>
		<link>https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/</link>
					<comments>https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 02 Mar 2016 20:13:17 +0000</pubDate>
				<category><![CDATA[Database Theory]]></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 topic]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[RDBMS]]></category>
		<category><![CDATA[Universally Unique Identifier]]></category>
		<category><![CDATA[UUID]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1884</guid>

					<description><![CDATA[I am Sharing an important theory for all Database Architects and Designers. We are following a common practice for creating a sequential, unique number for a database system. The best practice is to create a primary integer key for every table which represents the tuples. But you should also know about UUID. You can visit [&#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%2F03%2Fdatabase-theory-the-truth-about-universally-unique-identifier-uuid%2F&amp;linkname=Database%20Theory%3A%20The%20truth%20about%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID" 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%2F03%2Fdatabase-theory-the-truth-about-universally-unique-identifier-uuid%2F&amp;linkname=Database%20Theory%3A%20The%20truth%20about%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID" 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%2F03%2Fdatabase-theory-the-truth-about-universally-unique-identifier-uuid%2F&amp;linkname=Database%20Theory%3A%20The%20truth%20about%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID" 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%2F03%2Fdatabase-theory-the-truth-about-universally-unique-identifier-uuid%2F&amp;linkname=Database%20Theory%3A%20The%20truth%20about%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID" 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%2F03%2Fdatabase-theory-the-truth-about-universally-unique-identifier-uuid%2F&amp;linkname=Database%20Theory%3A%20The%20truth%20about%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID" 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%2F03%2Fdatabase-theory-the-truth-about-universally-unique-identifier-uuid%2F&amp;linkname=Database%20Theory%3A%20The%20truth%20about%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID" 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%2F03%2Fdatabase-theory-the-truth-about-universally-unique-identifier-uuid%2F&#038;title=Database%20Theory%3A%20The%20truth%20about%20Universally%20Unique%20Identifier%20%E2%80%93%20UUID" data-a2a-url="https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/" data-a2a-title="Database Theory: The truth about Universally Unique Identifier – UUID"></a></p><p>I am Sharing an important theory for all Database Architects and Designers. </p>
<p>We are following a common practice for creating a sequential, unique number for a database system.  </p>
<blockquote><p>
<em>The best practice is to create a primary integer key for every table which represents the tuples.<br />
But you should also know about UUID.<br />
</em><a href="https://www.dbrnd.com/2015/09/best-practice-for-primary-key-in-database-management-system/" target="_blank"><strong>You can visit this article on The truth about Primary Key. </strong></a></p></blockquote>
<p><strong>What is UUID and How it generates Unique Number?</strong></p>
<blockquote><p>UUID &#8211; Universally Unique Identifier has also stand as a unique string.</p>
<p>A UUID is a 128-bit number, and it used to identify different type of entities uniquely.<br />
The computation of the UUID is quick and easy to generate an ID which can be reasonably assumed to be universally unique. </p></blockquote>
<blockquote><p>The UUID is globally unique because it contains a unique combination of the network address, the timestamp of the transaction and other component details.<br />
The network address and timestamp of the transaction are enough to ensure uniqueness. </p></blockquote>
<p>Example, The standard form of UUID. It is total of 32 digits and representing the 128 bits.</p><pre class="crayon-plain-tag">c0acbc88-9q0b-4hq3-cc6u-8pp9er188a33</pre><p> </p>
<p><strong>Why we require UUID?</strong></p>
<blockquote><p>When we are working in the distributed environment system, we need UUID which identifies the integrated data from the different systems.</p></blockquote>
<blockquote><p>For example,<br />
We have two systems, System A and System B. Now I want to import some data from System A to System B without changing an ID of the source system. System B has already set of stored IDs which might conflict with System A IDs.</p>
<p>The UUID solves the above problem.</p></blockquote>
<blockquote><p>If the system is not online, the offline user also can generate a UUID at the client side for few operations. </p></blockquote>
<blockquote><p>A UUID always unique for all the systems which reside in a distributed environment. </p></blockquote>
<blockquote><p>For Example,<br />
System A inserts a record with ID 10 and at the same time System B also inserts a record with ID 10.<br />
Now, this is a collision.<br />
The UUID solves this problem.
</p></blockquote>
<blockquote><p>If the system is accessed by multiple threads, each thread has to wait for new IDs.<br />
A UUID also solve this problem because it does not depend on the previously generated key. </p></blockquote>
<blockquote><p>We can generate trillions of UUID in a year and it has very less chance of duplication. </p></blockquote>
<blockquote><p>If we recreate a Database or Table, again sequential ID starts from 1. In this kind of situations, we can use UUID. </p></blockquote>
<p><strong>Other limitations:</strong></p>
<blockquote><p>The index fragmentation is one of the major drawbacks of using UUID random keys. </p></blockquote>
<blockquote><p>We should not use UUID as a Primary key of a table. Still, I would suggest you create an integer sequential primary key and create a separate column for UUID. </p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/03/database-theory-the-truth-about-universally-unique-identifier-uuid/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
