<?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: Shreya Princy</title>
    <description>The latest articles on DEV Community by Shreya Princy (@shreya_princy_8194cc37e3f).</description>
    <link>https://dev.to/shreya_princy_8194cc37e3f</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%2F3844123%2Fe1df794d-2c76-40f9-b720-ee6ae2f051e3.png</url>
      <title>DEV Community: Shreya Princy</title>
      <link>https://dev.to/shreya_princy_8194cc37e3f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shreya_princy_8194cc37e3f"/>
    <language>en</language>
    <item>
      <title>Alter Tables</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:45:40 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/alter-tables-4d1m</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/alter-tables-4d1m</guid>
      <description>&lt;h1&gt;
  
  
  Modifying TabModifying Tables Using ALTER in PostgreSQL
&lt;/h1&gt;

&lt;p&gt;In real-world database systems, requirements often change after tables are created. Instead of recreating tables, we use the ALTER TABLE command to update structure, constraints, and relationships. Below are practical examples demonstrating how to modify existing tables effectively.&lt;/p&gt;

&lt;p&gt;Making Email Mandatory in Customers Table&lt;/p&gt;

&lt;p&gt;Initially, the email column may allow NULL values. To enforce that every new record must include an email:&lt;/p&gt;

&lt;p&gt;ALTER TABLE customers&lt;br&gt;
ALTER COLUMN email SET NOT NULL;&lt;br&gt;
Enforcing Unique Usernames&lt;/p&gt;

&lt;p&gt;To ensure that no two users share the same username, we add a unique constraint:&lt;/p&gt;

&lt;p&gt;ALTER TABLE users&lt;br&gt;
ADD CONSTRAINT unique_username UNIQUE (username);&lt;br&gt;
Adding Price Validation in Products Table&lt;/p&gt;

&lt;p&gt;We enforce that product prices must always be greater than zero:&lt;/p&gt;

&lt;p&gt;ALTER TABLE products&lt;br&gt;
ADD CONSTRAINT check_price_positive CHECK (price &amp;gt; 0);&lt;br&gt;
Setting Default Status in Orders Table&lt;/p&gt;

&lt;p&gt;To automatically assign a default value of 'pending' when no status is provided:&lt;/p&gt;

&lt;p&gt;ALTER TABLE orders&lt;br&gt;
ALTER COLUMN status SET DEFAULT 'pending';&lt;br&gt;
Adding Salary Column with Constraints&lt;/p&gt;

&lt;p&gt;We extend the employees table by adding a salary column with strict rules:&lt;/p&gt;

&lt;p&gt;ALTER TABLE employees&lt;br&gt;
ADD COLUMN salary INT NOT NULL CHECK (salary &amp;gt; 10000);&lt;br&gt;
Updating Foreign Key with Cascade Delete&lt;/p&gt;

&lt;p&gt;To ensure that deleting a department also removes all related employees, we modify the foreign key constraint:&lt;/p&gt;

&lt;p&gt;ALTER TABLE employees&lt;br&gt;
DROP CONSTRAINT employees_department_id_fkey;&lt;/p&gt;

&lt;p&gt;ALTER TABLE employees ADD CONSTRAINT employees_department_id_fkey FOREIGN KEY (department_id) REFERENCES departments(id) ON DELETE CASCADE;&lt;/p&gt;

&lt;p&gt;Removing a CHECK Constraint from Accounts Table&lt;br&gt;
If there is an existing constraint enforcing balance &amp;gt;= 0, it can be removed as follows:&lt;/p&gt;

&lt;p&gt;ALTER TABLE accounts DROP CONSTRAINT accounts_balance_check;&lt;/p&gt;

&lt;p&gt;To prevent duplicate transactions for the same user, we enforce a composite unique constraint:&lt;/p&gt;

&lt;p&gt;ALTER TABLE payments ADD CONSTRAINT unique_user_transaction UNIQUE (user_id, transaction_id);&lt;br&gt;
ALTER TABLE paymentsADD CONSTRAINT unique_user_transaction UNIQUE (user_id, transaction_id);&lt;/p&gt;

</description>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Create Tables</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:36:10 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/create-tables-144m</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/create-tables-144m</guid>
      <description>&lt;p&gt;Students Table&lt;/p&gt;

&lt;p&gt;Every student should have a unique identifier. This is achieved using a primary key.&lt;/p&gt;

&lt;p&gt;CREATE TABLE students (id SERIAL PRIMARY KEY,name TEXT,age INT);&lt;br&gt;
Employees Table&lt;/p&gt;

&lt;p&gt;In many real-world cases, certain fields must always have values. For employees, name and email are required, while phone number can be optional.&lt;/p&gt;

&lt;p&gt;CREATE TABLE employees (id SERIAL PRIMARY KEY,name TEXT NOT NULL,emailTEXT NOT NULL,phone_number TEXT);&lt;/p&gt;

&lt;p&gt;To prevent duplicate accounts, both username and email should be unique.&lt;/p&gt;

&lt;p&gt;CREATE TABLE users (id SERIAL PRIMARY KEY,username TEXT UNIQUE,email TEXT UNIQUE);&lt;/p&gt;

&lt;p&gt;Products Table&lt;br&gt;
Constraints can also enforce logical rules. A product cannot have a negative stock or a price less than or equal to zero.&lt;/p&gt;

&lt;p&gt;CREATE TABLE products (id SERIAL PRIMARY KEY,name TEXT,price NUMERIC CHECK (price &amp;gt; 0),stock INT CHECK (stock &amp;gt;= 0));&lt;/p&gt;

