TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst · 76.7K subscribers
Post #2821 378
ROLLBACK;


If everything is correct:

COMMIT;


This can be useful when performing potentially dangerous data modifications.

1️⃣8️⃣ A Safe Pattern for Data Changes

Before executing a large UPDATE or DELETE, analysts often first run a SELECT using the same condition.

Instead of immediately doing:

UPDATE customers
SET status = 'Inactive'
WHERE last_order_date < DATE '2024-01-01';


first check:

SELECT *
FROM customers
WHERE last_order_date < DATE '2024-01-01';


Then, where transaction support and operational rules permit:

BEGIN;

UPDATE customers
SET status = 'Inactive'
WHERE last_order_date < DATE '2024-01-01';

-- Verify the affected rows

COMMIT;


If something looks wrong:

ROLLBACK;


This is a valuable habit when working with production data.

1️⃣9️⃣ Transactions and Autocommit

Many database clients use an autocommit mode.

When autocommit is enabled, individual statements may be committed automatically.

For example:

UPDATE customers
SET status = 'Active'
WHERE customer_id = 101;


may be committed immediately.

That means you may not be able to simply run:

ROLLBACK;


after the statement has already been committed.

The exact behavior depends on:

• Database system

• Client/tool

• Connection settings

• Transaction configuration

Always understand the transaction mode before modifying production data.

20️⃣ Transactions and DDL

Statements such as:

• CREATE

• ALTER

• DROP

are DDL statements.

Their transaction behavior varies significantly across database systems.

Some databases implicitly commit certain DDL operations.

Therefore, don't assume:

BEGIN;
DROP TABLE test_table;
ROLLBACK;
More from @sqlanalyst
  1. Sep 29, 2026SQL Interview Series — Part 2 📌 Question 2: Find Duplicate Records Suppose you have an Em…
  2. Sep 29, 2026𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗟𝗲𝗮𝗿𝗻 𝗔𝗜 𝗶𝗻 𝟮𝟬𝟮𝟲🚀 ​ Explore 6 free resource…
  3. Sep 29, 2026SQL Interview Series — Part 1 Hi guys, let's start a SQL interview series covering frequen…
  4. Sep 28, 2026🧠 Real-World SQL Scenario-Based Questions & Answers 1. Get the 2nd highest salary from th…
  5. Sep 28, 2026🎓 𝗛𝗔𝗥𝗩𝗔𝗥𝗗 𝗨𝗡𝗜𝗩𝗘𝗥𝗦𝗜𝗧𝗬 𝗙𝗥𝗘𝗘 𝗢𝗡𝗟𝗜𝗡𝗘 𝗖𝗢𝗨𝗥𝗦𝗘𝗦 😍 Dreaming of…
  6. Sep 27, 2026Data Analytics Roadmap | |-- Fundamentals | |-- Mathematics | | |-- Descriptive Statistics…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →