獲得乙個表的所有欄位名

2022-03-10 23:18:36 字數 925 閱讀 4458

場景: 在除錯較為負責的儲存過程, 需要經常select

當表字段較多,但有幾個字段確實不想見到它,

以下就是方便了寫select語句

declare

@query

varchar(max

)declare

@name

varchar(50

)declare vacancy cursor local for

select name --

欄位名from

sys.all_columns

where

object_id=(

select

top1

object_id

from

sys.tables

where name =

'tbla'--

表名)open

vacancy

fetch

next

from vacancy into

@name

set@query

=@name

while

@@fetch_status=0

begin

set@query

=@query+'

,'+@name

--組合起來

fetch

next

from vacancy into

@name

endclose

vacancy

deallocate

vacancy

print

@query

--複製出來, 刪掉不想要的字段就方便多了

view code

例如表有15個字段, 其中有5哥不想看到,

現在不需要手打那麼多字段了

如何取得乙個表的所有欄位名用逗號分割

自從 oracle 9i 開始,就可以通過sys connect by path 函式實現將從父節點到當前 行內容以 path 或者層次元素列表的形式顯示出來。取得乙個表的所有欄位名,用逗號分割。select max substr sys connect by path column name,2 ...

mysql獲取某個表的所有欄位名

mysql安裝成功後可以看到已經存在mysql information schema和test這個幾個資料庫,information schema庫中有乙個名為columns的表,這個表中記錄了資料庫中所有表的字段資訊。知道這個表後,獲取任意表的字段就只需要一條select語句即可。例如 selec...

mysql獲取某個表的所有欄位名

mysql安裝成功後可以看到已經存在mysql information schema和test這個幾個資料庫,information schema庫中有乙個名為columns的表,這個表中記錄了資料庫中所有表的字段資訊。知道這個表後,獲取任意表的字段就只需要一條select語句即可。例如 selec...