English 中文(简体)
服务器2008年R2中指数化观点的缩略语
原标题:Understanding column type in indexed view in SQL Server 2008 R2

我们通过这种q子形成了一个指数化的观点:

Select Table1_ID, Count_BIG(*) as Table2TotalCount from Table2 inner join
Table1 inner join... where...

Also after creating the view, we set clustered unique index on column Table1_ID.
So View consists of two columns:

Table1_ID
Table2TotalCount

我们有两个问题:

  1. If we use Count(1) or Count_BIG(1) instead of Count_BIG(*), SQL doesn t allow us to set index on Table1_ID
  2. How can we control the type of second column (Table2TotalCount) - SQL give a long nullable type to this column. But we want to set int not nullable type to this column. After creating View, we can t find any way to change column type. Also t-sql we use for creating view, always return int values to Table2TotalCount.
最佳回答

你必须使用COUNT_BIG(*)。 The s one of the restrictions on creating an indexed view:

公平与和解委员会的声明不能包含以下内容:

  • COUNT (COUNT_BIG(*) is allowed.)

您可以提出第二种观点,即,这种先见的参考,并将计算栏的数据类型输入到您所希望的类别(并可能利用国际不动产公司防止不可撤销的财产)。

问题回答
  1. 这可能是因为你以表达而不是实地或<代码>表示。 使用<代码>count(1)得出的结果与count(*)相同,即计算记录号,因此没有理由使用count(1)

  2. 使用<条码><> 代码>而不是<条码>,参引条目_big而不是<条码>。 (文件特别指出,两者的唯一区别是返回类型。) 我不知道为什么这些价值作为<代码>count无效。 回返永远不会失去效力,但对所有合计数而言,这可能相同,而且可能无法控制。





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签