INSERT: It's a Boy!

We have a new patient and want to add him to the table. Robin Banks was born March 12, 2009 and is a boy. We will add him with the command;
INSERT INTO Patients(FirstName,LastName,Birthdate,Gender)
VALUES("Robin","Banks","2009-03-12","M")

We do not give a value for Patient because that fields value is generated automatically.

OOPS: Correct a mistake

We just found out that we spelled one of our patients names wrong. Find one of the patients named Deborah and change her name to Debra. Don't change everyone, just one person!
SELECT * FROM Patients WHERE FirstName="Deborah" then find the patient number and change the name as:

UPDATE Patients SET FirstName="Debra" WHERE Patient="52" or


UPDATE Patients SET FirstName="Debra" WHERE FirstName="Deborah" AND LastName="Smith"

OOPS: Correct more than 1 mistake

We can correct more than one mistake: UPDATE Patients SET FirstName="Debra", LastName="Jones" WHERE Patient="52"

DELETE

This person is too much work, let's just get rid of her! It is a very good idea to select a record first to make sure that is is really the one you want to delete! Be very careful with delete, there is no undoing it.
SELECT * FROM Patients WHERE Patient=11
(Make sure that it is the one you want.)

DELETE FROM Patients WHERE Patient=11 (If you are sure, delete it.)

You must also delete the diseases for that person:
DELETE FROM Diseases WHERE ID=11


INDEX, Retrieving Records with PHP, Add, Update and Delete, Missing Data, Join Tables, ALTER Table
Next lesson: FormsMAIN INDEX
EXAMPLES INDEX

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Add, Update and Delete