<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ARUL SELVI ML</title>
    <description>The latest articles on DEV Community by ARUL SELVI ML (@arul_selviml_7).</description>
    <link>https://dev.to/arul_selviml_7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3834708%2Fa02c95d5-09ff-4be1-9a53-fd5f030a95f1.jpg</url>
      <title>DEV Community: ARUL SELVI ML</title>
      <link>https://dev.to/arul_selviml_7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arul_selviml_7"/>
    <language>en</language>
    <item>
      <title>Modifying Tables in SQL using ALTER</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Sat, 28 Mar 2026 17:34:56 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/modifying-tables-in-sql-using-alter-12dl</link>
      <guid>https://dev.to/arul_selviml_7/modifying-tables-in-sql-using-alter-12dl</guid>
      <description>&lt;h2&gt;
  
  
  1. Making a Column NOT NULL
&lt;/h2&gt;

&lt;p&gt;Suppose we already created a &lt;code&gt;customers&lt;/code&gt; table, but now we want to ensure that email is always provided.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Adding UNIQUE Constraint
&lt;/h2&gt;

&lt;p&gt;To make sure no two users have the same username:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;unique_username&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Adding CHECK Constraint
&lt;/h2&gt;

&lt;p&gt;We want to ensure product price is always greater than 0:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;check_price&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Setting DEFAULT Value
&lt;/h2&gt;

&lt;p&gt;To make &lt;code&gt;status = 'pending'&lt;/code&gt; by default:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="s1"&gt;'pending'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Adding a Column with Constraints
&lt;/h2&gt;

&lt;p&gt;Now we add a &lt;code&gt;salary&lt;/code&gt; column to employees:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Modifying Foreign Key with CASCADE
&lt;/h2&gt;

&lt;p&gt;To automatically delete employees when a department is deleted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;employees_department_id_fkey&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;employees_department_id_fkey&lt;/span&gt;
&lt;span class="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;department_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;departments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;CASCADE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Dropping a CHECK Constraint
&lt;/h2&gt;

&lt;p&gt;To remove the balance restriction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;
&lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;accounts_balance_check&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Adding Composite UNIQUE Constraint
&lt;/h2&gt;

&lt;p&gt;To ensure a combination is unique:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;payments&lt;/span&gt;
&lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;unique_user_transaction&lt;/span&gt;
&lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;transaction_id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>create tables</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Sat, 28 Mar 2026 16:40:45 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/create-tables-l58</link>
      <guid>https://dev.to/arul_selviml_7/create-tables-l58</guid>
      <description>&lt;h2&gt;
  
  
  1. Primary Key – Unique Identity
&lt;/h2&gt;

