SELECT t.name Tname,p.name Pname,c.name Cname FROM sys.objects T INNER JOIN sys.objects P
ON t.object_id=p.parent_object_id AND t.type='U' AND p.type='PK'
INNER JOIN sys.SysColumns C ON c.id=t.object_id
INNER JOIN sysindexes i ON i.name=p.name
INNER JOIN sysindexkeys k ON k.id=c.id AND k.colid=c.colid AND k.indid=i.indid
select
a.name as FieldName, -- 字段名
a.isnullable, -- 是否可为空
--b.Value as FieldDesc, -- 字段说明
c.name as FieldType, -- 数据类型
COLUMNPROPERTY(a.id,a.name,'IsIdentity') as isidentity, --是否标识列
PK=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
SELECT name FROM sysindexes WHERE indid in(
SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
))) then 'true' else 'false' end --是否主键
from SysColumns a left JOIN
systypes c on a.xusertype=c.xusertype
where a.id=Object_Id('BSalesAccountMapping')
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步