<?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: Anjana R.K.</title>
    <description>The latest articles on DEV Community by Anjana R.K. (@anjana_rk_fbdea7abbdf13).</description>
    <link>https://dev.to/anjana_rk_fbdea7abbdf13</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%2F3837511%2F4ad235a8-2513-4b2e-8bd0-664b3858a3e2.jpg</url>
      <title>DEV Community: Anjana R.K.</title>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anjana_rk_fbdea7abbdf13"/>
    <language>en</language>
    <item>
      <title>Idempotency Situation</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:42:34 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/idempotency-situation-409e</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/idempotency-situation-409e</guid>
      <description>&lt;p&gt;Hi!&lt;br&gt;
To Simulate a situation where the same transfer operation is executed more than once, as might happen in a real system due to network retries or duplicate requests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&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;TEXT&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;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;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="n"&gt;last_updated&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;p&gt;inserting values to the table accounts,&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="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;to observe whether the accpunt balance is affected the deduction and credit operations performed multiple times&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;100&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;100&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;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;100&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;100&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;to analyze whether the system prevents duplicate processing or allows the same transaction to be applied repeatedly&lt;br&gt;
*it does not automatically prevent duplicate processing of the same transaction.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Durability</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:35:19 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/durability-1kfl</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/durability-1kfl</guid>
      <description>&lt;p&gt;hi!&lt;br&gt;
To Perform a successful transfer between two accounts and commit the transaction,&lt;br&gt;
first creating a table accounts,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&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;TEXT&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;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;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="n"&gt;last_updated&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;p&gt;the table contains attributes id as peimary key, name,balance &amp;gt;=0,last_updated.next to insert values to the table accounts&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="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;To ensuring that the changes are reflected in the database.&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;here the amount deduction and the amount added is done successfully. &lt;br&gt;
After simulating a system restart or database crash to check whether the reconnect to the database account balance is successful.And to verify whether the committed changes persist even after the restart.&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;balance&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;&lt;strong&gt;how the system guarantees durability and consider what could happen if a failure occurs just before or just after a commit, and how the database ensures that committed data is not lost.&lt;/strong&gt;&lt;br&gt;
For this PostgreSQL uses a mechanism called Write-Ahead Logging (WAL).&lt;br&gt;
Before changes are applied to disk,the database describes the change in log file (the WAL).&lt;br&gt;
When COMMIT, the database ensures this log is stored to the disk.&lt;br&gt;
 *if a failure occurs just after-the data will be in wal because commit is executed &lt;br&gt;
 *if a failure occurs just before-the is treated as incomplete. Upon restart, the database identifies this as an uncommitted transaction and performs a Rollback.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>Consistency</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:11:35 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/consistency-596k</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/consistency-596k</guid>
      <description>&lt;p&gt;Hi!&lt;br&gt;
To explore how the database enforces rules that maintain valid data states, particularly ensuring that account balances never become negative.&lt;br&gt;
first create a table account,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&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;TEXT&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;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;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="n"&gt;last_updated&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;p&gt;the table contains atributes id as primary key,name,balance hee check for condition as if balance &amp;gt;=0,last_updated here set default value as current timestamp.&lt;br&gt;
Next,insert values to the 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;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="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;Attempt to perform operations that violate deducting more money than is available in an account or directly updating a balance to a negative value.&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;1200&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;IT WILL THROW ERROER as attempting to deduct 1200 from Alice who only has 1000.&lt;br&gt;
In PostgreSQL,the failure occurs due to Constraints because if the deduction occour with balance less than the debit amount while checking the constraints the balance &amp;gt;=0 fails.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Atomicity - Design a Reliable Wallet Transfer System with ACID Guarantees</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Sun, 29 Mar 2026 16:46:33 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/atomicity-design-a-reliable-wallet-transfer-system-with-acid-guarantees-4fm7</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/atomicity-design-a-reliable-wallet-transfer-system-with-acid-guarantees-4fm7</guid>
      <description>&lt;p&gt;hi!&lt;br&gt;
to Design a transaction that transfers money from one account to another using the accounts 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;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;SERIAL&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;TEXT&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;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;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="n"&gt;last_updated&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;p&gt;create a table with attributes id,name,balance to check balance in account,and last_update .then insert values to the table using insert.&lt;br&gt;
INSERT INTO accounts (name, balance) VALUES ('Alice', 1000),('Bob', 500);&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;the balance from sender in deducted using update and again using update the balance of reciever is added then the transaction is commited to get the updated result.&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;100&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;balances&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;100&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;ROLLBACK&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here to show &lt;strong&gt;Failed Transaction: Breaking the Credit Operation&lt;/strong&gt;&lt;br&gt;
first the query 1:updating the account by debiting succeeds&lt;br&gt;
the next query 2:updating the accounts by crediting but here the column name is wrong ,so it fails.Due to the failure of query 2 it roolback.&lt;br&gt;
&lt;strong&gt;Creating Failed Transaction for Constraint Violation&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;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;ROLLBACK&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here the debited amount is more than the available balance so,this will trigger the check constraint violation immediatelyand the system will not allow the next step.&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Alter Tables</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Sun, 29 Mar 2026 16:20:16 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/alter-tables-3ag5</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/alter-tables-3ag5</guid>
      <description>&lt;p&gt;Hi!&lt;br&gt;
&lt;strong&gt;1. You have a table customers with a column email that currently allows NULL values. Modify the table so that future entries must always have an email.&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;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;here the alter is used to set the column email that should not be blank.&lt;br&gt;
&lt;strong&gt;2. In the users table, ensure that the username column is unique across all records using an ALTER statement.&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;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;here an new contraint unique_name is used to keep unique user name thus ensure that the username column is unique across all records.&lt;br&gt;
&lt;strong&gt;3. In the products table, enforce that price must always be greater than 0 using an ALTER command.&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;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;price&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here the table prducts is altered with price that has values greater than 0.&lt;br&gt;
&lt;strong&gt;4. Modify the orders table so that the status column defaults to 'pending' if no value is provided during insertion.&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;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;the oders table is modified by setting the default value of status with pending.&lt;br&gt;
&lt;strong&gt;5. Alter the employees table by adding a new column salary such that,It cannot be NULL,It must always be greater than 10,000&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;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="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;the column salary is added and it should not be null and check condition that salary &amp;gt;10000.&lt;br&gt;
&lt;strong&gt;6. Modify the foreign key constraint between employees and departments so that when a department is deleted, all related employees are automatically removed.&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;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;employees_department_id&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;the on delete cascade is used so that when a department is deleted,all related employees are automatically removed .&lt;br&gt;
&lt;strong&gt;7. In the accounts table, remove an existing CHECK constraint that enforces balance &amp;gt;= 0&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;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&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;8. In the payments table, ensure that the combination of user_id and transaction_id is unique using an ALTER TABLE statement.&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;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_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;creates a Unique Constraint on table payments.It ensures that the exact same user_id and transaction_id combination can never be recorded twice, effectively preventing duplicate payment entries for the same transaction.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Alter Tables</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Sun, 29 Mar 2026 16:11:49 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/alter-tables-5hj9</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/alter-tables-5hj9</guid>
      <description>&lt;p&gt;Hi!&lt;br&gt;
