How do I select from a table within a specific schema?

25 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2020 年 9 月 15 日
回答済み: MathWorks Support Team 2021 年 2 月 1 日
I would like to query a table in a database under a specific schema. In Database Explorer, I can select the schema in the Data Browser panel. How do I do this programmatically?

採用された回答

MathWorks Support Team
MathWorks Support Team 2020 年 9 月 15 日
This would depend on which command you are using to query the database:
If you are using 'sqlread', you can specify it as a argument:
tablename = 'productTable';
data = sqlread(conn,tablename,'Schema','dbo');
If you are using 'fetch' or 'select', then in your SQL statement, you specify the schema with the table name:
results = fetch(conn, 'SELECT * FROM schemaName.inventoryTable');
You can find more information regarding the SQL statement syntax in the documentation for your database. For SQL Server, we see this syntax explained here:

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by