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 CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

제품


릴리스

R2008a

Community Treasure Hunt

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

Start Hunting!

Translated by