&lt;p&gt;Orders Table&lt;br&gt;
Defaults make data handling easier. If no status is provided, it automatically becomes "pending". The creation time is also stored automatically.&lt;/p&gt;

&lt;p&gt;CREATE TABLE orders (id SERIAL PRIMARY KEY,status TEXTDEFAULT'pending',created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP);&lt;/p&gt;

&lt;p&gt;Accounts Table&lt;br&gt;
Here we combine multiple constraints. Account numbers must be unique and cannot be null, while balance should never go below zero.&lt;/p&gt;

&lt;p&gt;CREATE TABLE accounts (id SERIAL PRIMARY KEY,account_number TEXT UNIQUE NOT NULL,balance INT CHECK (balance &amp;gt;= 0));&lt;/p&gt;

&lt;p&gt;Enrollments Table&lt;br&gt;
A student can enroll in multiple courses, but cannot enroll in the same course more than once. This is handled using a composite unique constraint.&lt;/p&gt;

&lt;p&gt;CREATE TABLE enrollments (id SERIAL PRIMARY KEY,student_id INT,course_id INT,UNIQUE (student_id, course_id));&lt;br&gt;
Departments and Employees Relationship&lt;/p&gt;

&lt;p&gt;To connect employees with departments, we use a foreign key. This ensures that every employee belongs to a valid department.&lt;/p&gt;

&lt;p&gt;CREATE TABLE departments (id SERIAL PRIMARY KEY,name TEXT);&lt;/p&gt;

&lt;p&gt;CREATE TABLE employees (id SERIAL PRIMARY KEY,name TEXT,department_id INT,FOREIGN KEY (department_id) REFERENCES departments(id));&lt;br&gt;
Cascading Changes&lt;/p&gt;

&lt;p&gt;Sometimes, changes in one table should reflect in another. If a department is deleted, its employees should also be removed. Similarly, updates to department IDs should propagate.&lt;/p&gt;

&lt;p&gt;CREATE TABLE departments (id SERIAL PRIMARY KEY, name TEXT);&lt;/p&gt;

&lt;p&gt;CREATE TABLE employees (id SERIAL PRIMARY KEY,name TEXT,department_id,INT,FOREIGN KEY (department_id) REFERENCES departments(id)ON DELETE CASCADE ON UPDATE CASCADE);&lt;/p&gt;

&lt;p&gt;CREATE TABLE employees (id SERIAL PRIMARY KEY,name TEXT,department_idINT,FOREIGN KEY (department_id) REFERENCES departments(id) ON DELETE CASCADE ON UPDATE CASCADE);&lt;/p&gt;

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

&lt;p&gt;SQL constraints play a crucial role in maintaining data accuracy and reliability. By using primary keys, unique constraints, checks, defaults, and foreign keys, we can design robust database systems that prevent invalid data and enforce meaningful relationships between tables.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
    <item>
      <title>Idempotency Situation</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:22:13 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/idempotency-situation-4lok</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/idempotency-situation-4lok</guid>
      <description>&lt;h1&gt;
  
  
  Ensuring Reliable Money Transfers Using Database Transactions
&lt;/h1&gt;

&lt;p&gt;In a digital wallet system similar to PhonePe, Google Pay, or Paytm, users expect their money to be handled accurately and securely. Even a small inconsistency—such as deducting money from one account without crediting another—can lead to serious financial issues. To prevent such problems, database systems rely on &lt;strong&gt;ACID properties&lt;/strong&gt;, especially &lt;strong&gt;Durability&lt;/strong&gt;, to guarantee safe and consistent transactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  System Overview
&lt;/h2&gt;

&lt;p&gt;The system maintains an accounts table where each user has a balance. Users can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Store money in their wallet&lt;/li&gt;
&lt;li&gt;Transfer money to other users&lt;/li&gt;
&lt;li&gt;View their transaction history&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To ensure correctness, the database enforces rules like non-negative balances and timestamp tracking.&lt;/p&gt;

&lt;p&gt;Performing a Secure Transfer&lt;/p&gt;

&lt;p&gt;A typical money transfer between two users (for example, Alice to Bob) is executed within a transaction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The system begins a transaction&lt;/li&gt;
&lt;li&gt;Deducts money from the sender’s account&lt;/li&gt;
&lt;li&gt;Adds the same amount to the receiver’s account&lt;/li&gt;
&lt;li&gt;Commits the transaction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If all steps succeed, the transaction is permanently saved. After committing, querying the database shows the updated balances correctly.&lt;/p&gt;

&lt;p&gt;What Happens During a System Failure?&lt;/p&gt;

&lt;p&gt;Failure Before Commit&lt;/p&gt;

&lt;p&gt;If the system crashes before the transaction is committed, none of the changes are saved. The database automatically rolls back the transaction, ensuring that no partial updates occur. This prevents situations like money being deducted without being credited.&lt;/p&gt;

&lt;p&gt;Failure After Commit&lt;/p&gt;

&lt;p&gt;If the system crashes immediately after the commit, the changes remain persisted. When the database restarts, the updated balances remain intact. This behavior demonstrates &lt;strong&gt;Durability&lt;/strong&gt;, meaning once a transaction is committed, it will not be lost.&lt;/p&gt;

&lt;p&gt;How the Database Ensures Durability&lt;/p&gt;

