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

后端 未结 30 2550
花落未央
花落未央 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:09

    That what I use often for this case:

    declare @colnames varchar(max)=''
    
    select @colnames=@colnames+','+name from syscolumns where object_id(tablename)=id and name not in (column3,column4)
    
    SET @colnames=RIGHT(@colnames,LEN(@colnames)-1)
    

    @colnames looks like column1,column2,column5

提交回复
热议问题