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

SQL · Theory

How to Add Data to MySQL Database

← All stacks

Theory

339/439

How to Add Data to MySQL Database

INSERT INTO students (roll, name, marks) VALUES (12, 'Asha', 72); adds one row. List the columns. Don’t rely on column order in the table — tomorrow someone ALTERs it.

Many rows — INSERT INTO students (roll, name, marks) VALUES (12,'Asha',72), (13,'Kabir',40); One statement, two rows.

AUTO_INCREMENT: skip that column, MySQL fills it. Duplicate PRIMARY KEY → error 1062. INSERT IGNORE skips the bad row. ON DUPLICATE KEY UPDATE changes the old row instead.

Trap — INSERT INTO students VALUES ('Asha', 12, 72) with columns in the wrong order. Trap: inserting NULL into NOT NULL.

On the example next to this theory: How to Add Data to MySQL Database: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Exam tip

INSERT INTO students (roll, name, marks) VALUES (12, 'Asha', 72);

How to Add Data to MySQL Database — sample query

-- How to Add Data to MySQL Database
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;

How to Add Data to MySQL Database: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Short notes

  • DefINSERT INTO t (cols) VALUES (…);
  • RuleName columns. Multi-row VALUES (a),(b).
  • TrapWrong column order. Duplicate PK.

Questions

1

Write an INSERT.

2

How do you insert two rows?

339 / 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.