> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# dbListColumns

> 列出資料庫伺服器上表或檢視中的列。

export const siteNameShort = "知行之橋";

列出資料庫伺服器上的表或檢視中的列。根據配置和目標資料庫型別，其中一些參數和輸出屬性可能不相關。

## 必需的參數

* **driver**：跨平臺版本中的 JDBC 驅動程式類名稱，或 .NET 版本中的 ADO.NET 提供程式名稱。
* **conn**：連接字串或資料庫 URL。
* **table**：從中列出列的表或檢視。

## 可選的參數

* **schema**：表所在的資料庫 Schema 名稱。該 Schema 通常稱為一組表的 *命名空間*。
* **catalog**：資料庫伺服器中的 Catalog。這通常稱為 *資料庫*。如果不提供值，則傳回資料庫伺服器中所有 Catalog 的列。

## 輸出屬性

* **db:columnname**：指定表或檢視中的列名稱。
* **db:datatype**：指定表或檢視中列的 SQL 資料型別。
* **db:columnsize**：指定表或檢視中列的大小。
* **db:iskey**：布林值（true 或 false），指示該列是否為主索引鍵列。
* **db:nullable**：布林值（true 或 false），指示該列是否可為 null。
* **db:readonly**：布林值（true 或 false），指示該列是否為只讀。
* **db:autoincrement**：布林值（true 或 false），指示該列是否為自動增量列。

## 範例

在此範例中，目標資料庫伺服器是 MySQL，目標表是 `actor`。請注意，連接字串中沒有 `database` 參數：如果在連接字串中指定了資料庫，則不需要 `catalog` 參數。此指令碼將目標表的所有屬性寫入輸出檔案。

```xml theme={null}
<!-- Initializing the output item -->
<arc:set attr="output.data" />
<!-- Creating the input db item and the necessary attributes -->
<arc:set attr="db.driver" value="cdata.jdbc.mysql.MySQLDriver" />
<arc:set attr="db.catalog" value="sakila" />
<arc:set attr="db.table" value="actor" />
<arc:set attr="db.conn" value="jdbc:cdata:mysql:server=localhost;port=3306;user=root;password=Password123;"/>

<arc:call op="dbListColumns" in="db" out="results" >
  <!-- adding result data from the operation to an output item that will be pushed out as a file -->
  <arc:set attr="output.data">[output.data]\nColumn Name=[results.db:columnname]\nData Type=[results.db:datatype]\nSize=[results.db:columnsize]\nKey=[results.db:iskey]\nNullable=[results.db:nullable]\nReadOnly=[results.db:readonly]\nAutoInc=[results.db:autoincrement]\n-----</arc:set>
</arc:call>

<!-- setting the filename and pushing the file out --> 
<arc:set attr="output.filename" value="results.txt" />
<arc:push item="output" />
```

輸出：

```
Column Name=actor_id
Data Type=SMALLINT UNSIGNED
Size=2
Key=True
Nullable=False
ReadOnly=False
AutoInc=True
-----
Column Name=first_name
Data Type=VARCHAR
Size=45
Key=False
Nullable=False
ReadOnly=False
AutoInc=False
-----
Column Name=last_name
Data Type=VARCHAR
Size=45
Key=False
Nullable=False
ReadOnly=False
AutoInc=False
-----
Column Name=last_update
Data Type=TIMESTAMP
Size=19
Key=False
Nullable=False
ReadOnly=False
AutoInc=False
-----
```

只要在安裝並執行 {siteNameShort} 的計算機上安裝了驅動程式，就可以修改上面的範例以定位其他資料庫。針對 .NET 調整此範例時，需要按如下方式更改 `driver` 和 `conn` 輸入：

```xml theme={null}
<arc:set attr="db.driver" value="System.Data.CData.MySql" /> 
<arc:set attr="db.conn" value="Server=localhost;Database=sakila;UID=root;Password=Password123;"/>
```