&lt;strong&gt;1. You have a table customers with a column email that currently allows NULL values. Modify the table so that future entries must always have an email.&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;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;here the alter is used to set the column email that should not be blank.&lt;br&gt;
&lt;strong&gt;2. In the users table, ensure that the username column is unique across all records using an ALTER statement.&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;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;here an new contraint unique_name is used to keep unique user name thus ensure that the username column is unique across all records.&lt;br&gt;
&lt;strong&gt;3. In the products table, enforce that price must always be greater than 0 using an ALTER command.&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;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;price&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here the table prducts is altered with price that has values greater than 0.&lt;br&gt;
&lt;strong&gt;4. Modify the orders table so that the status column defaults to 'pending' if no value is provided during insertion.&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;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;the oders table is modified by setting the default value of status with pending.&lt;br&gt;
&lt;strong&gt;5. Alter the employees table by adding a new column salary such that,It cannot be NULL,It must always be greater than 10,000&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;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="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;the column salary is added and it should not be null and check condition that salary &amp;gt;10000.&lt;br&gt;
&lt;strong&gt;6. Modify the foreign key constraint between employees and departments so that when a department is deleted, all related employees are automatically removed.&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;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt; &lt;span class="k"&gt;ADD&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;employees_department_id&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;the on delete cascade is used so that when a department is deleted,all related employees are automatically removed .&lt;br&gt;
&lt;strong&gt;7. In the accounts table, remove an existing CHECK constraint that enforces balance &amp;gt;= 0&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;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&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;8. In the payments table, ensure that the combination of user_id and transaction_id is unique using an ALTER TABLE statement.&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;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_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;creates a Unique Constraint on table payments.It ensures that the exact same user_id and transaction_id combination can never be recorded twice, effectively preventing duplicate payment entries for the same transaction.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create Tables</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Sun, 29 Mar 2026 15:24:28 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/create-tables-46ib</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/create-tables-46ib</guid>
      <description>&lt;p&gt;Hi!&lt;br&gt;
&lt;strong&gt;1. Create a table called students where each student has an id, name, and age. Ensure that the id uniquely identifies each student.&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;Create&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;student&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;SERIAL&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;50&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;p&gt;i created a table student wher the id value should be unique ,let it be primary key,then name is give varchar datatype,for age the data type is int.&lt;br&gt;
*&lt;em&gt;2. Create a table employees where name and email cannot be empty, but phone_number can be optional.&lt;br&gt;
*&lt;/em&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;create&lt;/span&gt; &lt;span class="k"&gt;table&lt;/span&gt; &lt;span class="n"&gt;employee&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e_id&lt;/span&gt; &lt;span class="nb"&gt;serial&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;50&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="n"&gt;va&lt;/span&gt;
&lt;span class="n"&gt;rchar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;101&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;int&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here a table employee is created with fields employee id,name ,email,phone number where e_id is primary key ,name and email are not null&lt;br&gt;
&lt;strong&gt;3. Create a table users where both username and email must be unique across all records&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;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;u_id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&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="n"&gt;var&lt;/span&gt;
&lt;span class="nb"&gt;char&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here a table users is created where user id is u_id which is the primary key in the table,while username and email are unique.&lt;br&gt;
*&lt;em&gt;4. Create a table products where price must always be greater than 0 and stock cannot be negative.&lt;br&gt;
*&lt;/em&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;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;p_id&lt;/span&gt; &lt;span class="nb"&gt;serial&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;price&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;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;product_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;101&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in the above code the table product haave primary key p_id,product name, price which should be greater than 0 and stock must not be negative&lt;br&gt;
&lt;strong&gt;5. 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;/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;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;o_id&lt;/span&gt; &lt;span class="nb"&gt;serial&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;order_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;101&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="n"&gt;varc&lt;/span&gt;
&lt;span class="n"&gt;har&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;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="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here the table order has a order id as primary key, order_name,status is set default as pending,and created_at use timestamp datatype.&lt;br&gt;
&lt;strong&gt;6.Create a table accounts where account_number must be unique and not null&lt;br&gt;
balance must always be greater than or equal to 0&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;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;accounts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;account_id&lt;/span&gt; &lt;span class="nb"&gt;SERIAL&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;15&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;default&lt;/span&gt; &lt;span class="mi"&gt;0&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
create table accounts account_number is unique to prevent duplicates, and uses a CHECK balance is not negative.&lt;br&gt;
*&lt;em&gt;7. 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;br&gt;
*&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;CREATE TABLE enrollments (e_id SERIAL PRIMARY KEY,s_id INT,c_id INT,UNIQUE (student_id, course_id));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
sql&lt;br&gt;
create table enrollments unique values student_id and course_id. This prevents a student from being registered for the same course more than once while still allowing them to take many different courses.&lt;br&gt;
&lt;strong&gt;8.Create two tables:departments with id and name employees with id, name, and department_id Ensure that department_id in employees must exist in departments.&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;CREATE TABLE departments (id SERIAL PRIMARY KEY,name VARCHAR(100) NOT NULL
);
CREATE TABLE employees (id SERIAL PRIMARY KEY,name VARCHAR(100) NOT NULL,department_id INT REFERENCES departments(id));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
sql&lt;br&gt;
the departments table contain id,name and the employee table contain id,name,department_it which exist in departments table foreign key.&lt;br&gt;
&lt;strong&gt;9.Modify the previous foreign key example so that:When a department is deleted, all related employees are also deleted,When a department ID is updated, it reflects in the employees table&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;CREATE TABLE departments (id SERIAL PRIMARY KEY,name VARCHAR(100));
CREATE TABLE employees (id SERIAL PRIMARY KEY,name VARCHAR(100),department_id INT REFERENCES departments(id) ON DELETE CASCADE ON UPDATE CASCADE);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the table departments contain id,name.where teh table employees contain id,name,department_id as reference from table departments which delete all related employees when deleted ,When a department ID is updated, it reflects in the employees table.&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Users, Roles, Groups</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Wed, 25 Mar 2026 19:32:20 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/users-roles-groups-l84</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/users-roles-groups-l84</guid>
      <description>&lt;p&gt;Hi everyone!&lt;br&gt;
