Search Marketing

   
   

Delete Single Record in Database Table

Fri May 02, 2008 9:54 pm
<<     >>
Comments: 2 Views: 2550

Deleting a MySQL Database table record is similar to Selecting from one.

You use the "Where" option in the statement to determine which entries (rows) become deleted.

1. Lets assume we have the following database table.

mysql> select * from customers;
+----+--------+
| ID | Name |
+----+--------+
| 1 | John |
| 2 | James |
| 3 | Jack |
| 4 | Jim |
| 5 | Johnna |
+----+--------+

The table above has two fields (ID,Name).

2. Lets assume we wanted to delete the record Johnna.

mysql> delete from customers where ID=5;

mysql> select * from customers;

+----+-------+
| ID | Name |
+----+-------+
| 1 | John |
| 2 | James |
| 3 | Jack |
| 4 | Jim |
+----+-------+

You can see that ID 5 was removed from the results.

Note: If this were a real-world example you would want to make sure you do not have any orphaned records in other tables. To completely remove a series of records see:

Delete Multiple Records Across Different Database Tables



Comments
Thu Apr 10, 2008 6:26 am
Name: nae | Comment: hi
thanks
for the coding
much interesting code, it works
tankx again



Mon Mar 02, 2009 4:01 am
Name: Raj | Comment: extra ordinary coding thanx alot try better

Name:
*
URL: http: (ex. cnn.com)
Comment:
*
Number:
Math (26 + 1)
* required
SubCategories
Books

© 2017 Christonium LLC

Christonium.com
|
Terms of Use
|
Privacy
ccc