Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 30 - 2617_JSSPS_C-8
P. 30

    We can also use the wildcards (_and %) with the SELECT command to specify conditions. The _ wildcard
                  denotes a single character, on the other hand the % wildcard denotes the multiple characters:

                        SELECT FirstName, Marks FROM Student WHERE LastName like 'K%';

                                                        +-----------+-------+
                                                        | FirstName | Marks |
                                                        +-----------+-------+
                                                        | Divya     |   450 |
                                                        | Aadarsh   |   450 |
                                                        +-----------+-------+

                        SELECT Marks FROM Student WHERE FirstName like 'D%';

                                                                +-------+
                                                                | Marks |
                                                                +-------+
                                                                |   450 |
                                                                +-------+

                  UPDATING RECORDS IN A TABLE

                  Sometime, you may need to change the detail inserted into a table. In that case, the UPDATE command
                  will work. The syntax of the UPDATE command is:

                      UPDATE table_name SET field_change=value WHERE field_criteria=value;
                  Let us change the marks of the student  having  10002  as StudentID  from 480  to 485  by using  the
                  following command:

                      UPDATE Student SET Marks = 485 where StudentID = 10002;
                                          +-----------+-----------+----------+-------+
                                          | StudentID | FirstName | LastName | Marks |
                                          +-----------+-----------+----------+-------+
                                          |     10001 | Amit      | Sharma   |   450 |
                                          |     10002 | Divya     | Kaushik  |   485 |
                                          |     10003 | Aadarsh   | Kumar    |   450 |
                                          +-----------+-----------+----------+-------+

                  REMOVING RECORDS FROM A TABLE

                  The DELETE command is used to remove records from a table. The DELETE command can be used in
                  two ways:
                      Without WHERE clause

                      With the WHERE clause
                  We can remove a specific record by using the WHERE clause with the DELETE command. If we use the
                  DELETE command without the WHERE clause, it will remove all the records from a table. Let us use the
                  DELETE command to remove the record of a student whose LastName is Kumar:

                      DELETE FROM Student WHERE LastName="Kumar";
                  To remove all the records, following command is used:

                      DELETE FROM Student;

                            Premium Edition-VIII
                     28

| 25 26 27 28 29 30 31 32 33 34 35 |