[英]nvarchar or varchar or date in joins of SQL Server
I have a management project developed in Web using SQL Server 2008 R2 and Windows Application using SQL Server CE 4.0. 我有一个使用SQL Server 2008 R2在Web上开发的管理项目和使用SQL Server CE 4.0的Windows应用程序。
Both uses almost same database structure. 两者使用几乎相同的数据库结构 I have a fees table as :
我有一张费用表:
TABLE [fees]
(
[feeid] bigint NOT NULL IDENTITY(1,1),
[acno] int NULL DEFAULT 0,
[billingmonth] nvarchar(10) NULL,
[oldbal] numeric(18,2) NULL DEFAULT 0,
[duedtamt] numeric(18,2) NULL DEFAULT 0,
[afterdtamt] numeric(18,2) NULL DEFAULT 0,
[bal] numeric(18,2) NULL DEFAULT 0,
[depamt] numeric(18,2) NULL DEFAULT 0,
[totdpo] numeric(18,2) NULL DEFAULT 0,
[depdt] datetime NULL
)
billingmonth
will always use format MMM-yyyy
eg. billingmonth
将始终使用格式MMM-yyyy
例如。 Jan-2018 扬2018
BillingMonth
uses various joins (inner and left outer join) in other tables. BillingMonth
在其他表中使用各种连接(内部和左外部连接)。
How to increase performance of joins with BillingMonth
? 如何使用
BillingMonth
提高连接性能? , should i : , 我是不是该 :
Storing date values as nvarchar is not recommended at all 根本不建议将日期值存储为nvarchar
There are many suggestions to increase the join performance: 有许多建议可以提高连接性能:
Date
datatype Date
数据类型 tinyint
for month, smallint
for year, they can be used only for joining purpose ) tinyint
表示月份, smallint
表示年份,它们只能用于连接目的 ) Note that: AS @Pரதீப் mentioned, When you store month and year separately, you need to do some integer manipulations when searching for date ranges 需要注意的是:AS @Pரதீப்提到,当你分别存储月份和年份时,你需要在搜索日期范围时进行一些整数操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.