MATLAB: How to use the UPDATE command to update a column for all the rows in the table

bydatabaseDatabase Toolboxdborderorderbywhere

I am using the Database Toolbox 3.4.1 (R2008a). I want to update a column in my table with a given value using the UPDATE command without the WHERE clause.

Best Answer

A column in a table can be updated for all the rows using the UPDATE command with the ORDER BY clause instead of the WHERE clause.
For example, refer to the code below:
% Create the table
query = 'CREATE TABLE test2 (col1 varchar(10), col2 varchar(5))';
results = exec(conn,query);
results = fetch(results);
results.Data
query = 'SHOW tables';
results = exec(conn,query);
results = fetch(results);
results.Data
%Insert Rows
exdata = {'San Diego', 'CA'}
colnames = {'col1', 'col2'}
fastinsert(conn, 'test2', colnames, exdata)
exdata = {'Hartford', 'CT'}
fastinsert(conn, 'test2', colnames, exdata)
query = 'SELECT * from test2';
results = exec(conn,query);
results = fetch(results);
results.Data
% UPDATE the rows
update(conn, 'test2', {'col1'}, {'NewYork'}, '');
query = 'SELECT * from test';
results = exec(conn,query);
results = fetch(results);
results.Data