Removing a Column from a SQL Server Table

 

System_CAPS_ICON_warning.jpg Warning

SQL Server Native Client (SNAC) is not supported beyond SQL Server 2012. Avoid using SNAC in new development work, and plan to modify applications that currently use it. The Microsoft ODBC Driver for SQL Server provides native connectivity from Windows to Microsoft SQL Server and Microsoft Azure SQL Database.

The SQL Server Native Client OLE DB provider exposes the ITableDefinition::DropColumn function. This allows consumers to remove a column from a SQL Server table.

Consumers specify the table name as a Unicode character string in the pwszNamemember of the uName union in the pTableID parameter. The eKindmember of pTableID must be DBKIND_NAME.

The consumer indicates a column name in the pwszNamemember of the uName union in the pColumnID parameter. The column name is a Unicode character string. The eKind member of pColumnID must be DBKIND_NAME.

Code

DBID TableID;  
DBID ColumnID;  
HRESULT hr;  
  
TableID.eKind = DBKIND_NAME;  
TableID.uName.pwszName = L"MyTableName";  
  
ColumnID.eKind = DBKIND_NAME;  
ColumnID.uName.pwszName = L"MyColumnName";  
  
hr = m_pITableDefinition->DropColumn(&TableID, &ColumnID);  

Tables and Indexes

Community Additions

ADD
Show: