加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver获取某一张表中的所有列中的最大长度

发布时间:2020-12-12 15:00:26 所属栏目:MsSql教程 来源:网络整理
导读:比如 在我们导入sqlserver数据到oracle时? 时常碰到列超出长度的问题 很是烦劳,报错是又不说明是那一列 所以我们只有自己去查 一列列的写sql语句麻烦死了 如下可以查询一张表中所有列的最大长度 ? go declare @lengh int; declare @i int; declare @tableNam

比如 在我们导入sqlserver数据到oracle时? 时常碰到列超出长度的问题 很是烦劳,报错是又不说明是那一列 所以我们只有自己去查

一列列的写sql语句麻烦死了 如下可以查询一张表中所有列的最大长度

?

go
declare @lengh int;
declare @i int;
declare @tableName varchar(20);
DECLARE @SQLString NVARCHAR(500)


declare?? @a?? table?? (a?? int,b?? varchar(100)) ;
set @tableName='B2B_CONSTRACT';
set @lengh=(select count(*) from syscolumns where object_name(id)=@tableName);
insert into @a select? ROW_NUMBER() OVER (ORDER BY name),name from syscolumns where object_name(id)=@tableName;
set @i=1;
while @i<=@lengh
begin
?? SET @SQLString = N'select max(len('+(select b from @a where a=@i)+')) as '+(select b from @a where a=@i)+' from '+@tableName;?? exec (@SQLString); ?? set @i=@i+1;end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读