<?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: JAYA SRI J</title>
    <description>The latest articles on DEV Community by JAYA SRI J (@jaya_srij_c37a6ea796335c).</description>
    <link>https://dev.to/jaya_srij_c37a6ea796335c</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%2F3837089%2Ff9492909-8f4c-4d7f-ae28-b3ac8c6870b0.png</url>
      <title>DEV Community: JAYA SRI J</title>
      <link>https://dev.to/jaya_srij_c37a6ea796335c</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jaya_srij_c37a6ea796335c"/>
    <language>en</language>
    <item>
      <title>consistency</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:17:39 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/consistency-11pb</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/consistency-11pb</guid>
      <description>&lt;p&gt;Let us start with the accounts table, which stores user balance information.&lt;/p&gt;

&lt;p&gt;CREATE TABLE accounts (&lt;br&gt;
    id SERIAL PRIMARY KEY,&lt;br&gt;
    name TEXT NOT NULL,&lt;br&gt;
    balance INT NOT NULL CHECK (balance &amp;gt;= 0),&lt;br&gt;
    last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;Here, the most important rule is the CHECK constraint on balance. It ensures that the balance can never go below zero. This is a database-level safety mechanism that protects against invalid data.&lt;/p&gt;

&lt;p&gt;Now, insert some sample data.&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;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this stage, both users have valid balances, and the system is consistent.&lt;/p&gt;

&lt;p&gt;Now consider a situation where Alice tries to send more money than she has. For example, deducting 1500 from Alice’s account.&lt;/p&gt;

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

&lt;p&gt;PostgreSQL will reject this operation because it violates the CHECK constraint (balance &amp;gt;= 0). The database will throw an error and prevent the update from happening. This shows that the database itself enforces rules to maintain valid data.&lt;/p&gt;

&lt;p&gt;Next, consider directly trying to set a negative balance.&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;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, PostgreSQL will block this operation because it breaks the CHECK constraint. This confirms that constraints act as a safety net at the database level.&lt;/p&gt;

&lt;p&gt;However, not all problems can be solved using constraints alone. Consider a money transfer between two users. A transfer involves two steps: deducting money from one account and adding it to another. If one step succeeds and the other fails, the system becomes inconsistent.&lt;/p&gt;

&lt;p&gt;To handle this, we use transactions.&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;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If both operations succeed, the transaction is committed and the system remains consistent. But if any error occurs in between, we can roll back the entire transaction.&lt;/p&gt;

&lt;p&gt;ROLLBACK;&lt;/p&gt;

&lt;p&gt;This ensures that either both operations happen or none happen, preventing partial updates.&lt;/p&gt;

&lt;p&gt;Now consider a failure scenario where the first query runs but the second fails due to some error. Without a transaction, Alice’s balance would be reduced but Bob would not receive the money. This leads to money loss. With transactions, the system automatically rolls back and restores the original state.&lt;/p&gt;

&lt;p&gt;From these observations, we can clearly distinguish two types of rules.&lt;/p&gt;

&lt;p&gt;Application or transaction-level rules handle complex operations like money transfers. These ensure that multiple related operations are executed safely and completely.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>create tabel</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:03:21 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/create-tabel-558h</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/create-tabel-558h</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Create a table called students where each student has an id, name, and age, and ensure that the id uniquely identifies each student.
&lt;/li&gt;
&lt;/ol&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;students&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;age&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a table employees where name and email cannot be empty, but phone_number can be optional.
&lt;/li&gt;
&lt;/ol&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;ol&gt;
&lt;li&gt;Create a table users where both username and email must be unique across all records.
&lt;/li&gt;
&lt;/ol&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;ol&gt;
&lt;li&gt;Create a table products where price must always be greater than 0 and stock cannot be negative.
&lt;/li&gt;
&lt;/ol&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;ol&gt;
&lt;li&gt;Create a table orders where status should default to 'pending' if no value is provided, and created_at should store the current timestamp automatically.
&lt;/li&gt;
&lt;/ol&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;ol&gt;
&lt;li&gt;Create a table accounts where account_number must be unique and not null, and balance must always be greater than or equal to 0.
&lt;/li&gt;
&lt;/ol&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;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;account_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;20&lt;/span&gt;&lt;span class="p"&gt;)&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;ol&gt;
&lt;li&gt;Create a table enrollments where a student can enroll in multiple courses, but the combination of student_id and course_id must be unique.
&lt;/li&gt;
&lt;/ol&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;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;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;ol&gt;
&lt;li&gt;Create two tables: departments with id and name, and employees with id, name, and department_id, ensuring that department_id in employees must exist in departments.
&lt;/li&gt;
&lt;/ol&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;ol&gt;
&lt;li&gt;Modify the previous foreign key example so that when a department is deleted, all related employees are also deleted, and when a department ID is updated, it reflects in the employees table.
&lt;/li&gt;
&lt;/ol&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="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="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;UPDATE&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;