&lt;p&gt;Modern databases like PostgreSQL use a mechanism called &lt;strong&gt;Write-Ahead Logging (WAL)&lt;/strong&gt;. Before applying any changes to the actual data, the database records them in a log file. In case of a crash, the system replays this log to restore the latest committed state. This guarantees that committed transactions survive unexpected failures.&lt;/p&gt;

&lt;p&gt;Without proper transaction handling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users could lose money&lt;/li&gt;
&lt;li&gt;Duplicate transactions might occur&lt;/li&gt;
&lt;li&gt;Account balances could become incorrect&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By enforcing ACID properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transactions are either fully completed or not applied at all&lt;/li&gt;
&lt;li&gt;Data remains consistent at all times&lt;/li&gt;
&lt;li&gt;Concurrent operations do not interfere with each other&lt;/li&gt;
&lt;li&gt;Committed data is permanently stored&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Handling Idempotency in Money Transfers&lt;/p&gt;

&lt;p&gt;In real-world payment systems, a single transaction request may be sent multiple times due to network retries, timeouts, or client-side errors. If not handled properly, this can result in duplicate money transfers, leading to incorrect balances and financial inconsistencies.&lt;/p&gt;

&lt;p&gt;Simulating Duplicate Transactions&lt;/p&gt;

&lt;p&gt;Consider a scenario where a transfer of ₹200 from Alice to Bob is executed more than once:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First execution: Alice → 800, Bob → 700&lt;/li&gt;
&lt;li&gt;Second execution (duplicate): Alice → 600, Bob → 900&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This shows that the same operation is applied repeatedly, causing unintended deductions and credits.&lt;/p&gt;

&lt;p&gt;Problem Observation&lt;/p&gt;

&lt;p&gt;The database processes each request independently. Without additional safeguards, it does not recognize whether a transaction has already been executed. As a result, duplicate requests lead to repeated updates.&lt;br&gt;
 Why This Is Dangerous&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users may be charged multiple times&lt;/li&gt;
&lt;li&gt;Account balances become inaccurate&lt;/li&gt;
&lt;li&gt;Trust in the system is reduced&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How Real Systems Prevent This&lt;/p&gt;

&lt;p&gt;To avoid duplicate processing, modern systems implement idempotency.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Unique Transaction IDs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each transaction is assigned a unique identifier. Before processing, the system checks if the ID already exists. If it does, the request is ignored.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Idempotency Keys&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Clients send a unique key with each request. The server stores this key and ensures that repeated requests with the same key produce the same result without reprocessing.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Database Constraints&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Unique constraints or indexes can be applied on transaction identifiers to prevent duplicate entries at the database level.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Transaction Logs
&lt;/h3&gt;

&lt;p&gt;Maintaining a transaction history helps verify whether a request has already been completed.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>database</category>
      <category>softwareengineering</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>Durability</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Sun, 29 Mar 2026 17:08:27 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/durability-4lnn</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/durability-4lnn</guid>
      <description>&lt;p&gt;Ensuring Reliable Money Transfers Using Database Transactions&lt;/p&gt;

&lt;p&gt;In a digital wallet system similar to PhonePe, Google Pay, or Paytm, users expect their money to be handled accurately and securely. Even a small inconsistency such as deducting money from one account without crediting another  can lead to serious financial issues. To prevent such problems, database systems rely on ACID properties , especially Durability, to guarantee safe and consistent transactions.&lt;/p&gt;

&lt;p&gt;System Overview&lt;/p&gt;

&lt;p&gt;The system maintains an accounts table where each user has a balance. Users can:&lt;/p&gt;

&lt;p&gt;Store money in their wallet&lt;br&gt;
 Transfer money to other users&lt;br&gt;
 View their transaction history&lt;/p&gt;

&lt;p&gt;Performing a Secure Transfer:&lt;br&gt;
A typical money transfer between two users (for example, Alice to Bob) is executed within a transaction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The system begins a transaction&lt;/li&gt;
&lt;li&gt;Deducts money from the sender’s account&lt;/li&gt;
&lt;li&gt;Adds the same amount to the receiver’s account&lt;/li&gt;
&lt;li&gt;Commits the transaction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If all steps succeed, the transaction is permanently saved. After committing, querying the database shows the updated balances correctly.&lt;br&gt;
What Happens During a System Failure?&lt;br&gt;
Failure Before Commit:&lt;/p&gt;

&lt;p&gt;If the system crashes before the transaction is committed, none of the changes are saved. The database automatically rolls back the transaction, ensuring that no partial updates occur. This prevents situations like money being deducted without being credited.&lt;/p&gt;

&lt;p&gt;Failure After Commit:&lt;/p&gt;

&lt;p&gt;When the database restarts, the updated balances remain intact. This behavior demonstrates Durability, meaning once a transaction is committed, it will not be lost.&lt;/p&gt;

&lt;p&gt;How the Database Ensures Durability:&lt;br&gt;
Modern databases like PostgreSQL use a mechanism called WAL. Before applying any changes to the actual data, the database records them in a log file. In case of a crash, the system replays this log to restore the latest committed state. This guarantees that committed transactions survive unexpected failures.&lt;/p&gt;

&lt;p&gt;Why This Matters:&lt;br&gt;
Without proper transaction handling:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Users could lose money&lt;/li&gt;
&lt;li&gt;Duplicate transactions might occur&lt;/li&gt;
&lt;li&gt;Account balances could become incorrect&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By enforcing ACID properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transactions are either fully completed or not applied at all&lt;/li&gt;
&lt;li&gt;Data remains consistent at all times&lt;/li&gt;
&lt;li&gt;Concurrent operations do not interfere with each other&lt;/li&gt;
&lt;li&gt;Committed data is permanently stored&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Step 1: Successful Money Transfer (Transaction)&lt;/p&gt;

