To insert the details of at least 10 students in the student table
Expt. No.23
Page No.46
Insert 10 students
Aim
To insert the details of 10 students into the STUDENT table.
Concepts used
Queries
USE school;INSERT INTO student VALUES (1, 'XI', 'A', 'F', 'Aarohi', '2009-03-14', 78);INSERT INTO student VALUES (2, 'XI', 'A', 'M', 'Bharat', '2008-11-02', 45);INSERT INTO student VALUES (3, 'XI', 'B', 'M', 'Chetan', '2009-07-21', NULL);INSERT INTO student VALUES (4, 'XI', 'B', 'F', 'Divya', '2009-01-30', 91);INSERT INTO student VALUES (5, 'XII', 'A', 'M', 'Eshan', '2008-05-17', 66);INSERT INTO student VALUES (6, 'XII', 'A', 'F', 'Fatima', '2008-09-09', 83);INSERT INTO student VALUES (7, 'XII', 'B', 'M', 'Gagan', '2007-12-25', 38);INSERT INTO student VALUES (8, 'XII', 'B', 'F', 'Hina', '2008-02-11', NULL);INSERT INTO student (rno, class, section, gender, name, dob, marks)VALUES (9, 'XI', 'A', 'M', 'Ishan', '2009-10-05', 57);INSERT INTO student VALUES (10, 'XII', 'A', 'F', 'Jaya', '2008-06-28', 74);
A marked line continues the line above it. In your file, write it on the same line.
Table used
Table: student
+-----+-------+---------+--------+------+-----+-------+ | rno | class | section | gender | name | dob | marks | +-----+-------+---------+--------+------+-----+-------+ +-----+-------+---------+--------+------+-----+-------+
Output
mysql> USE school;
Database changed
mysql> INSERT INTO student VALUES (1, 'XI', 'A', 'F', 'Aarohi', '2009-03-14', 78);
Query OK, 1 row affected
mysql> INSERT INTO student VALUES (2, 'XI', 'A', 'M', 'Bharat', '2008-11-02', 45);
Query OK, 1 row affected
mysql> INSERT INTO student VALUES (3, 'XI', 'B', 'M', 'Chetan', '2009-07-21', NULL);
Query OK, 1 row affected
mysql> INSERT INTO student VALUES (4, 'XI', 'B', 'F', 'Divya', '2009-01-30', 91);
Query OK, 1 row affected
mysql> INSERT INTO student VALUES (5, 'XII', 'A', 'M', 'Eshan', '2008-05-17', 66);
Query OK, 1 row affected
mysql> INSERT INTO student VALUES (6, 'XII', 'A', 'F', 'Fatima', '2008-09-09', 83);
Query OK, 1 row affected
mysql> INSERT INTO student VALUES (7, 'XII', 'B', 'M', 'Gagan', '2007-12-25', 38);
Query OK, 1 row affected
mysql> INSERT INTO student VALUES (8, 'XII', 'B', 'F', 'Hina', '2008-02-11', NULL);
Query OK, 1 row affected
mysql> INSERT INTO student (rno, class, section, gender, name, dob, marks)
-> VALUES (9, 'XI', 'A', 'M', 'Ishan', '2009-10-05', 57);
Query OK, 1 row affected
mysql> INSERT INTO student VALUES (10, 'XII', 'A', 'F', 'Jaya', '2008-06-28', 74);
Query OK, 1 row affected
✓ Printed by running this query set, not typed by hand.
Result
Ten rows were inserted, each reported as "Query OK, 1 row affected". Two students (Chetan and Hina) have NULL marks, because their marks are not entered yet. The table on the facing page shows the data after the inserts.
Viva voce: what the examiner may ask
01When must column names be listed in INSERT?
When you don't give a value for every column, or give them in a different order.
02How is a missing value entered?
As NULL, without quotes.
03Why are strings and dates in single quotes?
SQL needs quotes around text and date values; numbers don't need them.
Variations for the lab test
- Insert a student giving only rno, name and class.
- Try inserting a student with an existing rno and read the error.
- Insert three rows with one INSERT statement.
! Common mistake Inserting the date as 14-03-2009 gives an error or a wrong date; MySQL expects 'YYYY-MM-DD'.