| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Database Toolbox |
| Contents | Index |
| Learn more about Database Toolbox |
This example updates the date field that you previously imported into the Avg_Freight_Cost table using the following Database Toolbox functions:
For more information on these functions, see matlab\toolbox\database\dbdemos\dbupdatedemo.m.
If you have completed the previous example, skip this step. Otherwise, enter the following commands:
conn = database('SampleDB', '', '');
colnames = {'Calc_Date', 'Avg_Cost'};
D = '20-Jan-2002';
meanA = 36.6067;
exdata = {D, meanA}
exdata =
'20-Jan-2002' [36.6067]
Change the date in the Avg_Freight_Cost table from 20-Jan-2002 to 19-Jan-2002:
D = '19-Jan-2002'
Assign the new date value to the newdata cell array.
newdata(1,1) = {D}
newdata =
'19-Jan-2002'
Specify the record to update in the database by defining a SQL where statement and assigning it to the variable whereclause. The record to update is the record whose Calc_Date is 20-Jan-2002. Because the date string is within a string, it is embedded within two single quotation marks rather than one.
whereclause = 'where Calc_Date = ''20-Jan-2002''' whereclause = where Calc_Date = '20-Jan-2002'
Export the data, replacing the record whose Calc_Date is 20-Jan-2002.
update(conn,'Avg_Freight_Cost',colnames,newdata,whereclause)
In Microsoft Access, view the Avg_Freight_Cost table to verify the results.

Close the cursor and disconnect from the database.
close(conn)
![]() | Exporting Data from the MATLAB Workspace to a New Record in a Database | Exporting Multiple Records from the MATLAB Workspace | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |