This free online course will teach you how to install the MySQL database and perform standard CRUD (Create, Read, Update, and Delete) operations to manipulate the data in the database. You'll learn how to execute a SQL query, which is a way of asking the database to give us the specific data we're looking for, and how to modify existing data using a SQL statement.
Most business applications store critical information in a database, and having database experience is an important skill to have on your resume in today's IT world.
Course Prep:
- Read Chapter #14 (pages 591 - 605) in the Core Servlets and JavaServer Pages textbook.
The reading in chapter 14 does a good job of covering general SQL CRUD statements, and the statements work the same regardless of which database is used (in fact, the book uses the Hypersonic database, but we'll stick with MySQL which is much more widely used in the real world).
- Download and install MySQL Server 5.0 by following the instructions in MySQL5_Install_Configure.doc.
- View the MySQL lecture (also available in pdf format here), which provides an overview of database concepts and an introduction to SQL CRUD operations.
Course Exercises:
- Open a MySQL command window and enter the SQL commands from the lecture. You'll find the MySQL command window by running mysql.exe, located in the bin folder of your MySQL installation.
- Save a pre-built SQL script to your system by right-clicking on this file and saving it to your hard-drive: etraining.txt.
- Load the etraining.txt script into MySQL using the source command (refer to the lecture slides for usage instructions).
- Use the MySQL commands described in the lecture to view the Etraining database tables, and select all records from the users and accounts tables.
- Delete a record from each table, using a SQL Delete statement.
- Add a new record to each table, using a SQL Insert statement.
- Change the username of one of the records in the users table, using a SQL Update statement.
- Change the account balance of one of the records in the accounts table, using a SQL Update statement.
- Notice that the accounts table contains an AccountKey field and a UserKey field. Select both the UserName and the Account balance in the same SQL query using a join (shown below):
SELECT users.UserName, accounts.Balance
FROM users, accounts
WHERE users.UserKey = 4
Congratulations - by reading the lecture slides and performing the tasks listed above, you should now be familiar with basic database operations.