SQL Server 中的 SYSNAME 数据类型是什么? [英] What is SYSNAME data type in SQL Server?

查看:41
本文介绍了SQL Server 中的 SYSNAME 数据类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是 SQL Server SYSNAME 数据类型?BOL 说:

What is the SQL Server SYSNAME data type for? BOL says:

sysname 数据类型用于表列、变量和存储存储对象的过程参数名字.

The sysname data type is used for table columns, variables, and stored procedure parameters that store object names.

但我真的不明白.您可以提供用例吗?

but I don't really get that. Is there a use-case you can provide?

推荐答案

sysname 是一种内置数据类型,限制为 128 个 Unicode 字符,IIRC 主要用于在创建脚本时存储对象名称.它的值不能是 NULL

sysname is a built in datatype limited to 128 Unicode characters that, IIRC, is used primarily to store object names when creating scripts. Its value cannot be NULL

与使用 nvarchar(128) NOT NULL

编辑

正如@Jim 在评论中提到的,老实说,我不认为真的存在您会使用 sysname 的商业案例.主要用于微软在SQL Server内部构建sys表和存储过程等.

As mentioned by @Jim in the comments, I don't think there is really a business case where you would use sysname to be honest. It is mainly used by Microsoft when building the internal sys tables and stored procedures etc within SQL Server.

例如,通过执行 Exec sp_help 'sys.tables' 你会看到列 name 被定义为 sysname 这是因为this 的值实际上是一个对象本身(一个表)

For example, by executing Exec sp_help 'sys.tables' you will see that the column name is defined as sysname this is because the value of this is actually an object in itself (a table)

我不会太担心.

还值得注意的是,对于那些仍在使用 SQL Server 6.5 及更低版本的人(还有人在使用它吗?)sysname 的内置类型相当于 varchar(30)

It's also worth noting that for those people still using SQL Server 6.5 and lower (are there still people using it?) the built in type of sysname is the equivalent of varchar(30)

文档

sysname 是使用 ncharnvarchar,在备注部分:

sysname is defined with the documentation for nchar and nvarchar, in the remarks section:

sysname 是系统提供的用户定义数据类型,在功能上与 nvarchar(128) 等效,只是它不可为空.sysname 用于引用数据库对象名称.

sysname is a system-supplied user-defined data type that is functionally equivalent to nvarchar(128), except that it is not nullable. sysname is used to reference database object names.

为了澄清上述说明,默认 sysname 被定义为 NOT NULL 当然可以将其定义为可空.同样重要的是要注意,确切的定义可能因 SQL Server 实例而异.

To clarify the above remarks, by default sysname is defined as NOT NULL it is certainly possible to define it as nullable. It is also important to note that the exact definition can vary between instances of SQL Server.

使用特殊数据类型

sysname 数据类型用于表列、变量和存储存储对象名称的过程参数.的准确定义sysname 与标识符规则有关.因此,它可以因 SQL Server 实例而异.sysname 在功能上是相同的与 nvarchar(128) 相同,但默认情况下,sysname 不是 NULL.在早期版本的 SQL Server,sysname 被定义为 varchar(30).

The sysname data type is used for table columns, variables, and stored procedure parameters that store object names. The exact definition of sysname is related to the rules for identifiers. Therefore, it can vary between instances of SQL Server. sysname is functionally the same as nvarchar(128) except that, by default, sysname is NOT NULL. In earlier versions of SQL Server, sysname is defined as varchar(30).

有关 sysname 允许或禁止 NULL 值的更多信息可以在此处找到 https://stackoverflow.com/a/52290792/300863

Some further information about sysname allowing or disallowing NULL values can be found here https://stackoverflow.com/a/52290792/300863

仅仅因为它是默认值(非空)并不能保证它会是!

Just because it is the default (to be NOT NULL) does not guarantee that it will be!

这篇关于SQL Server 中的 SYSNAME 数据类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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