</description>
    </item>
    <item>
      <title>ALTER</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Sun, 29 Mar 2026 15:48:39 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/alter-3ii5</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/alter-3ii5</guid>
      <description>&lt;p&gt;To ensure that every customer must provide an email in the future, we need to prevent NULL values in the email column. This enforces data completeness and avoids issues like missing contact information.&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;p&gt;This change guarantees that all future inserts must include an email value.&lt;/p&gt;

&lt;p&gt;Usernames are typically used for login or identification, so they must be unique. To enforce this at the database level, we add a unique constraint.&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;p&gt;This prevents duplicate usernames and ensures consistency across the system.&lt;/p&gt;

&lt;p&gt;In a products table, price should never be zero or negative. To enforce this rule, we add a check constraint.&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_positive&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;p&gt;This ensures that only valid product prices are stored.&lt;/p&gt;

&lt;p&gt;For an orders table, it is common to assign a default status when none is provided. This avoids NULL values and keeps workflows predictable.&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;p&gt;Now, if no status is specified during insertion, it will automatically be set to 'pending'.&lt;/p&gt;

&lt;p&gt;When adding a salary column to the employees table, we must ensure two things: it cannot be NULL and it must be greater than 10,000. This requires both a column addition and constraints.&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;INT&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;p&gt;This enforces both presence and validity of salary values.&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;employeesADD&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;p&gt;This ensures referential integrity by automatically cleaning up dependent records.&lt;/p&gt;

&lt;p&gt;Sometimes business rules change, and constraints need to be removed. For example, if the accounts table no longer requires balance to be non-negative, we can drop the check constraint.&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;p&gt;This removes the restriction and allows more flexible balance values.&lt;/p&gt;

&lt;p&gt;To ensure that each payment is uniquely identified per user, we enforce a composite unique constraint on user_id and transaction_id.&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;



&lt;p&gt;This prevents duplicate transactions for the same user.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Atomicity</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Sun, 29 Mar 2026 15:42:50 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/atomicity-1396</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/atomicity-1396</guid>
      <description>&lt;p&gt;** 1: Initial Setup**&lt;/p&gt;

&lt;p&gt;We already have the accounts table:&lt;/p&gt;

