且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL SERVER 2005 中基于函数的索引

更新时间:2023-02-07 09:40:34

你需要添加一个计算列

Alter Table BEER_HERE Add Column XBEER_DATE As dbo.TRUNCATE_DATE(BEER_DATE)

然后,您可以按照预期对其进行索引.

You can then index it as you'd expect.

但是,您的函数需要具有确定性和精确性,如 http://msdn.microsoft.com/en-us/library/ms189292(v=sql.90).aspx.您的函数应该满足这些要求,但您可能需要在函数定义中添加 With SchemaBinding.

However, your function needs to be deterministic and precise as defined in http://msdn.microsoft.com/en-us/library/ms189292(v=sql.90).aspx. Your function should meet these requirements, but you might need to add With SchemaBinding to the function definition.

您也许还可以使用视图

Create View V_BEER_HERE As Select BEER_CODE, BEER_DATE, dbo.TRUNCATE_DATE(BEER_DATE) As XBEER_DATE From BEER_HERE
Create Unique Clustered Index PK_V_BEER_HERE On V_BEER_HERE (BEER_CODE)
Create Index I_XBEER_DATE On V_BEER_HERE (XBEER_DATE)

插入到表中的东西,从视图中读取的东西.这取决于 BEER_CODE 作为主键.

Stuff that inserts writes to the table, stuff that reads reads from the view. This depends on BEER_CODE being a primary key.

SQL Server 不像 Oracle 那样具有基于函数的索引.

SQL Server doesn't have function based indexes the same way Oracle does.