&lt;p&gt;Example: Transfer 200 from Alice to  Bob&lt;/p&gt;

&lt;p&gt;UPDATE accounts SET balance = balance - 200, last_updated = CURRENT_TIMESTAMP WHERE name = 'Alice';&lt;br&gt;
UPDATE accounts SET balance = balance + 200,last_updated = CURRENT_TIMESTAMP WHERE name = 'Bob';&lt;br&gt;
COMMIT;&lt;/p&gt;

</description>
      <category>backend</category>
      <category>database</category>
      <category>sql</category>
      <category>systemdesign</category>
    </item>
    <item>
      <title>CA 33 - Users, Roles, Groups</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Sun, 29 Mar 2026 16:57:01 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/ca-33-users-roles-groups-3mj5</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/ca-33-users-roles-groups-3mj5</guid>
      <description>&lt;p&gt;Task 1: Create report_user with read access only to film:-&lt;/p&gt;

&lt;p&gt;CREATE ROLE report_user WITH LOGIN PASSWORD 'password123';&lt;br&gt;
GRANT CONNECT ON DATABASE dvdrental TO report_user;&lt;br&gt;
GRANT USAGE ON SCHEMA public TO report_user;&lt;br&gt;
GRANT SELECT ON TABLE film TO report_user;&lt;/p&gt;

&lt;p&gt;Task 2: Fix permission denied for customer table:-&lt;/p&gt;

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

&lt;p&gt;Task 3: Allow only specific columns from customer:-&lt;/p&gt;

&lt;p&gt;REVOKE SELECT ON TABLE 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;Task 4: Create support_user with restricted permissions:-&lt;/p&gt;

&lt;p&gt;CREATE ROLE support_user WITH LOGIN PASSWORD 'password123';&lt;br&gt;
GRANT CONNECT ON DATABASE dvdrental TO support_user;&lt;br&gt;
GRANT USAGE ON SCHEMA public TO support_user;&lt;br&gt;
Allow SELECT GRANT SELECT ON TABLE customer TO support_user;&lt;br&gt;
Allow UPDATE only on email column GRANT UPDATE (email) ON customer TO support_user;&lt;br&gt;
Ensure DELETE is not allowed REVOKE DELETE ON customer FROM support_user;&lt;/p&gt;

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

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

&lt;p&gt;Task 6: Create readonly_group with SELECT on all tables:-&lt;/p&gt;

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

&lt;p&gt;Task 7: Create users and add to group:-&lt;/p&gt;

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

</description>
    </item>
    <item>
      <title>CA 32 - Filter Assignments</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Sun, 29 Mar 2026 16:48:06 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/ca-32-filter-assignments-324b</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/ca-32-filter-assignments-324b</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Movies where special_features is NULL:- &lt;br&gt;
