MATLAB DATABASE TOOLBOX RELEASE NOTES Guía de usuario Pagina 358

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 684
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 357
6 Using Database Toolbox Functions
6-16
Delete Data from Databases
This example shows how to delete data from your database using MATLAB.
Create the SQL string with your deletion SQL statement. Consult your database
documentation for the correct SQL syntax. Execute the delete operation on your database
using exec with your SQL string. This example demonstrates deleting data records in a
Microsoft Access database.
Connect to the Database
Connect to the Microsoft Access database using native ODBC and the data source name
dbtoolboxdemo. This database contains the table inventoryTable with the column
productNumber.
conn = database.ODBCConnection('dbtoolboxdemo','','');
Display the last rows in the table inventoryTable.
curs = exec(conn,'select * from inventoryTable');
curs = fetch(curs);
curs.Data
ans =
...
[11] [ 567] [ 0] '2012-09-11 00:30...'
[12] [1278] [ 0] '2010-10-29 18:17...'
[13] [1700] [14.5000] '2009-05-24 10:58...'
Delete a Specific Record
Delete the data for the product number 13 from the table inventoryTable. Specify the
product number using the WHERE clause in the SQL statement.
curs = exec(conn,'delete * from inventoryTable where productNumber = 13');
Display the last rows in the table inventoryTable after the deletion.
curs = exec(conn,'select * from inventoryTable');
curs = fetch(curs);
curs.Data
ans =
Vista de pagina 357
1 2 ... 353 354 355 356 357 358 359 360 361 362 363 ... 683 684

Comentarios a estos manuales

Sin comentarios