使用 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_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
VARCHAR
列,这样您至少可以使用 LIKE
语句.sql_variant
数据类型.VARCHAR
column so you can at least use LIKE
statements.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 数据类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!