Introduction to Structured Query Language (SQL)
Inserting records
Insert a record with some values missing.
INSERT INTO adds new records (rows) to a table. It is a DML (Data Manipulation Language) statement.
Giving every value, in column order: INSERT INTO GUARDIAN VALUES (444444444444, 'Amit Ahuja', 5711492685, 'G-35, Ashok Vihar, Delhi');
- Text and date values go in single quotes; numbers do not.
- Without column names, a value must be given for every column, in the same order as the table's structure. Where a value is unknown, write NULL.
Giving only some values: name the columns: INSERT INTO GUARDIAN(GUID, GName, GAddress) VALUES (333333333333, 'Danny Dsouza', 'S-13, Ashok Village, Daman'); Columns left out get NULL or their DEFAULT value (unless they are NOT NULL, which causes an error).
Order of insertion with foreign keys. STUDENT.GUID is a foreign key referring to GUARDIAN, so a guardian's record must be inserted into GUARDIAN first; only then can a student with that GUID be added to STUDENT. Likewise, students must exist before their attendance is recorded.
Primary keys cannot repeat: inserting a second record with an existing primary key value gives an error.
Checking: SELECT * FROM GUARDIAN; shows all the records inserted so far.
Example (new): to add a club member whose sport is not yet known: INSERT INTO MEMBER(MemberID, MName, JoinDate) VALUES (17, 'Ritu Sen', '2025-06-01'); The Sport column, left out, is stored as NULL.
Practise this lesson
Questions that get harder as you improve, a Tutor that helps without giving the answer away, and progress you can see. Free for every learner.
No account, no email address. Opens the real product.