&lt;strong&gt;Task 1: Create a login role report_user that can only read from the film table.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CREATE ROLE report_user LOGIN PASSWORD 'password';&lt;br&gt;
GRANT SELECT ON film TO report_user;&lt;/p&gt;

&lt;p&gt;here a role named report_user is created with login password.Then SELECT permission is granted only on the film table. This means the user can read data from film but cannot modify it or access other tables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 2: Now try to access customer table. When report_user tries to query customer and gets permission denied. Fix it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GRANT SELECT ON customer TO report_user;&lt;/p&gt;

&lt;p&gt;The error occurs because report_user does not have permission on the customer table. Granting SELECT allows the user to read data from that table and resolve the permission denied issue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 3: Allow report_user to see only customer_id, first_name, last_name of the customer table.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;REVOKE SELECT ON customer FROM report_user;&lt;br&gt;
GRANT SELECT (customer_id, first_name, last_name) ON customer TO report_user;&lt;/p&gt;

&lt;p&gt;First, full SELECT access is removed to avoid unrestricted viewing. Then column-level permissions are granted so the user can only see specific columns such as customer_id, first_name, last_name .&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 4: Create support_user who can SELECT from customer, UPDATE only email column, Cannot DELETE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CREATE ROLE support_user LOGIN PASSWORD 'password';&lt;br&gt;
GRANT SELECT ON customer TO support_user;&lt;br&gt;
GRANT UPDATE (email) ON customer TO support_user;&lt;br&gt;
REVOKE DELETE ON customer FROM support_user;&lt;/p&gt;

&lt;p&gt;The support_user role is created with login access. It is allowed to read all customer data using SELECT. It can only update the email column due to column-level UPDATE permission. DELETE permission is explicitly revoked to ensure the user cannot remove records.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 5: Remove SELECT access on film from report_user.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;REVOKE SELECT ON film FROM report_user;&lt;/p&gt;

&lt;p&gt;here the select removes the previously granted read access on the film table, so report_user can no longer query it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 6: Create readonly_group that has SELECT on all tables.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CREATE ROLE readonly_group;&lt;br&gt;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_group;&lt;br&gt;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly_group;&lt;/p&gt;

