Main Content

preview

Return subset of data fromDatabaseDatastore

Description

example

data= preview(dbds)returns the first eight rows of data from theDatabaseDatastoreobjectdbdswithout changing its current position.

Note

previewreturns data as a table only.previewignores database preference settings for data return formatting.

If there is no data to read from the query,previewthrows an error.

Examples

collapse all

创造e a database connection using a JDBC driver. To create this connection, you must configure a JDBC data source. For more information, see theconfigureJDBCDataSourcefunction. Then, create aDatabaseDatastoreobject and preview the data stored in the object.

创造e a database connection to the JDBC data sourceMSSQLServerJDBCAuth. This data source configures a JDBC driver to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password.

datasource ="MSSQLServerJDBCAuth"; username =""; password =""; conn = database(datasource,username,password);

创造e aDatabaseDatastoreobject using the database connection and an SQL query. This SQL query reads all data from theairlinesmalltable.

sqlquery ='select * from airlinesmall'; dbds = databaseDatastore(conn,sqlquery);

Preview the first eight records in the data set returned by executing the SQL query in theDatabaseDatastoreobject.

preview(dbds)
ans = 8×29 table 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 ____ _____ __________ _________ _______ __________ _______ __________ _____________ _________ ________ _________________ ______________ _______ ________________ ______ _____ ________ ______ _______ _________ ________________ ________ ____________ ____________ ________ _____________ _________________ 1990 9 11 2 1810 1812 1939 1930 'AA' 1426 'NA' 89 78 'NA' 9 -2 'RST' 'ORD' 268 'NA' 'NA'0'na'0'na''na''na''1104'na''na'0'na'0'na'na'na''na''na'''roc''ewr'246'na''na'0'na'0'na'na''na''na''na''8 1 1515 1440 1609 1535'nw'749'na'NA'54 55'na'34 35'MSP''fsd'fsd'na'''Na'1990 10 19 5 1130 1120 1203 1154'UA'369'na'93 94'na'90'9 10'BUF'ORD'ORD'na'na'na'na''0'na'na'na'na'''''''''''Na''na''Na'1990 10 12 5 1755 1733 1858 1820'dl'590'na'63 47'na'38 22'bos''bgr'bgr'bgr'bgr'na'na'na'na'na'na'na'na'''na''na'''''105 114'90'-19 -10'JAX'MIA'334'334'8'7'0'Na'0'na'na''na''na''na'''aa'1947'n3bäa1'6487'47'-28 -5'sfo'lax'lax'337'6'6''11'0'na'0'na'na''na''na''na''

Close theDatabaseDatastoreobject and the database connection.

close(dbds)

Input Arguments

collapse all

Datastore containing data in a database, specified as aDatabaseDatastoreobject created using thedatabaseDatastorefunction.

Output Arguments

collapse all

查询results, returned as a table of the first eight records in the data set. Executing the SQL statement specified in the查询property of theDatabaseDatastoreobject creates the data set.

If there is no data to read from the query,previewthrows an error.

Introduced in R2014b