根據表名和模板GGUID,得到表字段 及清單資訊

2021-06-08 10:21:10 字數 1624 閱讀 3581

if object_id('sp_gettablecolinfo','p') is not null drop proc sp_gettablecolinfo  

go

create proc sp_gettablecolinfo

@tablename varchar(128),

@gguid uniqueidentifier

as

begin

with cte as

( select

--欄位名稱描述

b.desc0 as coldesc,

--欄位名稱

a.name as colname,

--獲取字段型別

case a.xusertype

when '167' then 'varchar('+ltrim(a.length)+')'

when '61' then 'datetime'

when '36' then 'uniqueidentifier'

when '56' then 'int'

when '108' then 'numeric(38,2)'

when '34' then 'image'

else ltrim(a.xusertype) end as [coltype],

--獲取清單資訊

listdetails=

( select cid+':'+char(9)+desc0+char(10)

from smlstd

where ltrim(lhguid)=ltrim(b.ctrlid)

order by cid

for xml path('')

),

--獲取是否允許為空

case b.pnull when 1 then '√'

when 0 then ''

else ltrim(b.pnull) end as [null],

--排序字段

b.zorder

from syscolumns a

left join smtmpd b on a.name=b.did

where

a.id=object_id(@tablename)

and b.gguid=@gguid

) select

coldesc,

colname,

coltype,

[null],

'', --預留

'', --預留

isnull(listdetails,'')

from cte

order by zorder

end

go

sp_gettablecolinfo

'csempl_1',

'1e3411fa-7c0a-4034-b998-42362cb1d695'

根據字段內容查詢表名

儲存指定資料庫中的表名 create table t id int identity 1,1 t name varchar 100 null,rc int null 儲存指定表的所有列名 create table t c id int identity 1,1 t c varchar 100 nul...

Oracle根據字段值找到表名和列名

方法1 oracle 根據字段值查詢其所在的表 字段 declare cursor cur query is select table name,column name,data type from user tab columns a number sql hard varchar2 2000 v...

根據表名獲取表字段資訊

實際應用中不免需要調取資料庫表字段的相關資訊,特此將 貼出,以作備用,調取的資訊 欄位名 字段型別 字段長度 是否主鍵 說明 建立sqlparameter public class cp public sqldbtype coltype public int collength public boo...