Show navigation

Week 6 - DML & DDL

This week we'll learn how to use commands from DML & DDL, including INSERT, UPDATE, DELETE, REPLACE, CREATE, ALTER and DROP. These commands are very powerful, but I think you'll find them simple to use!







Footnotes

1 Again, this is a matter of semantics, but some would omit DQL as a category entirely and consider SELECT to be a part of DML, since SELECT manipulates data en route to the results table. Others argue that this doesn't count as manipulating data, since results tables are temporary, and nothing in the database is affected by the query. And honestly, it makes me question whether I should even mention this stuff to you guys, because it's not going to help you remember this stuff even better, but I don't have the constitution to present information to you as if it's absolute truth when there are conflicting sources out there. Better, I think, for you to be confused in class, than to be given confidence in class, only to be confused once you're out on your own.
↑ Back to reference 1
2 I'm not gonna let you create, update or delete databases on my server, though. Get your own!
↑ Back to reference 2
3 ...by default. You can set up your AUTO_INCREMENT column to increment by other values.
↑ Back to reference 3
4 It's possible to make your primary key a combination of columns, but not by declaring it in the column definition. You have to use CONSTRAINT, but we're not going to learn about constraints yet - we'll save that until we're back from the break.
↑ Back to reference 4

Exercises!

  1. Create a new table in your database. Give it an auto-incrementing primary key, and one column each with the data type date, time, and decimal.
  2. Insert three rows, without explicitly adding a value to the primary key column.
  3. Replace one of the existing rows.
  4. Update one (and only one) of the other rows.
  5. Delete one row.
  6. Add a column. Make it so that this column will only accept whole numbers, and will not accept null values.
  7. Rename this column.
  8. Give this column a default value.
  9. Delete a column.
  10. Delete your table.
Here's what we're going to do today:Categories of SQL CommandsData Manipulation LanguageData Definition Language