SQL exclude a column using SELECT * [except columnA] FROM tableA?

后端 未结 30 2598
花落未央
花落未央 2020-11-21 23:15

We all know that to select all columns from a table, we can use

SELECT * FROM tableA

Is there a way to exclude column(s) from a table witho

30条回答
  •  故里飘歌
    2020-11-22 00:07

    Sometimes the same program must handle different database stuctures. So I could not use a column list in the program to avoid errors in select statements.

    * gives me all the optional fields. I check if the fields exist in the data table before use. This is my reason for using * in select.

    This is how I handle excluded fields:

    Dim da As New SqlDataAdapter("select * from table", cn)
    da.FillSchema(dt, SchemaType.Source)
    Dim fieldlist As String = ""
    For Each DC As DataColumn In DT.Columns
       If DC.ColumnName.ToLower <> excludefield Then
        fieldlist = fieldlist &  DC.Columnname & ","
       End If
      Next
    

提交回复
热议问题