SELECT * FROM film WHERE special_features IS NULL;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Movies with rental duration &amp;gt; 7 days:-&lt;br&gt;
SELECT *FROM film WHERE rental_duration &amp;gt; 7;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rental rate = 4.99 AND replacement cost &amp;gt; 20&lt;br&gt;
SELECT *FROM film WHERE rental_rate = 4.99 AND replacement_cost &amp;gt; 20;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rental rate = 0.99 OR rating = 'PG-13':-&lt;br&gt;
SELECT * FROM film WHERE rental_rate = 0.99 OR rating = 'PG-13';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First 5 movies sorted alphabetically:-&lt;br&gt;
SELECT *FROM film ORDER BY title ASC LIMIT 5;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Skip first 10, get next 3 (highest replacement cost):-&lt;br&gt;
SELECT * FROM film ORDER BY replacement_cost DESC OFFSET 10 LIMIT 3;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rating in ('G', 'PG', 'PG-13'):-&lt;br&gt;
SELECT * FROM film WHERE rating IN ('G', 'PG', 'PG-13');&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rental rate between 2 and 4:-&lt;br&gt;
SELECT * FROM film WHERE rental_rate BETWEEN 2 AND 4;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Titles starting with "The":-&lt;br&gt;
SELECT * FROM film WHERE title LIKE 'The%';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First 10 movies with multiple conditions&lt;br&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;/li&gt;
&lt;li&gt;&lt;p&gt;Titles containing %:-&lt;br&gt;
SELECT *FROM film WHERE title LIKE '%\%%' ESCAPE '\';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Titles containing _&lt;br&gt;
SELECT * FROM film WHERE title LIKE '%_%' ESCAPE '\';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Titles start with A or B and end with s:-&lt;br&gt;
SELECT * FROM film WHERE (title LIKE 'A%s' OR title LIKE 'B%s');&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Titles containing Man, Men, or Woman:-&lt;br&gt;
SELECT * FROM film WHERE title ILIKE '%Man%' OR title ILIKE '%Men%' OR title ILIKE '%Woman%';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Titles containing digits:-&lt;br&gt;
SELECT * FROM film WHERE title ~ '[0-9]';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Titles containing backslash ():-&lt;br&gt;
SELECT * FROM film WHERE title LIKE '%\%';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Titles containing "Love" or "Hate":-&lt;br&gt;
SELECT * FROM film&lt;br&gt;
WHERE title ILIKE '%Love%'&lt;br&gt;
OR title ILIKE '%Hate%';&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First 5 movies ending with er, or, ar&lt;br&gt;
SELECT *FROM filmWHERE title LIKE '%er' OR title LIKE '%or'OR title LIKE '%ar'&lt;br&gt;
LIMIT 5;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>DB-TASK-001</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Sun, 29 Mar 2026 16:38:19 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/db-task-001-33e1</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/db-task-001-33e1</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Film titles with rental rates:-
SELECT title AS "Movie Title", rental_rate AS "Rate" FROM film;&lt;/li&gt;
&lt;li&gt;Customer names and email:-&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;Films sorted by rental rate (desc), then title:-&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;Actor names sorted by last name, then first name:-
SELECT first_name, last_name FROM actor ORDER BY last_name ASC, first_name ASC;&lt;/li&gt;
&lt;li&gt;Unique replacement costs:-
SELECT DISTINCT replacement_cost FROM film;&lt;/li&gt;
&lt;li&gt;Film title and duration:-
SELECT title, length AS "Duration (min)" FROM film;&lt;/li&gt;
&lt;li&gt;Customer active status:-
SELECT first_name, last_name, active AS "Is Active" FROM customer;&lt;/li&gt;
&lt;li&gt;Film categories sorted alphabetically:-
SELECT nameFROM category ORDER BY name ASC;&lt;/li&gt;
&lt;li&gt;Films by length (descending):-
SELECT title, length FROM film ORDER BY length DESC;&lt;/li&gt;
&lt;li&gt;Actor names sorted by first name (descending)
SELECT first_name, last_name FROM actor ORDER BY first_name DESC;&lt;/li&gt;
&lt;li&gt;Unique ratings:-
SELECT DISTINCT rating FROM film;&lt;/li&gt;
&lt;li&gt;Unique rental durations:-
SELECT DISTINCT rental_duration FROM film;&lt;/li&gt;
&lt;li&gt;First unique customer ID based on active status:-
SELECT DISTINCT customer_id, active FROM customer ORDER BY customer_id
LIMIT 1;&lt;/li&gt;
&lt;li&gt;Earliest rental date for each customer:-
SELECT customer_id, MIN(rental_date) AS rental_date FROM rental GROUP BY customer_id ORDER BY customer_id;&lt;/li&gt;
&lt;li&gt;10 shortest films
SELECT title, length FROM film ORDER BY length ASC LIMIT 10;&lt;/li&gt;
&lt;li&gt;Top 5 customers with highest customer_id:-
SELECT first_name, last_name FROM customer ORDER BY customer_id DESC
LIMIT 5;&lt;/li&gt;
&lt;li&gt;Unique store IDs from inventory:-
SELECT DISTINCT store_id FROM inventory;&lt;/li&gt;
&lt;li&gt;Unique replacement_cost sorted ascending
SELECT DISTINCT replacement_cost FROM film ORDER BY replacement_cost ASC;&lt;/li&gt;
&lt;li&gt;First rental date for each store:-
SELECT i.store_id, MIN(r.rental_date) AS rental_date FROM rental r JOIN inventory i ON r.inventory_id = i.inventory_id GROUP BY i.store_id ORDER BY i.store_id;&lt;/li&gt;
&lt;li&gt;Unique film ratings sorted alphabetically:-
SELECT DISTINCT rating FROM film ORDER BY rating ASC;&lt;/li&gt;
&lt;li&gt;Films by rating (asc) and length (desc):-
SELECT title, rating, length FROM film ORDER BY rating ASC, length DESC;&lt;/li&gt;
&lt;li&gt;Actor names sorted last asc, first desc
SELECT first_name, last_name
FROM actor
ORDER BY last_name ASC, first_name DESC;&lt;/li&gt;
&lt;li&gt;Films by replacement_cost asc and rental_rate desc
SELECT title, replacement_cost, rental_rate
FROM film
ORDER BY replacement_cost ASC, rental_rate DESC;&lt;/li&gt;
&lt;li&gt;Customers sorted last asc, first desc
SELECT first_name, last_name
FROM customer
ORDER BY last_name ASC, first_name DESC;&lt;/li&gt;
&lt;li&gt;Rentals sorted by customer_id asc, rental_date desc
SELECT *
FROM rental
ORDER BY customer_id ASC, rental_date DESC;&lt;/li&gt;
&lt;li&gt;Films ordered by rental_duration asc and title desc
SELECT title, rental_duration
FROM film
ORDER BY rental_duration ASC, title DESC;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Python Variables, Print</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Thu, 26 Mar 2026 18:34:19 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/python-variables-print-j5a</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/python-variables-print-j5a</guid>
      <description>&lt;p&gt;How do you print the string “Hello, world!” to the screen?&lt;/p&gt;

&lt;p&gt;print("Hello, world!")&lt;/p&gt;

&lt;p&gt;2.How do you print the value of a variable name which is set to “Syed Jafer” or your name?&lt;/p&gt;