&lt;p&gt;A group role readonly_group is created. It is granted SELECT access on all existing tables in the public schema .The ALTER DEFAULT PRIVILEGES ensures that any future tables created in the schema will also automatically grant SELECT access to this group.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task 7: Create analyst1 and analyst2 and add them to readonly_group.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CREATE ROLE analyst1 LOGIN PASSWORD 'password';&lt;br&gt;
CREATE ROLE analyst2 LOGIN PASSWORD 'password';&lt;br&gt;
GRANT readonly_group TO analyst1;&lt;br&gt;
GRANT readonly_group TO analyst2;&lt;/p&gt;

&lt;p&gt;Two new login roles (analyst1 and analyst2) are created. They are added to readonly_group, which means they inherit all its permissions, including read-only access to all tables. This avoids granting permissions individually and simplifies management.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>sql</category>
      <category>database</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>DB-TASK-Filtering Data</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Wed, 25 Mar 2026 18:47:06 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/db-task-filtering-data-1ob8</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/db-task-filtering-data-1ob8</guid>
      <description>&lt;p&gt;Hi everyone!&lt;br&gt;
&lt;strong&gt;Find all movies where the special features are not listed (i.e.,special_features is NULL).&lt;/strong&gt;&lt;br&gt;
This query selects all movies where special_features column has no value (NULL).&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE special_features IS NULL;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies where the rental duration is more than 7 days.&lt;/strong&gt;&lt;br&gt;
selects movies whose rental duration is greater than 7 days.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE rental_duration &amp;gt; 7;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies that have a rental rate of $4.99 and a replacement cost of more than $20.&lt;/strong&gt;&lt;br&gt;
this query selects movies that satisfy both rental_rate = 4.99 and replacement_cost greater than 20.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE rental_rate = 4.99 AND replacement_cost &amp;gt; 20;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies that have a rental rate of $0.99 or a rating of 'PG-13'.&lt;/strong&gt;&lt;br&gt;
this query selects movies that satisfy either rental_rate = 0.99 or rating = 'PG-13'.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE rental_rate = 0.99 OR rating = 'PG-13';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve the first 5 rows of movies sorted alphabetically by title.&lt;/strong&gt;&lt;br&gt;
this query selects first 5 movies sorted in alphabetical order using title.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film ORDER BY title ASC LIMIT 5;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Skip the first 10 rows and fetch the next 3 movies with the highest replacement cost.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT * FROM film ORDER BY replacement_cost DESC LIMIT 3 OFFSET 10;&lt;/p&gt;

