楼主:
我前面提供的方法是经过验证的,难道您没有测试?
其次,我后来查询的一些技术资料,象楼主这个问题,完全可以使用sql server自身提供的SQL-DMO组件来解决。详细说明您可以参考sql server在线帮助,以下是它提供的一些代码:
Altering a Table by Adding a Column
These examples illustrate adding columns to an existing Microsoft® SQL Server™ table.
Examples
A. Adding a Column Defined on a Base Data Type
The example illustrates creating a column that does not allow NULL. The provided default value is used to populate existing rows in the table.
Dim tableProducts As SQLDMO.Table
' Create a Column object, then populate it to define a column
' called ShelfLife.
Dim colShelfLife As New SQLDMO.Column
colShelfLife.Name = "ShelfLife"
colShelfLife.Datatype = "smallint"
colShelfLife.AllowNulls = False
colShelfLife.DRIDefault.Text = "31"
' Get the Products table. Note: Create and connect of SQLServer
' object used is not illustrated in this example.
Set tableProducts = _
oSQLServer.Databases("Northwind"
.Tables("Products"
' Mark start of change unit.
tableProducts.BeginAlter
' Add the populated Column object to its containing collection.
tableProducts.Columns.Add colShelfLife
' Create the column by committing the unit of change.
tableProducts.DoAlter
B. Adding a Computed Column
This example illustrates altering a table, adding a column that perform simple multiplication of the values in two other columns.
Dim tableProducts As SQLDMO.Table
' Create a Column object and populate it to define a new column
' called StockValue.
Dim colStockValue As New SQLDMO.Column
colStockValue.Name = "StockValue"
colStockValue.IsComputed = True
colStockValue.Datatype = "money"
colStockValue.ComputedText = "UnitsInStock * UnitPrice"
' Get the Products table. Note: Create and connect of SQLServer
' object used is not illustrated in this example.
Set tableProducts = _
oSQLServer.Databases("Northwind"
.Tables("Products"
' Mark start of change unit.
tableProducts.BeginAlter
' Add the populated Column object to its containing collection.
tableProducts.Columns.Add colStockValue
' Create the column by committing the unit of change.
tableProducts.DoAlter