This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

readall

Read all data in DatabaseDatastore

Syntax

data = readall(dbds)

Description

example

data = readall(dbds) returns all the data in the DatabaseDatastore object dbds, and resets the DatabaseDatastore to the point where no data has been read from it.

Note

readall returns data as a table only. readall ignores database preference settings for data return formatting.

Examples

collapse all

Using a JDBC driver, create a database connection to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password. The code assumes that you are connecting to database toy_store, database server dbtb04, and port number 54317.

conn = database('toy_store','','','Vendor','Microsoft SQL Server', ...
    'Server','dbtb04','PortNumber',54317,'AuthType','Windows');

Create a DatabaseDatastore object using the database connection and SQL query. This SQL query reads all data from the table.

sqlquery = 'select * from airlinesmall';

dbds = databaseDatastore(conn,sqlquery);

Read all data in the DatabaseDatastore object.

data = readall(dbds);

data contains the query results.

Display the first three rows of query results.

data(1:3,:)
ans = 

    Year    Month    DayofMonth    DayOfWeek    DepTime    CRSDepTime    ArrTime    CRSArrTime    UniqueCarrier    FlightNum    TailNum    ActualElapsedTime    CRSElapsedTime    AirTime    ArrDelay    DepDelay    Origin    Dest     Distance    TaxiIn    TaxiOut    Cancelled    CancellationCode    Diverted    CarrierDelay    WeatherDelay    NASDelay    SecurityDelay    LateAircraftDelay
    ____    _____    __________    _________    _______    __________    _______    __________    _____________    _________    _______    _________________    ______________    _______    ________    ________    ______    _____    ________    ______    _______    _________    ________________    ________    ____________    ____________    ________    _____________    _________________

    1987    10       28            3            1140       1140          1212       1215          'US'             262          'NA'       32                   35                'NA'        -3         0           'CLE'     'PIT'    105         'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1987    10        9            5            1155       1155          1250       1300          'US'             282          'NA'       55                   65                'NA'       -10         0           'ROC'     'LGA'    254         'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             
    1987    10       22            4             715        715           807        803          'US'             304          'NA'       52                   48                'NA'         4         0           'DTW'     'PIT'    201         'NA'      'NA'       0            'NA'                0           'NA'            'NA'            'NA'        'NA'             'NA'             

Close the DatabaseDatastore object and database connection.

close(dbds)

Input Arguments

collapse all

Datastore containing data in a database, specified as a DatabaseDatastore object created using the databaseDatastore function.

Output Arguments

collapse all

Query results, returned as a table of the records in the data set. Executing the SQL statement specified in the Query property of the DatabaseDatastore object creates the data set.

Introduced in R2014b