&lt;p&gt;name = "Shreya"&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the variables name, age, and city with labels “Name:”, “Age:”, and “City:”?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;name = "Shreya" age = 21 city = "Chennai"&lt;br&gt;
print("Name:", name, "Age:", age, "City:", city)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you use an f-string to print name, age, and city in the format “Name: …, Age: …, City: …”?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(f"Name: {name}, Age: {age}, City: {city}")&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you concatenate and print the strings greeting (“Hello”) and target (“world”) with a space between them?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;greeting = "Hello" target = "world"&lt;br&gt;
print(greeting + " " + target)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print three lines of text with the strings “Line1”, “Line2”, and “Line3” on separate lines?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print("Line1\nLine2\nLine3")&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the string He said, "Hello, world!" including the double quotes?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print('He said, "Hello, world!"')&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the string C:\Users\Name without escaping the backslashes?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(r"C:\Users\Name")&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;How do you print the result of the expression 5 + 3?&lt;br&gt;
print(5 + 3)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you print the strings “Hello” and “world” separated by a hyphen -?&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print("Hello-world")&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the string “Hello” followed by a space, and then print “world!” on the same line?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print("Hello", end=" ")&lt;br&gt;
print("world!")&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the value of a boolean variable is_active which is set to True?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;is_active = True&lt;br&gt;
print(is_active)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the string “Hello ” three times in a row?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print("Hello " * 3)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the sentence The temperature is 22.5 degrees Celsius. using the variable temperature?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;temperature = 22.5&lt;br&gt;
print(f"The temperature is {temperature} degrees Celsius.")&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print name, age, and city using the .format() method in the format “Name: …, Age: …, City: …”?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print("Name: {}, Age: {}, City: {}".format(name, age, city))&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the value of pi (3.14159) rounded to two decimal places in the format The value of pi is approximately 3.14?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(f"The value of pi is approximately {pi:.2f}")&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How do you print the words “left” and “right” with “left” left-aligned and “right” right-aligned within a width of 10 characters each?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(f"{'left':&amp;lt;10}{'right':&amp;gt;10}")&lt;/p&gt;

&lt;h1&gt;
  
  
  TASK 2
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Create a variable named name and assign your name to it. Then print the value of the variable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;name = "Shiny"&lt;br&gt;
print(name)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a variable age and assign your age to it. Later, reassign the variable with a new value and print the new value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;age = 20&lt;br&gt;
age = 21&lt;br&gt;
print(age)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Assign the values 5, 10, and 15 to three variables a, b, and c in a single line. Print their values.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;a, b, c = 5, 10, 15&lt;br&gt;
print(a, b, c)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Swap the values of two variables x and y without using a third variable. Print their values before and after swapping.
x = 5
y = 10
print("Before:", x, y)
x, y = y, x&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print("After:", x, y)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define constants PI with appropriate values and print them.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;PI = 3.14159&lt;br&gt;
print(PI)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write a program that calculates the area of a circle using the constant PI and a variable radius. Print the area.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;PI = 3.14159&lt;br&gt;
radius = 5&lt;br&gt;
area = PI * radius * radius&lt;br&gt;
print(area)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define constants for the length and width of a rectangle. Calculate and print the area.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;LENGTH = 10&lt;br&gt;
WIDTH = 5&lt;br&gt;
area = LENGTH * WIDTH&lt;br&gt;
print(area)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define a constant for π (pi) and a variable for the radius. Calculate and print the circumference of the circle.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;radius = 5 ,circumference = 2 * PI * radius&lt;br&gt;
print(circumference)&lt;/p&gt;

&lt;h1&gt;
  
  
  TASK 3
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Create a list of five delivery items and print the third item in the list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;items = ["Notebook", "Pencil", "Eraser", "Ruler", "Marker"]&lt;br&gt;
print(items[2])&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add “Glue Stick” to the end of the list and print the updated list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;items.append("Glue Stick")&lt;br&gt;
print(items)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Insert “Highlighter” between the second and third items and print the updated list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;items.insert(2, "Highlighter")&lt;br&gt;
print(items)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remove “Ruler” from the list and print the updated list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;items.remove("Ruler")&lt;br&gt;
print(items)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Print a sublist containing only the first three items.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(items[:3])&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Convert all item names to uppercase using list comprehension and print.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;upper_items = [item.upper() for item in items]&lt;br&gt;
print(upper_items)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Check if “Marker” is in the list and print a message.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print("Marker found" if "Marker" in items else "Marker not found")&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Print the number of delivery items in the list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(len(items))&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sort the list in alphabetical order and print it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;items.sort()&lt;br&gt;
print(items)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reverse the list and print it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;items.reverse()&lt;br&gt;
print(items)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a list of items with delivery time and print first item and its time.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;delivery = [["Notebook", "10AM"], ["Pencil", "11AM"], ["Eraser", "12PM"]]&lt;br&gt;
print(delivery[0])&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Count how many times “Ruler” appears in the list and print.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(items.count("Ruler"))&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the index of “Pencil” in the list and print it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;print(items.index("Pencil"))&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Extend the list with another list and print updated list.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;new_items = ["Pen", "Sharpener"]&lt;br&gt;
items.extend(new_items)&lt;br&gt;
print(items)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clear the list and print it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;items.clear()&lt;br&gt;
print(items)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a list with “Notebook” repeated three times and print.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;repeat_list = ["Notebook"] * 3&lt;br&gt;
print(repeat_list)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a list of lists with item and its length using nested list comprehension.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;items = ["Notebook", "Pencil", "Eraser"]&lt;br&gt;
length_list = [[item, len(item)] for item in items]&lt;br&gt;
print(length_list)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Filter items containing letter “e” and print.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;filtered = [item for item in items if "e" in item.lower()]&lt;br&gt;
print(filtered)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remove duplicate items and print unique list.
items = ["Notebook", "Pencil", "Notebook", "Eraser"]
unique_items = list(set(items))
print(unique_items)
print(name)&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Consistency</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Thu, 26 Mar 2026 18:21:59 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/consistency-3921</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/consistency-3921</guid>
      <description>&lt;p&gt;A wallet system must always keep balances correct and never allow invalid states. PostgreSQL helps enforce this using constraints, but safe operations still depend on how queries are written.&lt;/p&gt;

