How do I use the UPDATE command to update a column for all the rows in my table?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
Respuesta aceptada
MathWorks Support Team
el 3 de Mzo. de 2011
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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Database Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!