tags:

views:

324

answers:

4

How can I insert a description for a column in an Access table using SQL?

I do:

CREATE TABLE TAB_A (COLUMN1 TEXT(30), COLUMN2 REAL, PRIMARY KEY (COLUMN1)

but how can I insert a description for each column?

A: 
Dim col As ADOX.Column = New ADOX.Column
With col
  .Name = name
  .Type = type
  .DefinedSize = size
  .ParentCatalog = cat
  .Properties("Description").Value = description
End With
Mitch Wheat
+1  A: 

You can't do it in SQL.

KB210314: ACC2000: How to Use ADO or DAO to Retrieve a Field's Description

I reckon that it can be set the same way that it can be retrieved:

Function SetFieldDesc_ADO(ByVal MyTableName As String, ByVal MyFieldName As String, ByVal Description As String)

   Dim MyDB As New ADOX.Catalog
   Dim MyTable As ADOX.Table
   Dim MyField As ADOX.Column

   On Error GoTo Err_SetFieldDescription

   MyDB.ActiveConnection = CurrentProject.Connection
   Set MyTable = MyDB.Tables(MyTableName)
   MyTable.Columns(MyFieldName).Properties("Description").Value = Description

   Set MyDB = Nothing

Bye_SetFieldDescription:
   Exit Function

Err_SetFieldDescription:
   MsgBox Err.Description, vbExclamation
   Resume Bye_SetFieldDescription
End Function
Tomalak
A: 

My question to you: considering you cannot 'query' a table for a column's description using SQL, how do plan to read it? Odds are, the answer to my question will be the same as the answer to your question :)

onedaywhen
A: 

FWIW I can't get the DAO (v3.6) method to work.

(C#) Both .Properties["Caption"] and .Properties["Description"] throw a COMException "Property not found." Examining the Properties collection does, in fact, corroborate this.

(...would have appended this to Tomalak's answer, if only I was authorized to do so.)

Could MS have such blatantly wrong documentation up? Anyone know how to make it work in DAO for real?

Yes-it-has-overflowed
Properties don't exist until they are created, so a field without a caption or description set won't yet have either of those properties. The Access UI shows the properties, but until you assign a value, they don't exist.
David-W-Fenton
Thank you for the clarification. Meanwhile I retooled to use ADO but this is helpful to know for the future!
Yes-it-has-overflowed
Why would you go to the trouble of using ADO when you're looking for something that is specific to Jet/ACE/Access? DAO would be the obvious interface for that.
David-W-Fenton
Maybe the word "retool" left a labor-intensive impression, but it was more like: spend 10 mins. to swap out one technique/method that seemed borked, for something that actually worked. It wasn't "obvious" why these expected, common Properties were not found in the collection! ("Obj.'s Properties don't exist until created" is a new one on me...) This amt. of time that could have easily vanished playing the "let's try to search MSDN" game! ATM it's for a personal use, one-off app, so an "as long as it works" implementation is satisfactory.Hey, I'm here to learn! TY again for the pointer(s)!
Yes-it-has-overflowed