找到SQL Server的数据类型为nvarchar可变长度从C#code [英] find variable length for sql server datatype nvarchar from c# code

查看:125
本文介绍了找到SQL Server的数据类型为nvarchar可变长度从C#code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以找到允许在SQL Server 2008为nvarchar的类型变量长度从C#code在asp.net应用程序?

Can I find allowed variable length for nvarchar type in sql server 2008 from c# code in asp.net application?

有关例如:

为nvarchar(?)

nvarchar(?)

我想找到的最大允许数量的?从C#code。

I want to find the maximum allowed number for "?" from c# code.

推荐答案

您可以使用此T-SQL查询来查看系统目录视图:

You can use this T-SQL query to look at the system catalog views:

SELECT 
    [max_length]
FROM sys.columns 
WHERE [object_id] = OBJECT_ID('YourTableNameHere')
AND name = 'YourColumnNameHere'

这将返回存储定义的最大长度(以字符)的列

This will return the stored, defined maximum length (in characters) for your column

更新:如果您想找出一个键入(不是你的任何表列)的最大长度,你可以使用这个查询,而不是:

Update: if you want to find out the max length of a type (not a column of any of your tables), you can use this query instead:

SELECT 
    name, max_length
FROM sys.types 
WHERE name IN ('varchar', 'nvarchar')

请注意:返回以字节为单位的最大长度 等你拿8000两种类型(而不是在字符!)。对于 VARCHAR ,8000字节等于8000个字符,而为nvarchar ,8000字节相当于4000个字符。

Be aware: this returns the max length in bytes (not in characters!) so you get 8000 for both types. For varchar, 8000 bytes is equal to 8000 characters, while for nvarchar, 8000 bytes corresponds to 4000 characters.

这篇关于找到SQL Server的数据类型为nvarchar可变长度从C#code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