A database can be manipulated in four possible ways: addition, deletion, modification, and search. These topics will all be briefly covered in the following two sections. However, before we begin, I would like to highlight the fact that SQL, like many computer languages, is somewhat particular about command syntax. The slightest error in placement of a parentheses, comma, or semicolon will almost surely end in error. As a result, take care to be attentive of command syntax. Insertion of records Note: The originally created table, test, created in the last section will be used to illustrate the examples in this section. Here it is again, for quick reference:
Insertion of data into the table is accomplished, logically enough, using the INSERT command.
Result, assuming the command was correctly entered:
So what happened?
Note: It is of importance to remember that the same number of values must be inserted as datatypes are contained within a record. In the above example, if one attempted to insert only three values instead of four, the insertion would fail. The same result applies if one attempted to insert five values. Example:
Note (2): One of the advantageous aspects of MySQL is it's ability to convert without trouble between datatypes. MySQL automatically converts between integers, strings, and dates without problems. Selection A database would not be much use if one was not able to search and extract data from it. In MySql terms, this is accomplished through the SELECT statement. Result:
Let's assume we have inserted four differing records, all bearing the same name of "Bugs Bunny", yet having different email addresses and phone numbers. The table test, would look somewhat like the following:
Deletion One can also delete records inserted into the table. This is accomplished through the DELETE command.
Result: Another example:
Result: (Using the previously illustrated example)
Modification MySQL also has the capability of modifying data already entered into the table. This is accomplished through the UPDATE command.
This section, we covered the core MySQL database manipulation functions, basic insertion, deletion, modification, and search. The next section will elaborate on these capabilities, providing extended functioning and flexibility when manipulating the database.
blog comments powered by Disqus |