|
Updating a Record Using SQL |
|
|
To edit a value using SQL, you start with the UPDATE
keyword and follow this formula:
UPDATE TableName
SET ColumnName = NewValue
|
The TableName is the name of the table where the
update will be made.
The ColumnName
is the one that will receive change. The column mu be a valid column in the TableName table.
The NewValue
factor is the value that will replace the old one.
If
you use this formula, all records of the ColumnName would be given the
NewValue.
Here is an example:
UPDATE Videos
SET Rating = "PG-13"
If you want to change a particular record, the formula to use is:
UPDATE TableName
SET ColumnName = NewValue
WHERE Condition
The Condition
specifies how the value will be located.
Here is an example:
UPDATE Videos
SET Director = "Peter Segal"
WHERE ShelfNumber = "CM-8842"
This can be done in code as follows: Private Sub cmdMaintenance_Click()
Dim strDataUpdate As String
strDataUpdate = "UPDATE Videos " & _
"SET Director = 'Peter Segal' " & _
"WHERE ShelfNumber = 'CM-8842';"
DoCmd.RunSQL strDataUpdate
End Sub
|