Wasabi Posted June 2, 2011 Share Posted June 2, 2011 On page 201, Chapter 7 SQL errors are normally a matter of syntax,and they’ll be reported when you try to run the query on MySQL. For example, I’ve done this many times (Figure 7.3): DELETE * FROM tablename The syntax is just wrong, a confusion with the SELECT syntax (SELECT * FROM tablename). The right syntax is DELETE FROM tablename However, I've seen this syntax used here: W3Schools and SQL Keywords: DELETE, and other "Googled" examples. However, the error is returned as stated in the publication from phpMyAdmin. As I always defer to this forum, could someone explain this discrepancy? Link to comment Share on other sites More sharing options...
Paul Swanson Posted June 2, 2011 Share Posted June 2, 2011 DELETE removes a row, so there is no need to use a wildcard. If you want to remove a particular value from a row, you need to use an UPDATE query and set the value to NULL or an empty string. When using DELETE, be sure to include a WHERE clause. Omitting that would delete EVERY row in the table. I also use a 'LIMIT 1' clause as an extra precaution. If you use LIMIT 1 without a WHERE, at least you'll only affect one row, although it probably won't be the one you intended. 1 Link to comment Share on other sites More sharing options...
Recommended Posts