Hdip Software Project: DR Martina Naughton
Hdip Software Project: DR Martina Naughton
Dr Martina Naughton
Room: A1.15
E-mail: [email protected]
Databases Topics covered this
week
Aims:
MySQL - Intro to the SQL query language
Students Table
student_id first_name last_name
1 Martina Naughton
2 Joe Bloggs
3 Bary MCCarthy
3. Click ‘Open’
Connecting to MySQL
mysql>
You can now specify that this is the database that you want
to operate on with this command:
Each file should have one record per line, with the
fields on each line delimited by a tab character.
1 Martina Naughton
2 Tina Woods A <tab> separates each field
3 Bary MCCarthy
4 Jeff Phelan
5 Marcus Alvers
6 Michael Amadore
7 Carl Gaffney
8 Rachel Mooney
9 Lisa Fowler
10 August Makalakalane
Loading Data from a file
Example:
mysql> LOAD DATA LOCAL INFILE 'students.txt'
INTO TABLE students;
Expected Output:
Query OK, 10 rows affected (0.00 sec)
Records: 10 Deleted: 0 Skipped: 0 Warnings: 0
Entering data one item at a
time
Use INSERT command
See http://dev.mysql.com/doc/refman/5.0/en/insert.html for more
information
Syntax: INSERT INTO table_name (field_name1,
field_name2) VALUES(val1,val2,val3);
Examples:
insert into students (student_id, first_name,
last_name) values (1, "Martina", "Naughton");
OR
insert into students (student_id, first_name,
last_name) values (null, ”joe", ”Bloggs");
The * indicates that you want all the fields in the table to be selected.
Your response should look something like:
+------------+------------+-----------+
| student_id | first_name | last_name |
+------------+------------+-----------+
| 1 | Martina | Naughton |
| 2 | Joe | Bloggs |
+------------+------------+-----------+
Selecting Data cont’d
+------------+------------+-----------+
| student_id | first_name | last_name |
+------------+------------+-----------+
| 2 | Joe | Bloggs |
+------------+------------+-----------+
1 row in set (0.00 sec)
Selecting Data cont’d
Expected output:
+------------+------------+-----------+------------+----------+-------+
| student_id | first_name | last_name | student_id | class_id | grade |
+------------+------------+-----------+------------+----------+-------+
| 1 | John | Falkner | 1 | 1 | 25.5 |
| 1 | John | Falkner | 1 | 2 | 74.2 |
+------------+------------+-----------+------------+----------+-------+
2 rows in set (0.01 sec)
Updating Data
Cover on Wednesday..