&lt;p&gt;The balance column is protected by a rule that prevents it from going below zero. If a query tries to violate this, PostgreSQL stops it.&lt;/p&gt;

&lt;p&gt;Example of an invalid update:&lt;br&gt;
UPDATE accounts&lt;br&gt;
SET balance = -100&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;This fails because the database constraint blocks negative values.&lt;/p&gt;

&lt;p&gt;Another invalid case:&lt;br&gt;
UPDATE accounts&lt;br&gt;
SET balance = balance - 1500&lt;br&gt;
WHERE name = 'Alice';&lt;/p&gt;

&lt;p&gt;If the balance is only 1000, this also fails for the same reason. These errors are enforced by the database schema itself.&lt;/p&gt;

&lt;p&gt;However, transferring money is more complex and must be handled carefully.&lt;/p&gt;

&lt;p&gt;A correct transfer must run inside a transaction:&lt;br&gt;
UPDATE accounts&lt;br&gt;
SET balance = balance - 300&lt;br&gt;
WHERE name = 'Alice' AND balance &amp;gt;= 300;&lt;/p&gt;

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

&lt;p&gt;The condition &lt;code&gt;balance &amp;gt;= 300&lt;/code&gt; ensures that the deduction only happens if enough money is available. If not, no row is updated and the transaction can be safely stopped.&lt;/p&gt;

&lt;p&gt;To make the system safe during concurrent transactions, locking is required,there are 2 types of loocking optimistic locking and pesimistic locking.&lt;br&gt;
Optimistic locking: Assumes no conflict and checks for changes before updating, failing if data was modified.&lt;br&gt;
Pessimistic locking: Locks the data before updating to prevent any concurrent access or conflicts.&lt;/p&gt;

&lt;p&gt;SELECT balance FROM accounts&lt;br&gt;
WHERE name = 'Alice'&lt;br&gt;
FOR UPDATE;&lt;/p&gt;

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

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

&lt;p&gt;This prevents multiple operations from modifying the same account at the same time.&lt;/p&gt;

&lt;p&gt;In this system, PostgreSQL constraints prevent invalid data like negative balances, while transactions and locking ensure correct behavior during money transfers. Both are required to maintain consistency and avoid financial errors.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Basic Select SQL Queries</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Thu, 26 Mar 2026 17:47:06 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/basic-select-sql-queries-3l5d</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/basic-select-sql-queries-3l5d</guid>
      <description>&lt;p&gt;SELECT * FROM CITY WHERE ID = 1661;&lt;/p&gt;

&lt;p&gt;select * from city where countrycode='JPN';&lt;/p&gt;

&lt;p&gt;select name from city where population&amp;gt; 120000 and countrycode='USA';&lt;/p&gt;

&lt;p&gt;SELECT DISTINCT CITY FROM STATION WHERE CITY NOT LIKE 'A%' AND CITY NOT LIKE 'E%' AND CITY NOT LIKE 'I%' AND CITY NOT LIKE 'O%' AND CITY NOT LIKE 'U%';&lt;/p&gt;

&lt;p&gt;select city, state from station;&lt;/p&gt;

&lt;p&gt;SELECT * FROM CITY WHERE CountryCode = 'USA' AND Population &amp;gt; 100000;&lt;/p&gt;

&lt;p&gt;SELECT COUNT(CITY) - COUNT(DISTINCT CITY) FROM STATION;&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%2Fny5i75dqgtp54qzi0g9e.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%2Fny5i75dqgtp54qzi0g9e.png" alt=" " width="800" height="421"&gt;&lt;/a&gt;&lt;br&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%2F278bcz4j359q2bf67z4c.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%2F278bcz4j359q2bf67z4c.png" alt=" " width="800" height="421"&gt;&lt;/a&gt;&lt;a href="https://dev.tourl"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create a simple EC2 instance and run a webserver and access it from outside.</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Thu, 26 Mar 2026 17:27:20 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/create-a-simple-ec2-instance-and-run-a-webserver-and-access-it-from-outside-24gj</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/create-a-simple-ec2-instance-and-run-a-webserver-and-access-it-from-outside-24gj</guid>
      <description>&lt;p&gt;Step 1: Launch Your Virtual Server ,log into your AWS Management Console.&lt;/p&gt;

&lt;p&gt;Search for EC2 in the top search bar and click on it.&lt;/p&gt;

&lt;p&gt;Give your server a  name, like "My-First-Web-Server".&lt;/p&gt;

&lt;p&gt;Step 2:Under Application and OS Images (Amazon Machine Image), select Amazon Linux. It is optimized for AWS.&lt;/p&gt;

&lt;p&gt;Ensure the Free tier eligible tag is visible so you don't accidentally run up a bill.&lt;/p&gt;

&lt;p&gt;For the Instance type, leave it as t2.micro (or t3.micro depending on your region). &lt;/p&gt;

&lt;p&gt;Step 3: Create the Keys to the instance.&lt;br&gt;
To securely connect to your server later, you need a digital key.&lt;/p&gt;

&lt;p&gt;Under Key pair (login), click Create new key pair.&lt;/p&gt;

&lt;p&gt;Name it something like "web-server-key", leave the defaults , and hit create.&lt;/p&gt;

&lt;p&gt;Step 4: Configure the Security Groups&lt;br&gt;
By default, AWS blocks all incoming traffic to protect your server. Since we are building a web server, we need to open the doors for the internet to see it.&lt;/p&gt;

&lt;p&gt;Under Network settings, check the box that says Allow SSH traffic from . Set the dropdown to My IP for maximum security.&lt;/p&gt;

&lt;p&gt;next step: Check the box for Allow HTTP traffic from the internet. This opens Port 80, which is the universal channel for web browsers to access your site.&lt;/p&gt;

&lt;p&gt;Step 5: Launch and Connect&lt;br&gt;
Hit the orange Launch instance button on the right side of your screen.&lt;/p&gt;

&lt;p&gt;Once it says "Success", click on the instance ID to go to your instances page. Wait until the "Instance state" says Running.&lt;/p&gt;

&lt;p&gt;Select your instance, and click the Connect button at the top.&lt;/p&gt;

&lt;p&gt;navigate to the EC2 Instance Connect tab and hit Connect. A black terminal window will pop up in your browser. You are now inside your server.&lt;/p&gt;

&lt;p&gt;Step 6: Install the Web Server&lt;br&gt;
Now that we are inside the machine, we need to install the software that serves web pages . Copy and paste these commands into your terminal one by one, hitting Enter after each, Update the system, Let's make sure our software is up to date.&lt;/p&gt;

&lt;p&gt;Install Apache: This is the actual web server software.&lt;/p&gt;

&lt;p&gt;Start the server: Turn the engine on.&lt;/p&gt;

&lt;p&gt;Keep it on: Tell the server to start automatically if the machine ever reboots.&lt;/p&gt;

&lt;p&gt;Step 7:It is time to see the work.&lt;/p&gt;

&lt;p&gt;Go back to your EC2 dashboard where your instance details are.&lt;/p&gt;

&lt;p&gt;Find the Public IPv4 address  like 3.85.22.112.&lt;/p&gt;

&lt;p&gt;Copy that address, open a new tab in your web browser, paste it in, and hit enter.&lt;br&gt;
You have officially launched a server in the cloud and made it accessible to the entire world.&lt;/p&gt;

&lt;p&gt;"Terminate instance" to destroy it and stop any potential future billing.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>beginners</category>
      <category>cloud</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Atomicity - Design a Reliable Wallet Transfer System with ACID Guarantees</title>
      <dc:creator>Shreya Princy</dc:creator>
      <pubDate>Thu, 26 Mar 2026 08:54:15 +0000</pubDate>
      <link>https://dev.to/shreya_princy_8194cc37e3f/atomicity-design-a-reliable-wallet-transfer-system-with-acid-guarantees-1635</link>
      <guid>https://dev.to/shreya_princy_8194cc37e3f/atomicity-design-a-reliable-wallet-transfer-system-with-acid-guarantees-1635</guid>
      <description>&lt;h1&gt;
  
  
  Atomicity in Action: Designing a Reliable Wallet Transfer System with ACID Guarantees
&lt;/h1&gt;

&lt;p&gt;Building a wallet system like PhonePe, GPay, or Paytm requires strict data consistency. Even a small error can lead to money loss, duplicate transactions, or incorrect balances. This is why ACID properties, especially Atomicity, are critical in such systems.&lt;/p&gt;

&lt;p&gt;Atomicity ensures that all operations in a transaction are completed successfully. If any step fails, the entire transaction is rolled back, and the database remains unchanged.&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 sample data:&lt;/p&gt;

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

&lt;p&gt;Initial state of the table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;ID&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Balance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h1&gt;
  
  
  Successful Transaction
&lt;/h1&gt;

&lt;p&gt;Transfer 200 from Alice to Bob using a transaction:&lt;/p&gt;

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

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

&lt;p&gt;After execution:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Balance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;800&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;700&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Both operations succeed, and the transaction is committed. The data remains consistent.&lt;/p&gt;

&lt;h1&gt;
  
  
  Failure After Debit Operation
&lt;/h1&gt;

&lt;p&gt;Now introduce an error after deducting money from Alice:&lt;/p&gt;

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

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

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

&lt;p&gt;The second query fails due to an invalid column name. The database aborts the transaction.&lt;/p&gt;

&lt;p&gt;Final state:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Balance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The deduction from Alice is rolled back. No partial update occurs.&lt;/p&gt;

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

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

&lt;p&gt;Final state remains unchanged:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Balance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;1000&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;500&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The rollback cancels all changes made during the transaction.&lt;/p&gt;

&lt;h1&gt;
  
  
  Without Transaction
&lt;/h1&gt;

&lt;p&gt;If the same operations are executed without a transaction:&lt;/p&gt;

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

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

&lt;p&gt;Alice’s balance is reduced, but Bob does not receive the money. This leads to inconsistency.&lt;/p&gt;

&lt;p&gt;Transactions ensure all operations are executed completely or not at all.&lt;br&gt;
Errors automatically trigger rollback.&lt;br&gt;
Partial updates are prevented.&lt;br&gt;
Data integrity is maintained.&lt;br&gt;
Transactions are essential for financial systems.&lt;/p&gt;

&lt;p&gt;Atomicity guarantees that a transaction is treated as a single unit of work. In a wallet system, this ensures that money is neither lost nor duplicated. By using transaction blocks, the system remains consistent even in the presence of failures.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>database</category>
      <category>sql</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
