如何获取表中字段使用的最大大小 [英] how to get the max size used by a field in table
本文介绍了如何获取表中字段使用的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个已设置为最大大小的字段.我如何找到该字段占用的最大大小.
I have a field which has been set to max size. How can i find the max size occupied by the field.
例如,如果记录是表 TableA
For example if the records are for table TableA
FieldA
123
abcd
1234567
我需要知道哪一行占用的大小最多,大小是多少
I need to know which row occupied the most size and what the size is
谢谢
普拉迪
推荐答案
LEN 测试以字符为单位的长度,例如"a" = 1 个字符
LEN tests for the length in characters, e.g. "a" = 1 char
select max(len(fieldA)) from tbl
DATALENGTH 以字节为单位检查大小,一个 NVarchar 每个字符占用 2 个字节>
DATALENGTH checks for the size in bytes, an NVarchar occupies 2 bytes per character
select max(datalength(fieldA)) from tbl
获取表中FieldA中数据长度最大的所有行,
To get all the rows in the table that have the maximum length of data in FieldA,
select *
from tbl join (select MAX(LEN(fieldA)) maxlen from tbl) l
on l.maxlen = LEN(tbl.fieldA)
这篇关于如何获取表中字段使用的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文