&lt;p&gt;Every table needs a way to identify each row uniquely. This is done using a &lt;strong&gt;PRIMARY KEY&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;CREATE TABLE students (&lt;br&gt;
    id INT PRIMARY KEY,&lt;br&gt;
    name VARCHAR(100),&lt;br&gt;
    age INT&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;So every student is uniquely identified.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. NOT NULL – Mandatory Fields
&lt;/h2&gt;

&lt;p&gt;Sometimes, certain fields must always have a value.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;phone_number&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name&lt;/code&gt; and &lt;code&gt;email&lt;/code&gt; are required&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;phone_number&lt;/code&gt; is optional&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. UNIQUE – No Duplicates Allowed
&lt;/h2&gt;

&lt;p&gt;If we don’t want duplicate values in a column, we use &lt;strong&gt;UNIQUE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;email&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures:&lt;/p&gt;

&lt;h2&gt;
  
  
  4. CHECK – Valid Data Only
&lt;/h2&gt;

&lt;p&gt;We can restrict values using conditions.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. DEFAULT – Automatic Values
&lt;/h2&gt;

&lt;p&gt;Sometimes we want a column to have a default value if none is provided.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="s1"&gt;'pending'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="nb"&gt;TIMESTAMP&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;CURRENT_TIMESTAMP&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Combining Constraints
&lt;/h2&gt;

&lt;p&gt;We can use multiple constraints together.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;account_number&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Composite Constraints
&lt;/h2&gt;

&lt;p&gt;Sometimes a combination of columns should be unique.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;enrollments&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;student_id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;course_id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;student_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;course_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Foreign Key – Connecting Tables
&lt;/h2&gt;

&lt;p&gt;Foreign keys help link tables together.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;departments&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;department_id&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;FOREIGN&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;department_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;departments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. CASCADE – Automatic Updates &amp;amp; Deletes
&lt;/h2&gt;

&lt;p&gt;We can control what happens when related data changes.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;dev&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;to&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;uploads&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;s3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amazonaws&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;uploads&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="n"&gt;adwzxri0qqs8hufztdj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl50h59tnww60cyhuqmv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl50h59tnww60cyhuqmv3.png" alt=" " width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Idempotency Situation</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Wed, 25 Mar 2026 13:25:18 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/idempotency-situation-odj</link>
      <guid>https://dev.to/arul_selviml_7/idempotency-situation-odj</guid>
      <description>&lt;p&gt;Today I tried to understand what happens when the same transaction is executed multiple times in a database. This can happen in real applications like PhonePe or GPay when there are network issues and the same request is sent again.&lt;/p&gt;

&lt;p&gt;I used the same accounts table where Alice has 1000 and Bob has 500. First, I performed a normal transfer of 200 from Alice to Bob.&lt;/p&gt;

&lt;p&gt;BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;After this, Alice had 800 and Bob had 700. Everything was correct.&lt;/p&gt;

&lt;p&gt;Then I repeated the same transaction again, as if the same request was sent twice.&lt;/p&gt;

&lt;p&gt;BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;Now the balances became Alice 600 and Bob 900. This means the same transaction was applied again. The database did not stop it.&lt;/p&gt;

&lt;p&gt;From this, I understood that PostgreSQL does not automatically prevent duplicate transactions. It will execute whatever queries we send, even if they are repeated.&lt;/p&gt;

&lt;p&gt;This can be dangerous in real systems because users may lose money or get incorrect balances if the same request is processed multiple times.&lt;/p&gt;

&lt;p&gt;To handle this, real world systems use additional logic. One common approach is using a unique transaction id. Every transaction is given a unique id, and the system checks if that id is already processed. If it is already present, the system ignores the duplicate request.&lt;/p&gt;

&lt;p&gt;Another approach is to maintain a transaction history table and check before processing any new request. Some systems also use locking or idempotent operations to avoid repeating the same effect.&lt;/p&gt;

&lt;p&gt;I understood that while the database ensures safety using ACID properties, it does not automatically handle duplicate requests. That responsibility is handled by the application design.&lt;/p&gt;

&lt;p&gt;Overall, this helped me understand the importance of handling repeated transactions carefully in real world financial systems.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>devjournal</category>
      <category>sql</category>
    </item>
    <item>
      <title>Durability</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Wed, 25 Mar 2026 13:20:46 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/durability-h20</link>
      <guid>https://dev.to/arul_selviml_7/durability-h20</guid>
      <description>&lt;p&gt;Today I learned about durability in databases by doing a small experiment using a wallet system example.&lt;/p&gt;

&lt;p&gt;I used the same accounts table where Alice has 1000 and Bob has 500. First, I checked the initial balances to make sure the data is correct.&lt;/p&gt;

&lt;p&gt;Then I performed a money transfer from Alice to Bob.&lt;/p&gt;

&lt;p&gt;BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 300&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 300&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;After committing the transaction, I checked the balances again. Alice’s balance became 700 and Bob’s balance became 800. This showed that the transaction was successful.&lt;/p&gt;

&lt;p&gt;Next, I wanted to test what happens if the system restarts. So I disconnected and reconnected to the database, similar to a system restart. After reconnecting, I queried the accounts table again.&lt;/p&gt;

&lt;p&gt;I observed that the balances were still 700 and 800. The changes were not lost. This shows that once a transaction is committed, the data is stored permanently.&lt;/p&gt;

&lt;p&gt;From this, I understood the concept of durability. It means that once a transaction is completed and committed, the data will remain safe even if there is a crash or restart.&lt;/p&gt;

&lt;p&gt;I also thought about what happens if a failure occurs before commit. In that case, the transaction will not be saved, and the database will roll back to the previous state. So no partial changes will be stored.&lt;/p&gt;

&lt;p&gt;If a failure happens just after commit, the database uses log files to make sure the data is not lost. PostgreSQL writes changes to a log before saving them to the actual data files. This helps in recovering the data after a crash.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>database</category>
      <category>sql</category>
    </item>
    <item>
      <title>Isolation</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Wed, 25 Mar 2026 13:18:06 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/isolation-1npn</link>
      <guid>https://dev.to/arul_selviml_7/isolation-1npn</guid>
      <description>&lt;p&gt;Today I tried to understand how isolation works in a database by simulating multiple users using the same account at the same time. This is very important for applications like PhonePe or GPay because many users can perform transactions at once.&lt;/p&gt;

&lt;p&gt;I used the same accounts table where Alice has 1000 balance. Then I opened two database sessions to act like two different users.&lt;/p&gt;

&lt;p&gt;In the first session, I started a transaction and deducted money from Alice’s account but did not commit it.&lt;/p&gt;

&lt;p&gt;BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 700&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;At this point, the balance is reduced inside this transaction, but it is not yet saved permanently.&lt;/p&gt;

&lt;p&gt;Now in the second session, I also started a transaction and tried to read Alice’s balance.&lt;/p&gt;

&lt;p&gt;BEGIN;&lt;/p&gt;

&lt;p&gt;SELECT * FROM accounts WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;I observed that the second session still showed the old balance as 1000. It did not see the uncommitted change from the first session. This means dirty read is prevented.&lt;/p&gt;

&lt;p&gt;Then I tried to update again in the second session.&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 500&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;This query did not execute immediately. It waited until the first transaction was either committed or rolled back. This showed that PostgreSQL is preventing conflicts between transactions.&lt;/p&gt;

&lt;p&gt;Next, I committed the first transaction.&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;After that, the second transaction continued and used the updated balance. This ensured that the final result was correct and no money was lost.&lt;/p&gt;

&lt;p&gt;I repeated this experiment with different isolation levels. In the default level, which is read committed, I saw that uncommitted data is not visible. This prevents dirty reads.&lt;/p&gt;

&lt;p&gt;When I thought about lower isolation like read uncommitted, such problems could happen, but PostgreSQL does not actually allow dirty reads even in that mode.&lt;/p&gt;

&lt;p&gt;I understood that isolation ensures that multiple transactions do not interfere with each other. It prevents problems like reading incomplete data, updating wrong values, or losing updates.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
    </item>
    <item>
      <title>Consistency</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Wed, 25 Mar 2026 13:13:40 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/consistency-1679</link>
      <guid>https://dev.to/arul_selviml_7/consistency-1679</guid>
      <description>&lt;p&gt;Today I explored how databases maintain correct data using consistency rules, especially in a wallet system like PhonePe or GPay.&lt;/p&gt;

&lt;p&gt;I used the same accounts table where Alice has 1000 and Bob has 500. One important thing in this table is the condition that balance should never be negative. This rule is already defined in the table using a check condition.&lt;/p&gt;

&lt;p&gt;First, I tried a normal update where I deduct a valid amount.&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;This worked fine because Alice still had a positive balance.&lt;/p&gt;

&lt;p&gt;Then I tried something wrong. I attempted to deduct more money than Alice has.&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 2000&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;This time, PostgreSQL did not allow the update. It gave an error because the balance would become negative. This showed that the database itself is enforcing the rule.&lt;/p&gt;

&lt;p&gt;Next, I tried directly setting a negative balance.&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = -100&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;Again, the database rejected the query. This is because of the check constraint defined in the table. So even if I try to manually break the rule, the database does not allow it.&lt;/p&gt;

&lt;p&gt;After this, I understood that consistency is maintained in two ways.&lt;/p&gt;

&lt;p&gt;One way is through database constraints. In this case, the check condition ensures that balance is always zero or positive. This is handled directly by PostgreSQL.&lt;/p&gt;

&lt;p&gt;Another way is through application logic or transactions. For example, before transferring money, the application should check if the sender has enough balance. This avoids unnecessary errors and improves user experience.&lt;/p&gt;

&lt;p&gt;So, constraints act as a safety layer, while application logic acts as a control layer.&lt;/p&gt;

&lt;p&gt;I clearly understood that PostgreSQL does not allow invalid data to enter the system. Even if a developer makes a mistake, the database prevents wrong updates.&lt;/p&gt;

&lt;p&gt;Overall, this helped me understand how consistency is maintained and why it is very important in financial systems where even a small mistake can cause serious problems.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>Atomicity - Design a Reliable Wallet Transfer System with ACID Guarantees</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Wed, 25 Mar 2026 13:09:50 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/atomicity-design-a-reliable-wallet-transfer-system-with-acid-guarantees-43pe</link>
      <guid>https://dev.to/arul_selviml_7/atomicity-design-a-reliable-wallet-transfer-system-with-acid-guarantees-43pe</guid>
      <description>&lt;p&gt;Today I worked on a small database problem where I tried to understand how money transfer works in applications like PhonePe or GPay. The main idea was to see how databases handle transactions safely using ACID properties.&lt;/p&gt;

&lt;p&gt;First, I created a simple accounts table with id, name, and balance. I inserted two users, Alice with balance 1000 and Bob with balance 500. This helped me simulate a real scenario of transferring money between users.&lt;/p&gt;

&lt;p&gt;Before starting the transaction, I checked the data. Alice had 1000 and Bob had 500.&lt;/p&gt;

&lt;p&gt;Then I wrote a transaction to transfer 200 from Alice to Bob.&lt;/p&gt;

&lt;p&gt;BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;After running this, I checked the table again. Alice’s balance became 800 and Bob’s balance became 700. This showed a successful transaction.&lt;/p&gt;

&lt;p&gt;Next, I wanted to see what happens when something goes wrong. So I introduced an error after deducting money from Alice.&lt;/p&gt;

&lt;p&gt;BEGIN;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance - 200&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;SELECT * FROM wrong_table;&lt;/p&gt;

&lt;p&gt;UPDATE accounts&lt;br&gt;
SET balance = balance + 200&lt;br&gt;
WHERE name = 'Bob';&lt;/p&gt;

&lt;p&gt;COMMIT;&lt;/p&gt;

&lt;p&gt;Here, the second step caused an error because the table does not exist. Because of this, the transaction failed.&lt;/p&gt;

&lt;p&gt;After that, I checked the balances again. I expected Alice’s balance to be reduced, but surprisingly it was still 1000 and Bob was still 500. This means the database did not save the partial change.&lt;/p&gt;

&lt;p&gt;This clearly showed the concept of atomicity. Even though one update was executed, since the full transaction did not complete, everything was rolled back.&lt;/p&gt;

&lt;p&gt;If the system allowed partial updates, it could lead to money loss or incorrect balances.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>database</category>
      <category>sql</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Overview of PostgreSQL architecture and ACID</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Wed, 25 Mar 2026 13:00:44 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/overview-of-postgresql-architecture-and-acid-1gap</link>
      <guid>https://dev.to/arul_selviml_7/overview-of-postgresql-architecture-and-acid-1gap</guid>
      <description>&lt;p&gt;Today I learned about PostgreSQL architecture in a more detailed way by understanding each component.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The process starts from the client. A user or application sends a query to the PostgreSQL server through an API or connection layer. Once the request reaches the server, the query processing begins. The system first checks the query, then plans how to execute it, and finally runs it to get the result.&lt;/li&gt;
&lt;li&gt;Inside the server, one important part is the shared buffer. This is a memory area where frequently used data is stored. Instead of going to the disk every time, PostgreSQL first checks the shared buffer. This makes the system faster.&lt;/li&gt;
&lt;li&gt;Another important concept is write ahead logging. Before updating the actual data in storage, PostgreSQL writes the changes into a WAL log. This ensures that even if the system crashes, the data can be recovered.&lt;/li&gt;
&lt;li&gt;There are different background processes related to WAL. The WAL writer is responsible for writing log records from memory to the WAL files. The WAL sender sends these log records to another server in case of replication. On the other side, the WAL receiver receives the logs and applies them to keep the standby server updated.&lt;/li&gt;
&lt;li&gt;The storage layer contains the actual data like tables and indexes. Data is read from and written to the disk when needed.&lt;/li&gt;
&lt;li&gt;Another important background process is autovacuum. In PostgreSQL, when data is updated or deleted, the old data is not immediately removed. It remains as unused space. The autovacuum process automatically cleans this unused data and frees up space. It also helps maintain database performance by preventing the database from becoming slow over time.&lt;/li&gt;
&lt;li&gt;Along with this, other background processes keep running to manage tasks like saving data to disk and maintaining stability.&lt;/li&gt;
&lt;li&gt;Finally, after processing everything, the result is sent back to the client.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Overall, learning these components like shared buffer, WAL writer, WAL sender, WAL receiver, and autovacuum helped me understand how PostgreSQL manages performance, data safety, and maintenance in a real system.&lt;br&gt;
&lt;strong&gt;ACID&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties are very important because they make sure that database transactions are reliable and the data remains correct.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Atomicity means all operations in a transaction should happen completely or not happen at all. There is no partial execution. For example, in a bank transfer, if money is deducted from one account but not added to another account, the transaction will be cancelled. So either both actions happen or none happens.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consistency means the database should always follow rules and constraints. Before and after a transaction, the data must remain valid. For example, if a rule says account balance cannot be negative, the system will not allow a transaction that breaks this rule.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Isolation means multiple transactions happening at the same time should not affect each other. Each transaction should work as if it is running alone. For example, if two users are accessing the same account, one user should not see incomplete changes made by another user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Durability means once a transaction is successfully completed, the data is permanently stored. Even if there is a system crash or power failure, the data will not be lost because it is saved properly in the database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A simple example to understand all these properties is a bank transfer system. When a person transfers money, the system ensures that the amount is deducted and added correctly, rules are followed, other users do not see intermediate changes, and once the transaction is completed, it is saved permanently.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Merge Two Sorted Linked Lists</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Tue, 24 Mar 2026 16:04:40 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/merge-two-sorted-linked-lists-4de3</link>
      <guid>https://dev.to/arul_selviml_7/merge-two-sorted-linked-lists-4de3</guid>
      <description>&lt;h1&gt;
  
  
  Merge Two Sorted Linked Lists
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given the heads of two sorted linked lists, merge them into one sorted linked list and return the head of the merged list.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Input&lt;br&gt;
List1&lt;br&gt;
1 -&amp;gt; 2 -&amp;gt; 4&lt;/p&gt;

&lt;p&gt;List2&lt;br&gt;
1 -&amp;gt; 3 -&amp;gt; 4&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
1 -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 4&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach Iterative Method
&lt;/h2&gt;

&lt;p&gt;Compare nodes from both lists and build a new sorted list.&lt;/p&gt;




&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;1 Create a dummy node to store result&lt;br&gt;
2 Compare values of both lists&lt;br&gt;
3 Attach smaller node to result&lt;br&gt;
4 Move pointer of that list&lt;br&gt;
5 Repeat until one list becomes empty&lt;br&gt;
6 Attach remaining nodes&lt;/p&gt;




&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;p&gt;```python id="mll1"&lt;br&gt;
class ListNode:&lt;br&gt;
    def &lt;strong&gt;init&lt;/strong&gt;(self, val=0, next=None):&lt;br&gt;
        self.val = val&lt;br&gt;
        self.next = next&lt;/p&gt;

&lt;p&gt;def mergeTwoLists(l1, l2):&lt;br&gt;
    dummy = ListNode(0)&lt;br&gt;
    tail = dummy&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while l1 and l2:
    if l1.val &amp;lt; l2.val:
        tail.next = l1
        l1 = l1.next
    else:
        tail.next = l2
        l2 = l2.next
    tail = tail.next

if l1:
    tail.next = l1
if l2:
    tail.next = l2

return dummy.next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

## Approach Recursive Method

---

### Code



```python id="mll2"
def mergeTwoLists(l1, l2):
    if not l1:
        return l2
    if not l2:
        return l1

    if l1.val &amp;lt; l2.val:
        l1.next = mergeTwoLists(l1.next, l2)
        return l1
    else:
        l2.next = mergeTwoLists(l1, l2.next)
        return l2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;p&gt;The iterative method builds the merged list step by step using a dummy node. The recursive method compares nodes and builds the list during function calls.&lt;/p&gt;




&lt;h2&gt;
  
  
  Expected Output
&lt;/h2&gt;

&lt;p&gt;Input&lt;br&gt;
1 -&amp;gt; 2 -&amp;gt; 4&lt;br&gt;
1 -&amp;gt; 3 -&amp;gt; 4&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
1 -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 4&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Merging two sorted linked lists is a basic and important problem. It helps in understanding linked list traversal and pointer manipulation.&lt;/p&gt;

&lt;p&gt;Practice both iterative and recursive methods to improve your coding skills.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>dsa</category>
      <category>interview</category>
      <category>python</category>
    </item>
    <item>
      <title>Sort a Linked List using Merge Sort</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Tue, 24 Mar 2026 16:02:52 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/sort-a-linked-list-using-merge-sort-2mhk</link>
      <guid>https://dev.to/arul_selviml_7/sort-a-linked-list-using-merge-sort-2mhk</guid>
      <description>&lt;h1&gt;
  
  
  Sort a Linked List using Merge Sort
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given the head of a linked list, sort the list in ascending order using merge sort and return the sorted list.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Input&lt;br&gt;
4 -&amp;gt; 2 -&amp;gt; 1 -&amp;gt; 3&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4&lt;/p&gt;




&lt;p&gt;Input&lt;br&gt;
-1 -&amp;gt; 5 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 0&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
-1 -&amp;gt; 0 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 5&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach Merge Sort on Linked List
&lt;/h2&gt;

&lt;p&gt;Merge sort works by dividing the list into halves, sorting each half, and then merging them.&lt;/p&gt;




&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;p&gt;1 Find the middle of the linked list&lt;br&gt;
2 Split the list into two halves&lt;br&gt;
3 Recursively sort both halves&lt;br&gt;
4 Merge the sorted halves&lt;/p&gt;




&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;p&gt;```python id="msll1"&lt;br&gt;
class ListNode:&lt;br&gt;
    def &lt;strong&gt;init&lt;/strong&gt;(self, val=0, next=None):&lt;br&gt;
        self.val = val&lt;br&gt;
        self.next = next&lt;/p&gt;

&lt;p&gt;def getMiddle(head):&lt;br&gt;
    slow = head&lt;br&gt;
    fast = head.next&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while fast and fast.next:
    slow = slow.next
    fast = fast.next.next

return slow
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;def merge(l1, l2):&lt;br&gt;
    dummy = ListNode(0)&lt;br&gt;
    tail = dummy&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while l1 and l2:
    if l1.val &amp;lt; l2.val:
        tail.next = l1
        l1 = l1.next
    else:
        tail.next = l2
        l2 = l2.next
    tail = tail.next

if l1:
    tail.next = l1
if l2:
    tail.next = l2

return dummy.next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;def sortList(head):&lt;br&gt;
    if not head or not head.next:&lt;br&gt;
        return head&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mid = getMiddle(head)
right = mid.next
mid.next = None

left_sorted = sortList(head)
right_sorted = sortList(right)

return merge(left_sorted, right_sorted)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

## Explanation

The linked list is divided into two halves using the slow and fast pointer method. Each half is sorted recursively. Finally, both halves are merged into a sorted list.

---

## Expected Output

Input
4 -&amp;gt; 2 -&amp;gt; 1 -&amp;gt; 3

Output
1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4

---

## Conclusion

Merge sort is very efficient for linked lists because it does not require random access. This problem helps in understanding recursion and linked list manipulation.

Practice this problem to strengthen your understanding of sorting and linked lists.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Remove Duplicates from Sorted Linked List</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Tue, 24 Mar 2026 16:01:18 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/remove-duplicates-from-sorted-linked-list-160m</link>
      <guid>https://dev.to/arul_selviml_7/remove-duplicates-from-sorted-linked-list-160m</guid>
      <description>&lt;h1&gt;
  
  
  Remove Duplicates from Sorted Linked List
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Input&lt;br&gt;
1 -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 3&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
1 -&amp;gt; 2 -&amp;gt; 3&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach Iterative Method
&lt;/h2&gt;

&lt;p&gt;Since the list is already sorted, duplicates will be adjacent. We can compare current node with the next node and remove duplicates.&lt;/p&gt;




&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;

&lt;p&gt;1 Start from the head node&lt;br&gt;
2 Compare current node with next node&lt;br&gt;
3 If both values are equal, skip the next node&lt;br&gt;
4 Else move to the next node&lt;br&gt;
5 Repeat until end of list&lt;/p&gt;




&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;p&gt;```python id="rdll1"&lt;br&gt;
class ListNode:&lt;br&gt;
    def &lt;strong&gt;init&lt;/strong&gt;(self, val=0, next=None):&lt;br&gt;
        self.val = val&lt;br&gt;
        self.next = next&lt;/p&gt;

&lt;p&gt;def deleteDuplicates(head):&lt;br&gt;
    current = head&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while current and current.next:
    if current.val == current.next.val:
        current.next = current.next.next
    else:
        current = current.next

return head
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

## Explanation

Since the list is sorted, all duplicate values are next to each other. We simply skip the duplicate nodes by changing the pointer of the current node.

---

## Expected Output

Input
1 -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 3

Output
1 -&amp;gt; 2 -&amp;gt; 3

---

## Conclusion

This problem helps in understanding linked list traversal and pointer manipulation. It is simple yet important for mastering linked list operations.

Practice this problem to improve your confidence in working with linked lists.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>Reverse a Linked List</title>
      <dc:creator>ARUL SELVI ML</dc:creator>
      <pubDate>Tue, 24 Mar 2026 15:59:40 +0000</pubDate>
      <link>https://dev.to/arul_selviml_7/reverse-a-linked-list-560p</link>
      <guid>https://dev.to/arul_selviml_7/reverse-a-linked-list-560p</guid>
      <description>&lt;h1&gt;
  
  
  Reverse a Linked List
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given the head of a singly linked list, reverse the list and return the new head.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example
&lt;/h2&gt;

&lt;p&gt;Input&lt;br&gt;
1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 5&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
5 -&amp;gt; 4 -&amp;gt; 3 -&amp;gt; 2 -&amp;gt; 1&lt;/p&gt;




&lt;h2&gt;
  
  
  Approach 1 Iterative Method
&lt;/h2&gt;

&lt;p&gt;Reverse the links of the list one by one.&lt;/p&gt;




&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;

&lt;p&gt;1 Initialize three pointers previous as None, current as head, next as None&lt;br&gt;
2 Traverse the list&lt;br&gt;
3 Store next node&lt;br&gt;
4 Reverse current node link&lt;br&gt;
5 Move previous and current one step forward&lt;br&gt;
6 Repeat until current becomes None&lt;/p&gt;




&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;



&lt;p&gt;```python id="ll1"&lt;br&gt;
class ListNode:&lt;br&gt;
    def &lt;strong&gt;init&lt;/strong&gt;(self, val=0, next=None):&lt;br&gt;
        self.val = val&lt;br&gt;
        self.next = next&lt;/p&gt;

&lt;p&gt;def reverseList(head):&lt;br&gt;
    prev = None&lt;br&gt;
    curr = head&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while curr:
    next_node = curr.next
    curr.next = prev
    prev = curr
    curr = next_node

return prev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


---

## Approach 2 Recursive Method

Reverse the list using recursion.

---

### Code



```python id="ll2"
def reverseList(head):
    if not head or not head.next:
        return head

    new_head = reverseList(head.next)

    head.next.next = head
    head.next = None

    return new_head
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;p&gt;In the iterative method, we reverse the direction of pointers step by step.&lt;br&gt;
In the recursive method, we reverse the rest of the list and then fix the current node.&lt;/p&gt;




&lt;h2&gt;
  
  
  Expected Output
&lt;/h2&gt;

&lt;p&gt;Input&lt;br&gt;
1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 5&lt;/p&gt;

&lt;p&gt;Output&lt;br&gt;
5 -&amp;gt; 4 -&amp;gt; 3 -&amp;gt; 2 -&amp;gt; 1&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Reversing a linked list is a fundamental problem that helps in understanding pointers and data structures. It is frequently asked in coding interviews.&lt;/p&gt;

&lt;p&gt;Practice both iterative and recursive methods to strengthen your understanding.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>beginners</category>
      <category>dsa</category>
      <category>python</category>
    </item>
  </channel>
</rss>