&lt;p&gt;CREATE TABLE accounts (&lt;br&gt;
    id SERIAL PRIMARY KEY,&lt;br&gt;
    name TEXT NOT NULL,&lt;br&gt;
    balance INT NOT NULL CHECK (balance &amp;gt;= 0),&lt;br&gt;
    last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;Insert dummy data:&lt;/p&gt;

&lt;p&gt;INSERT INTO accounts (name, balance) VALUES ('Alice', 1000),('Bob', 500);&lt;/p&gt;

&lt;p&gt;** 2: Check Initial State**&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&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;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Alice is 1000
Bob is 500
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is our starting point.&lt;/p&gt;

&lt;p&gt;** 3: Correct Money Transfer**&lt;/p&gt;

&lt;p&gt;We transfer 200 from Alice to Bob.&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;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;/p&gt;

&lt;p&gt;BEGIN starts the transaction next update deducts money from Alice.Then update adds money to Bob.COMMIT saves changes permanently&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;After Transaction&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&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;p&gt;Alice is  800&lt;br&gt;
Bob is  700&lt;/p&gt;

&lt;p&gt;This is correct behavior.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4: Failure Scenario&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we simulate a failure after deducting money.&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;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simulated error&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;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;nam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What Happens Here?&lt;/p&gt;

&lt;p&gt;First query succeeds belongs  Alice becomes 800&lt;br&gt;
Second query fails belongs  column error&lt;br&gt;
Transaction stops&lt;br&gt;
Important Point&lt;/p&gt;

&lt;p&gt;Since an error occurred, the transaction is not committed.&lt;/p&gt;

&lt;p&gt;Check Data&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&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;p&gt;Result&lt;br&gt;
Alice is  1000&lt;br&gt;
Bob is 500&lt;br&gt;
Explanation&lt;/p&gt;

&lt;p&gt;Even though the debit query ran, the database rolled back everything.&lt;/p&gt;

&lt;p&gt;This proves Atomicity:&lt;br&gt;
Either both updates happen, or none happen.&lt;/p&gt;

&lt;p&gt;5: Failure Scenario&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;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Bob'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What Happens?&lt;br&gt;
Alice’s balance would go negative But we have a constraint: CHECK (balance &amp;gt;= 0)&lt;br&gt;
So the query fails&lt;br&gt;
Final State&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&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;p&gt;Alice is 1000&lt;br&gt;
Bob is  500&lt;br&gt;
Explanation&lt;/p&gt;

&lt;p&gt;The database prevents invalid data and rolls back the transaction.&lt;/p&gt;

&lt;p&gt;Step 6: Failure Scenario&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;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Alice'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;ROLLBACK&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result&lt;br&gt;
Transaction is canceled manually,No changes are saved&lt;br&gt;
Final State&lt;br&gt;
Alice is  1000&lt;br&gt;
Bob is  500&lt;/p&gt;

&lt;p&gt;Step 8: Real-World Improvement&lt;/p&gt;

&lt;p&gt;In real systems, we also add:&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;BEGIN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;AND&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;200&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&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;COMMIT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>filter assigment</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Sun, 29 Mar 2026 15:29:45 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/filter-assigment-57cn</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/filter-assigment-57cn</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. Movies where special features are not lis&lt;/strong&gt;ted&lt;/p&gt;

&lt;p&gt;Sometimes data is missing. In SQL, missing values are stored as NULL.&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;special_features&lt;/span&gt; &lt;span class="k"&gt;IS&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;p&gt;Explanation&lt;br&gt;
We cannot use = with NULL because NULL means "unknown" So we use IS NULL to check if the column has no value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Movies with rental duration more than 7 days&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;  &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;rental_duration&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;We use &amp;gt; to filter movies whose rental period is greater than 7 days.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Movies with rental rate 4.99 and replacement cost &amp;gt; 20&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;AND means both conditions must be true We are filtering premium movies that are costly to replace.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Movies with rental rate 0.99 or rating PG-13&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'PG-13'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;OR means either condition can be true This helps find cheap movies or specific rated movies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. First 5 movies sorted alphabetically&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;ASC&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;ORDER BY sorts the titles alphabetically the LIMIT 5 ensures only the first 5 records are shown.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Skip first 10 and fetch next 3 highest replacement cost&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;replacement_cost&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="k"&gt;OFFSET&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;We first sort movies by highest replacement cost OFFSET 10 skips the first 10 rows LIMIT 3 gives the next 3 rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Movies with rating G, PG, or PG-13&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'G'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'PG'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'PG-13'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;IN is used when checking multiple values is cleaner than writing multiple OR conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Movies with rental rate between 2 and 4&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;BETWEEN includes both 2 and 4 it  simplifies range conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Movies with titles starting with "The"&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'The%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;LIKE is used for pattern matching % means any characters after "The".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. First 10 movies with multiple conditions&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;rental_rate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'R'&lt;/span&gt;&lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%Love%'&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;We combine conditions:&lt;/p&gt;

&lt;p&gt;rental rate is either 2.99 or 4.99 ,rating must be R and title must contain "Love"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. Titles containing % symbol&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%&lt;/span&gt;&lt;span class="se"&gt;\%&lt;/span&gt;&lt;span class="s1"&gt;%'&lt;/span&gt; &lt;span class="k"&gt;ESCAPE&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s1"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;% is normally a wildcard it  search the  literally, we escape it using .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;12. Titles containing underscore (_)&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%&lt;/span&gt;&lt;span class="se"&gt;\_&lt;/span&gt;&lt;span class="s1"&gt;%'&lt;/span&gt; &lt;span class="k"&gt;ESCAPE&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s1"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;_ means one character in SQL it  escape it to treat it as a normal character.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13. Titles starting with A or B and ending with s&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'A%s'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'B%s'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;br&gt;
A%s ---&amp;gt; starts with A, ends with s&lt;br&gt;
B%s ---&amp;gt; starts with B, ends with s&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;14. Titles containing Man, Men, or Woman&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%Man%'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%Men%'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%Woman%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;br&gt;
We search for specific words inside the title using %.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;15. Titles containing digits&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="n"&gt;REGEXP&lt;/span&gt; &lt;span class="s1"&gt;'[0-9]'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;16. Titles containing backslash ()&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%&lt;/span&gt;&lt;span class="se"&gt;\\\\&lt;/span&gt;&lt;span class="s1"&gt;%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;Backslash is a special escape character So we use double escaping (\\) to match a single .&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Titles containing "Love" or "Hate"
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%Love%'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%Hate%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;br&gt;
We check if either word exists anywhere in the title.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;18. First 5 movies ending with "er", "or", or "ar"&lt;/strong&gt;&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;film&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%er'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%or'&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'%ar'&lt;/span&gt;&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;/p&gt;

&lt;p&gt;%er, %or, %ar means titles ending with those suffixes the LIMIT 5 restricts output.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>select queries</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Thu, 26 Mar 2026 15:20:27 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/select-queries-part-1-1mo7</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/select-queries-part-1-1mo7</guid>
      <description>&lt;p&gt;let's see about different queries and how it works&lt;br&gt;
&lt;strong&gt;1. Retrieve Film Titles and Rental Rates&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title "Movie Title", rental_rate "Rate" FROM film;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;br&gt;
here I ma doing title is renamed as "Movie Name" and rental_rate is renamed as rate&lt;br&gt;
here why I use string----&amp;gt; when you give space without using string it does not exists.&lt;br&gt;
here without AS or with As no problem both is acceptable&lt;/p&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%2F3bo1gpix5mam5zvmadct.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%2F3bo1gpix5mam5zvmadct.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Retrieve Customer Names and Email&lt;/strong&gt;&lt;br&gt;
Query&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT first_name "First Name", last_name "Last Name", email FROM customer;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;br&gt;
first_name is renamed to "First Name". and last_name is renamed to "Last Name".&lt;br&gt;
email is left unchanged because it is already clear.&lt;/p&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%2Fihgpujft7s757uos0p8k.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%2Fihgpujft7s757uos0p8k.png" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Films sorted by rental rate (descending), then title&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title, rental_rate FROM film ORDER BY rental_rate DESC, title ASC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation&lt;br&gt;
DESC is for highest first and ASC is for alphabetical.&lt;br&gt;
Used for ranking + tie-breaking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Actor names sorted by last name, then first name&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT first_name, last_name FROM actor ORDER BY last_name, first_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;br&gt;
Standard way to sort names .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Unique replacement costs&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT replacement_cost FROM film;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;br&gt;
Distinct removes duplicates is useful for analysis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Film title and duration&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select title, length AS "Duration (min)" FROM film;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;br&gt;
Alias makes unit clear.&lt;br&gt;
**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Customer active status**
SELECT first_name, last_name, active AS "Is Active" FROM customer;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Explanation:&lt;br&gt;
Boolean values become user-friendly labels.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Film categories alphabetically&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT name FROM category ORDER BY name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;br&gt;
Sorting improves readability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Films sorted by length (descending)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title, length FROM film ORDER BY length DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;br&gt;
Find longest movies quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. Actor names sorted by first name (descending)&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT first_name, last_name FROM actor ORDER BY first_name DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Reverse sorting for different views.&lt;br&gt;
**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Unique ratings**
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT rating FROM film;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;explanation:&lt;br&gt;
Know all available categories (PG, R, etc.).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;12. Unique rental durations&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT rental_duration FROM film;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Understand available rental plans.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;13. First unique customer by active status&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT customer_id, active FROM customer ORDER BY customer_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Combining DISTINCT + ORDER BY helps identify unique records in order.&lt;br&gt;
**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Earliest rental date for each customer**
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT customer_id, MIN(rental_date) AS first_rental FROM rental GROUP BY customer_id ORDER BY customer_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;explanation:&lt;br&gt;
GROUP BY groups data MIN() used to finds earliest value&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;15. 10 shortest films&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title, length FROM film ORDER BY length ASC LIMIT 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
LIMIT restricts output of useful for top/bottom lists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;16. Top 5 customers&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT first_name, last_name FROM customer ORDER BY customer_id DESC LIMIT 5;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
It is used to find latest or highest records.&lt;br&gt;
**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Unique store ID**s
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT store_id FROM inventory;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;explanation: &lt;br&gt;
Identify all store locations.&lt;br&gt;
**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Unique replacement cost (sorted)**
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT replacement_cost FROM film ORDER BY replacement_cost ASC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;explanation:&lt;br&gt;
Sorting helps in analysis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;19. First rental date for each store&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT store_id, MIN(rental_date) AS first_rental FROM rental GROUP BY store_id ORDER BY store_id;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Track store activity start.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;20. Unique ratings sorted&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT DISTINCT rating FROM film ORDER BY rating;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation: &lt;br&gt;
Cleaner categorized output.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;21. Films by rating and length&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title, rating, length FROM film ORDER BY rating ASC, length DESC;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Multi-level sorting.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;22. Actor names sorted *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT first_name, last_name FROM actor ORDER BY last_name ASC, first_name DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Advanced sorting combinations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;23. Films by replacement cost and rental rate&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title, replacement_cost, rental_rate FROM film ORDER BY replacement_cost ASC, rental_rate DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Useful for pricing analysis.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;24. Customers sorted by name&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT first_name, last_name FROM customer ORDER BY last_name ASC,first_name DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Readable listing format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;25. Rentals sorted by customer and date&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT *FROM rental ORDER BY customer_id ASC, rental_date DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
See latest activity per customer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;26. Films by rental duration and title&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT title, rental_duration FROM film ORDER BY rental_duration ASC, title DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explanation:&lt;br&gt;
Helps compare short vs long rental plans.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>idempotency situation</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Wed, 25 Mar 2026 15:56:34 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/idempotency-situation-460a</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/idempotency-situation-460a</guid>
      <description>&lt;p&gt;Idempotency is executing the same operation multiple times that will result in the same final state&lt;/p&gt;

&lt;p&gt;Situation:&lt;/p&gt;

&lt;p&gt;Imagine there are 2 accounts A which has a balance of 300 and B which has a balance of 100&lt;br&gt;
If A initiates a transfer of 50 to B,&lt;/p&gt;

&lt;p&gt;first transfer:&lt;br&gt;
A sends B 100, A=300-50--&amp;gt; 250, B=100+50--&amp;gt; 200.&lt;/p&gt;

&lt;p&gt;second transfer:&lt;br&gt;
A sends B 100 again, A=200-50 --&amp;gt; 150, B=200+50--&amp;gt; 250.&lt;/p&gt;

&lt;p&gt;From the situation, we can see that:&lt;/p&gt;

&lt;p&gt;The system processes each request independently.&lt;br&gt;
There is no mechanism to detect duplicates.&lt;br&gt;
The same transaction is applied multiple times.&lt;/p&gt;

&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;Incorrect account balances&lt;br&gt;
Loss of data integrity&lt;br&gt;
inconsistency&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>QUERIES</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Wed, 25 Mar 2026 15:52:25 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/queries-poj</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/queries-poj</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. Select All&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Problem: Show all columns from the CITY table.&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query displays all the data in the table.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Select By ID&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Problem: Get details of the city with ID = 1661.&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;ID&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1661&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The WHERE clause is used to filter a specific row.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Japanese Cities Name&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Problem: Get names of all cities in Japan.&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;NAME&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;COUNTRYCODE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'JPN
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;';&lt;/p&gt;

&lt;p&gt;Only the NAME column is selected here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Japanese Cities Attributes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Problem: Get all details of cities in Japan.&lt;/p&gt;

&lt;p&gt;SELECT * FROM CITY WHERE COUNTRYCODE = 'JPN';&lt;/p&gt;

&lt;p&gt;This query returns all columns for cities in Japan.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Revising the Select Query&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Problem: Get all American cities with population greater than 100000.&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;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;COUNTRYCODE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'USA'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;POPULATION&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multiple conditions are combined using AND.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Revising the Select Query 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Problem: Get names of American cities with population greater than 120000.&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;NAME&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;COUNTRYCODE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'USA'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;POPULATION&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;120000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only the NAME column is required in this case.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;7. Weather Observation Station 1&lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
Problem: Show CITY and STATE.&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;SELECT&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;STATE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;STATION&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query selects two specific columns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Weather Observation Station 4&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Problem: Find the difference between total CITY entries and unique CITY entries.&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;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;STATION&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This calculates how many duplicate city names exist.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. Weather Observation Station 9&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Problem: Get city names that do not start with vowels.&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;SELECT&lt;/span&gt; &lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;STATION&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'A%'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'E%'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'I%'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'O%'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;CITY&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'U%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DISTINCT removes duplicates, and NOT LIKE filters out cities starting with vowels.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>how DNS happening</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Wed, 25 Mar 2026 15:29:26 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/how-dns-happening-2f6l</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/how-dns-happening-2f6l</guid>
      <description>&lt;p&gt;first let see as flow:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      user----&amp;gt; DNS query initialization----&amp;gt; sub resolver [local machine]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;example:&lt;br&gt;
&lt;a href="http://www.wikipedia.org" rel="noopener noreferrer"&gt;www.wikipedia.org&lt;/a&gt;.&lt;br&gt;
here last [.] represent root &lt;br&gt;
org represents TLD [Top level domain]&lt;br&gt;
Wikipedia represents SLD [secondary level domain]&lt;br&gt;
www represents Zone file &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                root [name server]
                /         |       \
               /          |        \
              /           |         \
           .org           .com     .in
          [Name server]
           /
          /
         /
    Wikipedia [name server]
       /
      /
     /
 www ------&amp;gt; IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;zone file :&lt;br&gt;
         A -----&amp;gt; IPV4&lt;br&gt;
         AAAA----&amp;gt; IPV6&lt;br&gt;
         mx-------&amp;gt; mail &lt;/p&gt;

&lt;p&gt;When your browser needs to resolve a domain (like &lt;a href="http://www.wikipedia.org." rel="noopener noreferrer"&gt;www.wikipedia.org.&lt;/a&gt;), it doesn’t directly go to root servers first.&lt;/p&gt;

&lt;p&gt;It usually goes to a DNS resolver provided by your ISP (Internet Service Provider).&lt;/p&gt;

&lt;p&gt;Here’s the real-world flow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You Type a Website
&lt;a href="http://www.wikipedia.org" rel="noopener noreferrer"&gt;www.wikipedia.org&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Browser Checks Cache&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If not found → continue&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Request Goes to ISP DNS Resolver &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your device sends the request to:&lt;br&gt;
 Your ISP’s DNS server&lt;/p&gt;

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

&lt;p&gt;Airtel DNS&lt;br&gt;
Jio DNS&lt;/p&gt;

&lt;p&gt;This server is called a recursive resolver&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;ISP Resolver Checks Cache
If it already knows → returns IP immediately 
If not → it starts querying:&lt;/li&gt;
&lt;li&gt;ISP Contacts Root Server org[.]&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;“Where is &lt;a href="http://www.wikipedia.org.?%E2%80%9D" rel="noopener noreferrer"&gt;www.wikipedia.org.?”&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;ISP Contacts TLD Server org.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;“Where is &lt;a href="http://www.wikipedia.org.?%E2%80%9D" rel="noopener noreferrer"&gt;www.wikipedia.org.?”&lt;/a&gt;&lt;br&gt;
7.next it goes to SLD here it has the Ip address &lt;br&gt;
 where is &lt;a href="http://www.wikipedia.org" rel="noopener noreferrer"&gt;www.wikipedia.org&lt;/a&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;zone file is www
it has IPV4 :A
IPV6:AAAA
MX: MAIL&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>networking</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>how a request originates from client and reaches server</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Wed, 25 Mar 2026 15:19:10 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/how-a-request-originates-from-client-and-reaches-server-1aka</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/how-a-request-originates-from-client-and-reaches-server-1aka</guid>
      <description>&lt;p&gt;&lt;strong&gt;How a Request Travels from Client to Server&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Every time you open a website, send a message, or watch a video online, something fascinating happens behind the scenes. A simple action—like typing a URL—sets off a chain reaction across the internet.&lt;/p&gt;

&lt;p&gt;But how exactly does your request travel from your device (the client) to a server somewhere in the world?&lt;/p&gt;

&lt;p&gt;Step 1: You Make a Request&lt;/p&gt;

&lt;p&gt;It all starts with you.&lt;/p&gt;

&lt;p&gt;You open your browser and type something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;www.wikipedia.org.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this moment, your device (phone, laptop, etc.) becomes the &lt;strong&gt;client&lt;/strong&gt;, and it’s asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey, can I see this website?”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Step 2: The Browser Checks Cache&lt;/p&gt;

&lt;p&gt;Before going out to the internet, your browser does a quick check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“Do I already have this data saved?”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If yes, it loads instantly.&lt;br&gt;
If not, it proceeds to the next step.&lt;/p&gt;

&lt;p&gt;This saves time and reduces unnecessary network traffic.&lt;/p&gt;

&lt;p&gt;Step 3: DNS — Finding the Server’s Address&lt;/p&gt;

&lt;p&gt;Humans use names like &lt;code&gt;wikipedia.org&lt;/code&gt;, but computers need numbers.&lt;/p&gt;

&lt;p&gt;So your system contacts a &lt;strong&gt;DNS (Domain Name System)&lt;/strong&gt; server to translate the domain into an IP address.&lt;/p&gt;

&lt;p&gt;Think of DNS as the internet’s phonebook.&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 plaintext"&gt;&lt;code&gt;www.wikipedoa.org → 10.1.34.81
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your device knows &lt;strong&gt;where&lt;/strong&gt; to send the request.&lt;/p&gt;

&lt;p&gt;Step 4: Building the Request&lt;/p&gt;

&lt;p&gt;Your browser now prepares a proper request using a protocol called &lt;strong&gt;HTTP (or HTTPS)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This request includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The resource you want (like a webpage)&lt;/li&gt;
&lt;li&gt;Your browser details&lt;/li&gt;
&lt;li&gt;Other metadata&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s like writing a letter with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Address&lt;/li&gt;
&lt;li&gt;Message&lt;/li&gt;
&lt;li&gt;Sender info
Step 5: Breaking Data into Packets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The request doesn’t travel as one big chunk.&lt;/p&gt;

&lt;p&gt;Instead, it is broken into &lt;strong&gt;small packets&lt;/strong&gt;. Each packet contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Part of the data&lt;/li&gt;
&lt;li&gt;Source IP (your device)&lt;/li&gt;
&lt;li&gt;Destination IP (server)&lt;/li&gt;
&lt;li&gt;Sequence info&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why?&lt;br&gt;
Because smaller pieces travel faster and more reliably.&lt;/p&gt;

&lt;p&gt;Step 6: Traveling Across the Network&lt;/p&gt;

&lt;p&gt;here  we can see the forward proxy and reverse proxy &lt;br&gt;
FORWARD PROXY :&lt;br&gt;
     where it multiple requests goes to internet.&lt;br&gt;
REVERSE PROXY:&lt;br&gt;
     where it comes from the internet.&lt;/p&gt;

&lt;p&gt;Your packets travel through:&lt;/p&gt;

&lt;p&gt;Each router acts like a traffic controller, deciding:&lt;/p&gt;

&lt;p&gt;“Where should this packet go next?”&lt;/p&gt;

&lt;p&gt;Packets don’t always take the same path—but they all eventually reach the destination.&lt;/p&gt;

&lt;p&gt;Step 7: Reaching the Server&lt;/p&gt;

&lt;p&gt;Finally, the packets arrive at the server.&lt;/p&gt;

&lt;p&gt;The server:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reassembles the packets&lt;/li&gt;
&lt;li&gt;Understands the request&lt;/li&gt;
&lt;li&gt;Processes it&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Step 8: Server Sends a Response&lt;/p&gt;

&lt;p&gt;Once processed, the server sends back a &lt;strong&gt;response&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This response is again:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Broken into packets&lt;/li&gt;
&lt;li&gt;Sent back through the internet&lt;/li&gt;
&lt;li&gt;Routed back to your device&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Step 9: Browser Renders the Page&lt;/p&gt;

&lt;p&gt;Your device receives the packets and:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reassembles them&lt;/li&gt;
&lt;li&gt;Interprets the content&lt;/li&gt;
&lt;li&gt;Displays it on your screen&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And just like that—you see the website.&lt;/p&gt;

&lt;p&gt;All of this typically happens in &lt;strong&gt;milliseconds&lt;/strong&gt;.&lt;br&gt;
A Simple Real-Life Analogy&lt;/p&gt;

&lt;p&gt;Imagine ordering food online:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You place an order (request)&lt;/li&gt;
&lt;li&gt;App finds the restaurant (DNS)&lt;/li&gt;
&lt;li&gt;Order is prepared (server processing)&lt;/li&gt;
&lt;li&gt;Delivery travels through roads (network routing)&lt;/li&gt;
&lt;li&gt;Food reaches you (response)&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>beginners</category>
      <category>computerscience</category>
      <category>networking</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Iternet works</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Mon, 23 Mar 2026 14:29:01 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/iternet-works-4g1c</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/iternet-works-4g1c</guid>
      <description>&lt;p&gt;Hi all today I am going to write a blog o** how the internet works?**&lt;/p&gt;

&lt;p&gt;&lt;a href="http://10.1.34.81:8000/" rel="noopener noreferrer"&gt;http://10.1.34.81:8000/&lt;/a&gt; here 10.1.34.81 is IP address and after the :8000/ is called port.&lt;br&gt;
_&lt;strong&gt;&lt;em&gt;.&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;.&lt;/em&gt;&lt;strong&gt;&lt;em&gt;.&lt;/em&gt;&lt;/strong&gt;_&lt;br&gt;
here one dash contains 8 bits that means 0-255 but here 0,1,255 will not appear so one dash contains 253 values.&lt;br&gt;
&lt;strong&gt;IP TYPES&lt;/strong&gt;&lt;br&gt;
1.network port&lt;br&gt;
2.host port&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;8its&lt;/em&gt;&lt;/strong&gt;_ .&lt;strong&gt;8 bits&lt;/strong&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;em&gt;8 bits&lt;/em&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;em&gt;8 bits&lt;/em&gt;_&lt;br&gt;
here network denotes how many bits can be same or blocked and the host will change the values for every machines.&lt;/p&gt;

&lt;p&gt;example:&lt;br&gt;
10.1.34.3/24 &lt;br&gt;
here 10.1.34 will same for every machine and the host value will change like 3,4, ......254 etcccc.&lt;br&gt;
we can use CIDR calculation for this method&lt;/p&gt;

&lt;p&gt;FORWARD PROXY means where it goes to the internet.&lt;br&gt;
REVERSE PROXY means where it comes from internet.&lt;/p&gt;

&lt;p&gt;APPLIACTION IP :&lt;br&gt;
user----&amp;gt; DNS query initialization----&amp;gt; sub resolver [local machine]&lt;br&gt;
 example:&lt;br&gt;
&lt;a href="http://www.wikipedia.org" rel="noopener noreferrer"&gt;www.wikipedia.org&lt;/a&gt;.&lt;br&gt;
here last [.] represent root &lt;br&gt;
org represents TLD [Top level domain]&lt;br&gt;
Wikipedia represents SLD [secondary level domain]&lt;br&gt;
www represents Zone file &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                root [name server]
                /         |       \
               /          |        \
              /           |         \
           .org           .com     .in
          [Name server]
           /
          /
         /
    Wikipedia [name server]
       /
      /
     /
 www ------&amp;gt; IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;zone file :&lt;br&gt;
         A -----&amp;gt; IPV4&lt;br&gt;
         AAAA----&amp;gt; IPV6&lt;br&gt;
         mx-------&amp;gt; mail&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;why we need protocol? *&lt;/em&gt;&lt;br&gt;
                Standardization&lt;br&gt;
                communication&lt;br&gt;
  IETF set the setting the conditions of internet&lt;/p&gt;

&lt;p&gt;HTTP -----&amp;gt; IETF&lt;/p&gt;

&lt;p&gt;GET-----&amp;gt;retrieve data&lt;br&gt;
 POST----&amp;gt; creates data&lt;br&gt;
 PUT------&amp;gt; update all fields resources&lt;br&gt;
 PATCH-----&amp;gt; update partial that means update some fields&lt;br&gt;
 DELETE----&amp;gt; remove data&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Merge two sorted list</title>
      <dc:creator>JAYA SRI J</dc:creator>
      <pubDate>Sun, 22 Mar 2026 07:22:07 +0000</pubDate>
      <link>https://dev.to/jaya_srij_c37a6ea796335c/merge-two-sorted-list-5009</link>
      <guid>https://dev.to/jaya_srij_c37a6ea796335c/merge-two-sorted-list-5009</guid>
      <description>&lt;p&gt;&lt;strong&gt;Merging Two Sorted Linked Lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1.Merging two sorted linked lists is a fundamental problem in data structures. It is commonly used in algorithms like merge sort and appears frequently in coding interviews.&lt;/p&gt;

&lt;p&gt;2.The goal is simple: given two sorted linked lists, combine them into one sorted linked list.&lt;br&gt;
**&lt;br&gt;
Understanding the Problem**&lt;/p&gt;

&lt;p&gt;Suppose we have two sorted linked lists:&lt;/p&gt;

&lt;p&gt;list1: 1 -&amp;gt; 3 -&amp;gt; 5&lt;br&gt;
list2: 2 -&amp;gt; 4 -&amp;gt; 6&lt;/p&gt;

&lt;p&gt;After merging, the result should be:&lt;br&gt;
1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 5 -&amp;gt; 6&lt;/p&gt;

&lt;p&gt;The final list must remain sorted.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Approach Used&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We use an iterative approach with a dummy node to simplify pointer handling.&lt;/p&gt;

&lt;p&gt;The idea is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Compare nodes from both lists&lt;/li&gt;
&lt;li&gt;Attach the smaller node to the result&lt;/li&gt;
&lt;li&gt;Move forward in that list&lt;/li&gt;
&lt;li&gt;Continue until one list is exhausted&lt;/li&gt;
&lt;li&gt;Attach the remaining nodes
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;Code&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Solution&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;mergeTwoLists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;dummy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ListNode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;list2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;list2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
            &lt;span class="n"&gt;tail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
        &lt;span class="n"&gt;tail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;list1&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;list2&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;dummy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;next&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step-by-Step Explanation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create Dummy Node&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dummy = tail = ListNode()&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;dummy is a placeholder node that helps simplify the logic&lt;br&gt;
tail keeps track of the last node in the merged list&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Traverse Both Lists&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;while list1 and list2:&lt;/code&gt;&lt;br&gt;
We continue looping as long as both lists have nodes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Compare Nodes&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;&lt;br&gt;
if list1.val &amp;lt;= list2.val:&lt;/code&gt;&lt;br&gt;
Compare the current values of both lists&lt;br&gt;
Choose the smaller value&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Attach Node to Result&lt;/strong&gt;&lt;br&gt;
tail.next, list1 = list1, list1.next&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;tail.next, list2 = list2, list2.next&lt;br&gt;
Attach the selected node to the merged list&lt;br&gt;
Move forward in the corresponding list&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Move Tail Pointer&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tail = tail.next&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Update the tail to the newly added node.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Attach Remaining Nodes&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;tail.next = list1 or list2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When one list becomes empty, attach the remaining part of the other list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Return Result&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;return dummy.next&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;dummy.next points to the head of the merged list&lt;br&gt;
We skip the dummy node itself&lt;br&gt;
Example Walkthrough&lt;/p&gt;

&lt;p&gt;Input:&lt;/p&gt;

&lt;p&gt;list1 = 1 -&amp;gt; 2 -&amp;gt; 4&lt;br&gt;
list2 = 1 -&amp;gt; 3 -&amp;gt; 4&lt;/p&gt;

&lt;p&gt;Steps:&lt;/p&gt;

&lt;p&gt;Compare 1 and 1, take one of them&lt;br&gt;
Continue comparing and attaching smaller elements&lt;br&gt;
Eventually merge both lists&lt;/p&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;1 -&amp;gt; 1 -&amp;gt; 2 -&amp;gt; 3 -&amp;gt; 4 -&amp;gt; 4&lt;br&gt;
Why This Approach is Used&lt;/p&gt;

&lt;p&gt;This method is efficient because:&lt;/p&gt;

&lt;p&gt;It processes each node exactly once&lt;br&gt;
It does not create new nodes, only rearranges pointers&lt;br&gt;
The dummy node simplifies edge cases like empty lists&lt;br&gt;
Time and Space Complexity&lt;/p&gt;

&lt;p&gt;Time complexity is O(n + m), where n and m are the lengths of the two lists.&lt;/p&gt;

&lt;p&gt;Space complexity is O(1) since no extra space is used apart from pointers.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>computerscience</category>
      <category>interview</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
