Column Object
未來的 Microsoft SQL Server 發行版本將不再提供此功能。請避免在新的開發工作中使用此功能,並計劃修改目前使用此功能的應用程式。
The Column object represents the properties of a single column in a Microsoft SQL Server table.
Properties
Methods
|
備註
With the Column object, you can:
- Define columns of a new SQL Server table.
- Define a new column for an existing SQL Server table.
- Drop an existing column from a SQL Server table.
- List the references of a SQL Server column.
The Name property of a Column object uses the SQL Server data type sysname. The Name property must be unique within the names of columns in the SQL Server table.
Column object properties can be set before the Column object is added to the Columns collection of a Table object.
To define columns for a new SQL Server table
Create a Table object.
Set the Name property of the Table object.
Create a Column object.
Set the Name property of the Column object.
Set properties that define the column data type. For example, to specify a column with a char(5) data type, set the Datatype property to char and the Length property to 5.
Set other properties.
Add the Column object to the Columns collection of the Table object.
Repeat Steps from 3 through 7 until all columns are defined.
Add the Table object to the Tables collection of a Database object.
To add a new column to a SQL Server table
Create a Column object.
Set the Name property.
Set properties that define the column data type. For example, to specify a column with a char(5) data type, set the Datatype property to char and the Length property to 5.
Set other properties.
Get the appropriate Table object from the Tables collection of a Database object.
Use the BeginAlter method of the Table object to mark the beginning of changes to the SQL Server table.
Add the Column object to the Columns collection of the Table object.
Use the DoAlter method of the Table object to submit the changed table definition to the instance of SQL Server.
To drop a column from a SQL Server table
Get the appropriate Table object from the Tables collection of a Database object.
Use the BeginAlter method of the Table object to mark the beginning of changes to the SQL Server table.
Get the appropriate Column object from the Columns collection of the Table object.
Use the Remove method of the Column object to drop the column from the SQL Server table.
Use the DoAlter method of the Table object to submit the changed table definition to the instance of SQL Server.
附註: |
---|
The Column object is compatible with instances of SQL Server version 7.0 and later. However, the Column2 object extends the functionality of the Column object for use with features that were added in SQL Server 2000. |