次の方法で共有


Columns Collection

この機能は、将来のバージョンの Microsoft SQL Server では削除される予定です。新規の開発作業ではこの機能を使用しないようにし、現在この機能を使用しているアプリケーションは修正することを検討してください。

The Columns collection contains Column objects that expose the columns of a Microsoft SQL Server table.

現在のオブジェクトを表す SQL-DMO オブジェクト モデル

Methods

Add Method

Refresh Method

ItemByID Method

Remove Method (Collections)

解説

With the Columns collection, you can:

  • Add a column to a SQL Server table.
  • Remove a column from a SQL Server table.

Columns in SQL Server tables are defined as part of a CREATE TABLE or ALTER TABLE statement.

When creating a SQL Server table using the Table object, an empty Columns collection is created as part of the Table object creation. Adding Column objects to the Columns collection adds column definition text to the CREATE TABLE statement generated when the Table object is added to the Tables collection of a Database object.

If a Table object references an existing SQL Server table, changes to the Columns collection generate ALTER TABLE statements.

For more information about creating columns, see Column Object.

To remove a column from a SQL Server table

  1. Get the desired Table object from the Tables collection of a Database object.

  2. Use the BeginAlter method of the Table object to mark the beginning of changes to the SQL Server table.

  3. Use the Remove method of the Columns collection of a Table object. Indicate the targeted column using the column name or the ordinal location in the collection, as in:

    oTables("Employees").Columns.Remove("Photo")
    
  4. Use the DoAlter method of the Table object to submit the changed table definition to SQL Server.

    ms135184.note(ja-jp,SQL.90).gifメモ :
    Dropping a column from a SQL Server table is bound by dependencies on the column, and can fail.