• <small id='Uo2Yr'></small><noframes id='Uo2Yr'>

    <i id='Uo2Yr'><tr id='Uo2Yr'><dt id='Uo2Yr'><q id='Uo2Yr'><span id='Uo2Yr'><b id='Uo2Yr'><form id='Uo2Yr'><ins id='Uo2Yr'></ins><ul id='Uo2Yr'></ul><sub id='Uo2Yr'></sub></form><legend id='Uo2Yr'></legend><bdo id='Uo2Yr'><pre id='Uo2Yr'><center id='Uo2Yr'></center></pre></bdo></b><th id='Uo2Yr'></th></span></q></dt></tr></i><div id='Uo2Yr'><tfoot id='Uo2Yr'></tfoot><dl id='Uo2Yr'><fieldset id='Uo2Yr'></fieldset></dl></div>
  • <tfoot id='Uo2Yr'></tfoot>

  • <legend id='Uo2Yr'><style id='Uo2Yr'><dir id='Uo2Yr'><q id='Uo2Yr'></q></dir></style></legend>

        <bdo id='Uo2Yr'></bdo><ul id='Uo2Yr'></ul>

        我应该使用 SQL_Variant 数据类型吗?

        Should I use SQL_Variant data type?(我应该使用 SQL_Variant 数据类型吗?)
          <bdo id='oPkdV'></bdo><ul id='oPkdV'></ul>

          <small id='oPkdV'></small><noframes id='oPkdV'>

            • <i id='oPkdV'><tr id='oPkdV'><dt id='oPkdV'><q id='oPkdV'><span id='oPkdV'><b id='oPkdV'><form id='oPkdV'><ins id='oPkdV'></ins><ul id='oPkdV'></ul><sub id='oPkdV'></sub></form><legend id='oPkdV'></legend><bdo id='oPkdV'><pre id='oPkdV'><center id='oPkdV'></center></pre></bdo></b><th id='oPkdV'></th></span></q></dt></tr></i><div id='oPkdV'><tfoot id='oPkdV'></tfoot><dl id='oPkdV'><fieldset id='oPkdV'></fieldset></dl></div>

              <tfoot id='oPkdV'></tfoot>
                  <tbody id='oPkdV'></tbody>

                1. <legend id='oPkdV'><style id='oPkdV'><dir id='oPkdV'><q id='oPkdV'></q></dir></style></legend>
                  本文介绍了我应该使用 SQL_Variant 数据类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 SQL Server 2005 和 SP4,我正在设计一个数据库表.

                  using SQL Server 2005 with SP4 and I am designing a database table.

                  这是表DDL

                  CREATE TABLE CPSync4D.ProjectProfilerOption
                  (
                      ProjectProfilerOptionID     INT  IDENTITY(1,1) CONSTRAINT PK_ProjectProfilerOption_ProjectProfilerOptionID PRIMARY KEY 
                     ,ProjectID                   INT  CONSTRAINT FK_ProjectProfilerOption_Project_ProjectID FOREIGN KEY(ProjectID) REFERENCES CPSync4D.Project(ProjectID) ON DELETE CASCADE
                     ,ProfilerOptionID            TINYINT CONSTRAINT FK_ProjectProfilerOption_ProfilerOption_ProfilerOptionID  FOREIGN KEY(ProfilerOptionID) REFERENCES CPSync4D.ProfilerOption (ProfilerOptionID) 
                     ,ProfilerOptionValue         sql_variant  NOT NULL   
                  
                  )
                  Go
                  

                  profileroptionvalue 列可以包含最多 30 个字符的字符串、整数或十进制值,例如值为ProfilerValueType",或 12.52 或 20 等(不超过两位小数且整数值小于 100)

                  profileroptionvalue column can hold either a string upto 30 characters, integer or decimal values e.g. values are "ProfilerValueType", or 12.52 or 20 etc. (no more than than two decimals and integer values are less than 100)

                  我应该使用 sql_variant 还是 varchar(30)...?我之前从未使用过 sql_variant 并且不确定不使用在数据库设计方面的任何含义.

                  Should I use sql_variant or varchar(30)...? I never used sql_variant before and not sure any implication of not using in terms of database design.

                  在 .net 代码中使用 sql_variant 的任何陷阱

                  Any pitfalls of using sql_variant...with .net code

                  推荐答案

                  显式转换 SQL Server 数据类型的 10 个理由

                  作为一般规则,您应该避免使用 SQL Server 的 sql_variant数据类型.除了内存占用之外,sql_variant 也是有限的:

                  As a general rule, you should avoid using SQL Server’s sql_variant data type. Besides being a memory hog, sql_variant is limited:

                  • 变体不能是主键或外键的一部分.(这在 SQL Server 2005 中不成立.请参阅下面的更新)
                  • 变体不能是计算列的一部分.
                  • 变体不能与 WHERE 子句中的 LIKE 一起使用.
                  • OLE DB 和 ODBC 提供程序会自动将变体转换为 nvarchar(4000) — 哎哟!

                  为避免出现问题,始终将 sql_variant 数据类型显式转换为你使用它们.使用任何你喜欢的方法,只是不要尝试使用未转换的 sql_variant 数据类型.

                  To avoid problems, always explicitly convert sql_variant data types as you use them. Use any method you please, just don’t try to work with an unconverted sql_variant data type.

                  我之前没有使用过 sql_variant,但考虑到这些限制和性能影响,我会首先考虑替代方案.

                  I haven't used sql_variant before but with these restrictions and performance implications in mind, I would first look at alternatives.

                  以下是我最喜欢到最不喜欢的解决方案

                  Following would be my most to least prefered solution

                  • 只需创建三个不同的列.3 不同的数据类型(应该)意味着在客户端和服务器端都有 3 种不同的解释方式.
                  • 如果这不是一个选项,请使用 VARCHAR 列,这样您至少可以使用 LIKE 语句.
                  • 使用 sql_variant 数据类型.
                  • Simply create three different columns. 3 Different data types (should) mean 3 different ways of interpreting it both at the client side and server side.
                  • If that is not an option, use a VARCHAR column so you can at least use LIKE statements.
                  • Use the sql_variant data type.

                  编辑 Cudo's to ta.speot.is

                  变体可以 成为外键主键的一部分

                  Variants can be part of a primary of foreign key

                  唯一键、主键或外键可能包含类型为sql_variant,但构成数据值的总长度特定行的键不应超过一个的最大长度指数.这是 900 字节

                  A unique, primary, or foreign key may include columns of type sql_variant, but the total length of the data values that make up the key of a specific row should not be more than the maximum length of an index. This is 900 bytes

                  这篇关于我应该使用 SQL_Variant 数据类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                    <i id='znufJ'><tr id='znufJ'><dt id='znufJ'><q id='znufJ'><span id='znufJ'><b id='znufJ'><form id='znufJ'><ins id='znufJ'></ins><ul id='znufJ'></ul><sub id='znufJ'></sub></form><legend id='znufJ'></legend><bdo id='znufJ'><pre id='znufJ'><center id='znufJ'></center></pre></bdo></b><th id='znufJ'></th></span></q></dt></tr></i><div id='znufJ'><tfoot id='znufJ'></tfoot><dl id='znufJ'><fieldset id='znufJ'></fieldset></dl></div>
                      <legend id='znufJ'><style id='znufJ'><dir id='znufJ'><q id='znufJ'></q></dir></style></legend>
                        • <small id='znufJ'></small><noframes id='znufJ'>

                            <tbody id='znufJ'></tbody>

                        • <tfoot id='znufJ'></tfoot>
                          • <bdo id='znufJ'></bdo><ul id='znufJ'></ul>