&lt;p&gt;this query sorts movies by replacement_cost in descending order, skips first 10 rows and selects next 3.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies where the rating is either 'G', 'PG', or 'PG-13'.&lt;br&gt;
this query selects movies whose rating is in the given list.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE rating IN ('G','PG','PG-13');&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies with a rental rate between $2 and $4.&lt;/strong&gt;&lt;br&gt;
this query selects movies whose rental rate is between 2 and 4.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE rental_rate BETWEEN 2 AND 4;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies with titles that start with 'The'.&lt;/strong&gt;&lt;br&gt;
this query selects movies whose title starts with "The".&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE title LIKE 'The%';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find the first 10 movies with a rental rate of $2.99 or $4.99, a rating of 'R', and a title containing the word "Love".&lt;/strong&gt;&lt;br&gt;
here it selects from movies that satisfies all conditions and limits result to 10.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE rental_rate IN (2.99,4.99) AND rating = 'R' AND title LIKE '%Love%' LIMIT 10;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies where the title contains the % symbol.&lt;/strong&gt;&lt;br&gt;
this query selects movies where title contains % symbol using escape.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE title LIKE '%\%%' ESCAPE '\';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies where the title contains an underscore (_).&lt;/strong&gt;&lt;br&gt;
SELECTS movies where title contains underscore character .&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE title LIKE '%_%' ESCAPE '\';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies where the title starts with "A" or "B" and ends with "s".&lt;/strong&gt;&lt;br&gt;
The query selects movies that start with Aor B and end with s.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE (title LIKE 'A%' OR title LIKE 'B%') AND title LIKE '%s';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies where the title contains "Man","Men", or"Woman".&lt;/strong&gt;&lt;br&gt;
This query selects movies whose title contains given words.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE title LIKE '%Man%' OR title LIKE '%Men%' OR title LIKE '%Woman%';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies with titles that contain digits (e.g.,"007", "2", "300").&lt;/strong&gt;&lt;br&gt;
this query selects movies whose title contains numbers.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE title REGEXP '[0-9]';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies with titles containing a backslash().&lt;/strong&gt;&lt;br&gt;
this query selects movies whose title contains backslash symbol.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE title LIKE '%\%';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all movies where the title does contain the words "Love" or "Hate".&lt;/strong&gt;&lt;br&gt;
this selects movies containing either Love or Hate in title.&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE title LIKE '%Love%' OR title LIKE '%Hate%';&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find the first 5 movies with titles that end with "er", "or",or "ar".&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT * FROM film WHERE title LIKE '%er' OR title LIKE '%or' OR title LIKE '%ar' LIMIT 5;&lt;/p&gt;

&lt;p&gt;here it selects movies ending with given patterns and limits to 5.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>DB-TASK using dvdrental database</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Wed, 25 Mar 2026 18:31:31 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/db-task-using-dvdrental-database-11j0</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/db-task-using-dvdrental-database-11j0</guid>
      <description>&lt;p&gt;Hi everyoune!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve film titles and their rental rates. Use column aliases to rename title as "Movie Title" and rental_rate as "Rate".&lt;/strong&gt;&lt;br&gt;
this query selects title and rental_rate from table film and renames the columns as Movie_Title and Rate.&lt;/p&gt;

&lt;p&gt;SELECT title AS "Movie Title", rental_rate AS "Rate" FROM film;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List customer names and their email addresses. Alias first_name and last_name as "First Name" and "Last Name".&lt;/strong&gt;&lt;br&gt;
This query selects first name, last name, and emailfrom customer table and then renamed first_name as First Name and last_name as Last Name.&lt;/p&gt;

&lt;p&gt;SELECT first_name AS "First Name", last_name AS "Last Name", email FROM customer;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get a list of films sorted by rental rate in descending order. If two films have the same rental rate, sort them alphabetically by title.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT title, rental_rate FROM film ORDER BY rental_rate DESC, title ASC;&lt;/p&gt;

&lt;p&gt;here we select films sorted by highest rental rate first, and if same rate, sorted alphabetically by title.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve actor names sorted by last name, then first name.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT first_name, last_name FROM actor ORDER BY last_name, first_name;&lt;/p&gt;

&lt;p&gt;select actors arranged based on last name first, then first name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List all unique replacement costs from the film table.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT DISTINCT replacement_cost FROM film;&lt;/p&gt;

&lt;p&gt;the query selects only unique replacement cost values without duplicates using distinct.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List all films' title and length in minutes. Alias length as "Duration (min)".&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT title, length as "Duration" FROM film;&lt;/p&gt;

&lt;p&gt;selects title and length from table film and  rename length as Duration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve customer first and last names along with their active status. Alias active as "Is Active".&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT first_name, last_name, active AS "Is_Active" FROM customer;&lt;/p&gt;

&lt;p&gt;selects customer first_name,last_name and check whether they are active or not based on column active.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve the list of film categories sorted alphabetically.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT name FROM category ORDER BY name;&lt;/p&gt;

