Connect to a Microsoft® SQL Server® database and verify the database connection. Then, import data from the database into MATLAB®. Determine the highest unit cost among the retrieved products in the table. Close the database connection.
Create an ODBC database connection to a Microsoft® SQL Server® database with Windows® authentication. Specify a blank user name and password. The database contains the table productTable.
datasource = 'MS SQL Server Auth';
conn = database(datasource,'','');
Check the database connection. If the Message property is empty, the connection is successful.
conn.Message
ans =
[]
Determine if the database connection is open. The isopen function returns the numeric scalar 1, which means the database connection is open.
i = isopen(conn)
i =
1
Select all the data from productTable and sort it by the product number. data is a table containing the imported data that results from executing the SQL SELECT statement.
selectquery = 'SELECT * FROM productTable ORDER BY productNumber';
data = select(conn,selectquery);
Determine if the database connection is closed. The isopen function returns the numeric scalar 0, which means the database connection is closed. If the database connection is invalid, the isopen function returns the same result.
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window.
Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.