How do I use the UPDATE command to update a column for all the rows in my table?

1 回表示 (過去 30 日間)
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.

採用された回答

MathWorks Support Team
MathWorks Support Team 2011 年 3 月 3 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2008a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by