PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

SQL · Theory

Table Locking

← All stacks

Theory

27/439

Table Locking

LOCK TABLES students WRITE; stops others from writing that table until UNLOCK TABLES; This is old-school. InnoDB row locks inside transactions are the normal way: START TRANSACTION; UPDATE …; COMMIT;

READ lock lets others read. WRITE lock is exclusive. Easy to deadlock a lab if you forget UNLOCK.

Trap — LOCK TABLES as the answer for every concurrency question. Prefer transactions + InnoDB.

On the example next to this theory: Table Locking: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Exam tip

Know LOCK TABLES exists. Prefer START TRANSACTION for InnoDB.

Table Locking — sample query

-- Table Locking
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

Table Locking: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Short notes

  • DefLOCK TABLES … READ/WRITE then UNLOCK TABLES.
  • RulePrefer InnoDB transactions for real apps.
  • TrapForgetting UNLOCK TABLES.

Questions

1

Modern alternative to LOCK TABLES?

27 / 439

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.