Page 27 - Modular_V2.0_SQL_Flipbook
P. 27

3                                                     HANDLING RECORDS



                                                                                                 IN MYSQL










                         Your Aim

                         to learn about:
                                  Inserting Records in a Table            Retrieving Records from a Table
                                   Updating Records in a Table              Deleting Records from a Table
                                     Using DISTINCT Clause                  Using Operators
                                      MySQL Comments



                 In the previous chapter, you learnt how to create a table, add or remove a column, and change the
                 data type of a column. In this chapter, you will learn how to insert records, update records, and
                 delete records.


                     INSERTING RECORDS IN A TABLE

                 After creating a table, you can insert records into it by using the INSERT command. The syntax to
                 insert a record into a table is:

                     INSERT INTO table_name
                     VALUES ('val_column1', 'val_column2', ... , 'val_columnN');

                 The values should be in exact order as they were defined in the table.
                 Let's insert the following records in the Students table created in the previous chapter:

                                                           Table-STUDENTS

                     Student_id     First_name      Last_name        Marks                     Address
                        10001      Amit            Sharma              450       E-458, Vikas Puri, New Delhi

                        10002      Divya           Kaushik             480       9, Ansari Road, Daryaganj, New Delhi
                        10003      Aadarsh         Kumar               475       22/12, Sarita Vihar, New Delhi

                 To insert the above records, you can use the following commands:

                     INSERT INTO Students  VALUES (10001,  'Amit', 'Sharma',  450, 'E-458, Vikas
                     Puri, New Delhi');
                     INSERT INTO Students VALUES (10002, 'Divya', 'Kaushik', 480, '9, Ansari Road,
                     Daryaganj, New Delhi');


                                                                                                                     25
                                                                                          Handling Records in MySQL
   22   23   24   25   26   27   28   29   30   31   32