&lt;p&gt;selects all categories sorted in alphabetical order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List films by length, sorted in descending order. Include only the title and length&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT title, length FROM film ORDER BY length DESC;&lt;/p&gt;

&lt;p&gt;selects title and length from table film and order based on length in descending.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve all actor names, sorted by their first name in descending order.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT first_name, last_name FROM actor ORDER BY first_name DESC;&lt;/p&gt;

&lt;p&gt;here the table Actors is sorted in reverse alphabetical order of first name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List all unique ratings available in the film table&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT DISTINCT rating FROM film;&lt;/p&gt;

&lt;p&gt;Select all distinct ratings fron the table film.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all unique rental durations from the film table.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT DISTINCT rental_duration FROM film;&lt;/p&gt;

&lt;p&gt;the query selects unique rental durations from the film table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve the first unique customer ID based on active status. Include the customer_id and active columns, and order by customer_id.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT customer_id, active FROM customer ORDER BY customer_id;&lt;/p&gt;

&lt;p&gt;selects customer_id and active from table customer and sorted by id.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List the earliest rental date for each customer. Include customer_id and rental_date, and order by customer_id.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT customer_id, MIN(rental_date) FROM rental GROUP BY customer_id ORDER BY customer_id;&lt;/p&gt;

&lt;p&gt;selects the earliest rental date for each customer by taking average on each customer_id.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List the 10 shortest films by length. Include the title and length.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT title, length FROM film ORDER BY length ASC LIMIT 10;&lt;/p&gt;

&lt;p&gt;select first 10 films with smallest duration using limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get the top 5 customers with the highest customer_id. Include the first and last name.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT first_name, last_name FROM customer ORDER BY customer_id DESC LIMIT 5;&lt;/p&gt;

&lt;p&gt;select last 5 customers with highest customer_id by ordering in descending and apply limit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve all unique values of store_id from the inventory table.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT DISTINCT store_id FROM inventory;&lt;/p&gt;

&lt;p&gt;select all unique values of store_id from the inventory table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Find all unique replacement_cost values in the film table. Sort the results in ascending order.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT DISTINCT replacement_cost FROM film ORDER BY replacement_cost;&lt;/p&gt;

&lt;p&gt;select all unique replacement_cost values in the film table sort in ascending order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List the first rental date for each store. Include store_id and rental_date, and sort by store_id.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT store_id, MIN(rental_date) FROM rental GROUP BY store_id ORDER BY store_id;&lt;/p&gt;

&lt;p&gt;selects store_id,rental_date as the first rental date for each store and sort based on store_id.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve a list of film ratings sorted alphabetically and include only unique values.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT DISTINCT rating FROM film ORDER BY rating;&lt;/p&gt;

&lt;p&gt;select all unique ratings from film table in alphabetical order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List films by rating in ascending order and length in descending order.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT title,rating,length FROM film ORDER BY rating ASC,length DESC;&lt;/p&gt;

&lt;p&gt;here the query order the film by rating in ascending order and length in descending.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve actor names sorted by last_name in ascending order and first_name in descending order.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT first_name, last_name FROM actor ORDER BY last_name ASC, first_name DESC;&lt;/p&gt;

&lt;p&gt;select first_name and last_name from table actor and Sort last_name by ascending, and reverse order of first_name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List films ordered by replacement_cost in ascending order and rental_rate in descending order.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT title, replacement_cost, rental_rate FROM film ORDER BY replacement_cost ASC, rental_rate DESC;&lt;/p&gt;

&lt;p&gt;select columns from table film ordered by replacement_cost in ascending order and rental_rate in descending order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve customer names sorted by last_name ascending and first_name descending.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT first_name,last_name FROM customer ORDER BY last_name ASC, first_name DESC ;&lt;/p&gt;

&lt;p&gt;select columns from table Customers sorted by last_name ascending and reverse_first name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;List all rentals sorted by customer_id ascending and rental_date descending.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT * FROM rental ORDER BY customer_id ASC, rental_date DESC;&lt;/p&gt;

&lt;p&gt;select columns from table rental sorted by customer_id ascending and rental_date descending.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Retrieve a list of films ordered by rental_duration ascending and title descending.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;SELECT title, rental_duration FROM film ORDER BY rental_duration ASC, title DESC;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>Basic Select SQL Queries</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Wed, 25 Mar 2026 17:29:09 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/basic-select-sql-queries-pck</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/basic-select-sql-queries-pck</guid>
      <description>&lt;p&gt;1.&lt;strong&gt;Query all columns for a city in CITY with the ID 1661&lt;/strong&gt;&lt;br&gt;
 here we need to select all columns in city where ID value is equal to 1661.&lt;br&gt;
so&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;2.&lt;strong&gt;Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA.&lt;/strong&gt;&lt;br&gt;
 we to select all columns from cities where countrycode is USA and population greater than 100000.so,&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;3.&lt;strong&gt;Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is JPN.&lt;/strong&gt;&lt;br&gt;
 select all columns from city where countrycode is JPN.&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;'JPN'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.&lt;strong&gt;Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.&lt;/strong&gt;&lt;br&gt;
select the difference between the cities and distinct cities based on names from 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="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;5.&lt;strong&gt;Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The query selects the NAME from the CITY table for all cities where the COUNTRYCODE is USA and the population is 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;6.&lt;strong&gt;Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.&lt;/strong&gt;&lt;br&gt;
The query selects the NAME field from the CITY table for all cities where the COUNTRYCODE is 'JPN'.&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;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7.&lt;strong&gt;Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates.&lt;/strong&gt;&lt;br&gt;
The query selects the distinct CITY names from the STATION table where the city names do not start with any vowels (A, E, I, O, U).&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;8.&lt;strong&gt;Query all columns (attributes) for every row in the CITY table.&lt;/strong&gt;&lt;br&gt;
The query selects all columns from the CITY table for every row.&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;9.Query a list of CITY and STATE from the STATION table.&lt;br&gt;
this query is to select city and state columns form the station 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="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;



</description>
    </item>
    <item>
      <title>Setup a DNS hosted zone in Route53 in AWS.</title>
      <dc:creator>Anjana R.K.</dc:creator>
      <pubDate>Wed, 25 Mar 2026 16:08:08 +0000</pubDate>
      <link>https://dev.to/anjana_rk_fbdea7abbdf13/setup-a-dns-hosted-zone-in-route53-in-aws-3109</link>
      <guid>https://dev.to/anjana_rk_fbdea7abbdf13/setup-a-dns-hosted-zone-in-route53-in-aws-3109</guid>
      <description>&lt;p&gt;Hi everyone!&lt;br&gt;
Here lets understand how to Setup a DNS hosted zone in Route53 in AWS.&lt;/p&gt;

&lt;p&gt;To setup a DNS hosted zone,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the aws console,search for Rout53.&lt;/li&gt;
&lt;li&gt;Then in route53, click &lt;code&gt;hosted zone&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;After that click Create Hosted Zone and entered the domain name.&lt;/li&gt;
&lt;li&gt;Then for type selected Public Hosted Zone.&lt;/li&gt;
&lt;li&gt;After that click &lt;code&gt;create hosted zone&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If you already bought a domain,follow the steps, Copy the NS values given by AWS.&lt;/li&gt;
&lt;li&gt;Go back to my domain provider account and updated the nameservers with the AWS nameservers&lt;/li&gt;
&lt;li&gt;Next to create record in AWS Rout53,click &lt;code&gt;Create Record&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Enter the record name as www,then selected record type as A.&lt;/li&gt;
&lt;li&gt;Give value as the public IP address of EC2 instance. &lt;/li&gt;
&lt;li&gt;Then click &lt;code&gt;Create Record&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Finally, I opened the browser and typed the domain name, and the website was displayed.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>networking</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
