Questions tagged [indexed-view]

The tag has no usage guidance.

indexed-view
Filter by
Sorted by
Tagged with
0 votes
0 answers
53 views

Can an indexed view on SQL Server be updated asynchronously?

Can I create an indexed view on SQL Server that be updated asynchronously from physical table, so that the INSERT/DELETE performance will not be affected much?
xon.ha's user avatar
  • 1
0 votes
1 answer
86 views

How to simulate LEFT JOIN as INNER JOIN in SQL Server while creating indexed view

It is possible to simulate left join using inner join while creating indexed view in SQL Server? I found a solution using ISNULL(id,0) but it does not work for me. I have Table1 (ID PK, ID_U FK null) ...
blane's user avatar
  • 317
0 votes
0 answers
38 views

Why table scan on a Indexed View? [duplicate]

I created a table by copying 19972 rows (ID,FirstName,LastName) from Adventureworks.person.person table. On this table I created a non-clustered index on Firstname Column. Using this table I created ...
Alok Bajaj's user avatar
0 votes
1 answer
60 views

Index on view with 3 joined table is not working

I have Microsoft SQL Server 2019. I want to create a view that includes 3 tables, then create an index on it to use it in query. When I do this on 2 tables, all works fine, but with 3 tables in the ...
Денис Дудко's user avatar
1 vote
2 answers
93 views

Index of view isn't used on SQL Server

I want to speed up the access to a view and have put an index over it. Unfortunately this is not used, although it seems logical and obvious to me that this should be used. Can someone tell me what I ...
André Reichelt's user avatar
1 vote
2 answers
288 views

What can cause index corruption in SQL Server indexed view

I have a view with a clustered index on it. sometimes, when I update Order table (using EF Core that uses transaction) UPDATE dbo.Order SET OrderStatus = @orderStatus INSERT INTO dbo.History VALUES (.....
Liero's user avatar
  • 26.2k
2 votes
1 answer
562 views

Using SQL Server Indexed View in combination with OPENJSON

I have a table with just one row and one column which stores a JSON array with about 30MB/16k objects in it: CREATE TABLE [dbo].[CitiesTable] ( [CitiesJson] [NVARCHAR](MAX) NOT NULL ) ON [PRIMARY]...
Jan Köhler's user avatar
  • 5,961
1 vote
1 answer
339 views

How to drop and recreate indexed view without hardcoding the CREATE VIEW definitition

I have couple of indexed views (with schema binding and index) in my database. I want to alter some some columns used by the view, but I get: The object 'MyIndexedView' is dependent on the column '...
Liero's user avatar
  • 26.2k
0 votes
2 answers
104 views

How do I Index this View Properly?

I have a table similar to this: CREATE TABLE dbo.SomeTable (Work_ID VARCHAR(9)); I need to be able to run the following query and unfortunately can not change the data type of the Work_ID column: ...
TheSQLGuy's user avatar
0 votes
0 answers
128 views

Indexed view on hierarchical data

I have some tree-like data that is implemented using hierarchyid. Some nodes in that tree can be "locked" and when that happens, all the subnodes of the locked nodes become locked too. ...
torvin's user avatar
  • 6,803
0 votes
1 answer
63 views

Greatest value in group solution that also meets requirements for indexed view

In an Azure SQL database, I have an EAV-style table AttributeValues that stores multiple attribute values, like this: Id Organization_Id Attribute_Id Value 1 1 1 Old Org 1 Description 2 1 1 New Org ...
coryseaman's user avatar
-1 votes
2 answers
117 views

Is there a way to find out which records have changed in an indexed view?

I have a table (invoice details) which has two columns (productid and quantity). I created an indexed view on this table in order to know the balance of products. When a user enters an invoice on a ...
Attaf's user avatar
  • 1
0 votes
0 answers
330 views

SQL Server: Materialized view based on stored proc with dynamic sql - how to

My client wants a pivot table, showing the performance of each month (column headers) per department (row headers). It has to be be possible to insert a 'as-of date' as a parameter, so the user (PHP) ...
Paul de Roos's user avatar
0 votes
1 answer
306 views

Multiple composite index vs single non-clustered column store index

We have a OLTP system and we have got a grid, which is containing close to 20 columns, coming from multiple tables. The grid loaded based on search parameters involving around 6 columns. The data is ...
Venkataraman R's user avatar
1 vote
2 answers
1k views

SQL Server - indexed view with string_agg

I try to define an indexed view to create full text search index on it. The view itself is created correctly: CREATE OR ALTER VIEW dbo.my_view WITH SCHEMABINDING AS SELECT p.id as protector_id, ...
r34's user avatar
  • 320
1 vote
0 answers
1k views

Updating an indexed view with NOEXPAND

Suppose I have a table T, and I have an indexed view V on it: CREATE TABLE dbo.T (id int PRIMARY KEY, b bit NOT NULL, txt varchar(20)); GO CREATE VIEW dbo.V WITH SCHEMABINDING AS SELECT T.Id, T.txt ...
Charlieface's user avatar
  • 63.4k
0 votes
1 answer
678 views

Performance issues with inserting records into a table used by indexed views?

I have a fairly big table, let's call that 2B records split evenly between 200 partitions (SQL Server 2012). Every day, I have a process that takes 6 hours to create a new partition and insert 10 ...
user3339793's user avatar
0 votes
1 answer
53 views

Updating underlying tables of indexed view but the column is not present in the view

Let's say I have two tables, Country and City. Country(id, fname, president_name) City(id, cname, country_id_fk, mayor_name) City table has a foreign key dependency on the Country table. Let's say I ...
JavaLearner's user avatar
2 votes
0 answers
852 views

Why does STATISTICS_NORECOMPUTE turn on by itself?

I am running SQL Server 13.0.5622.0. I have a number of large indexed views (>5MM rows) defined similar to: CREATE VIEW MyView WITH SCHEMABINDING AS SELECT T1.Column1, T1.Column2 FROM dbo.T1 ...
Mike's user avatar
  • 7,633
1 vote
2 answers
765 views

indexed view update is table scanning 110 million rows for 6 actual rows found out of histogram key bounds

On SQL Server 2017(RTM-CU17) with query optimizer hot fixes on I have an indexed view that is taking a considerable amount of time to update. I am at a loss and cannot figure out why a full table ...
Ben H's user avatar
  • 26
0 votes
2 answers
84 views

Use Sum on extra aggregation and Make Total

I want to create an indexed View. I have this query: SELECT srvmn.BBC_ID AS Inventory, srvInv.ObjectID, srv.State, SUM( IIF(srvInv.Direction = srvInv.ReverseBroken, 1, 0)) AS ...
Massoud Beygi's user avatar
1 vote
0 answers
32 views

Indexed View w Business Logic

I have been tasked to create several 'views' on data that exists on our analytics server. These views are 'business logic' heavy, but will be referenced by potentially multiple tools, so we are trying ...
Andy's user avatar
  • 31
0 votes
0 answers
26 views

Add an index in view if it is simply a simple select on one table. No joins

I know this is DBA 101, but the question was asked and I have no answer ... well I guess what the answer is but need to confirm. I have a view (View1) that is a simple select of one table: Select col1,...
DJElie's user avatar
  • 1
0 votes
1 answer
399 views

Makes it sense to create an indexed view when the data is frequently changed?

I have round about 5 tables which each have more than 1,000,000 datasets inside of them. I`ve read about indexed-views and that they can increase the performance at continuous querys. But the tables/...
Robert Wolf's user avatar
0 votes
1 answer
588 views

Not able to create index on schema binding view

Not able to create index on below schema binding view.It is created from another view (v_prod_manu_sub).It is showing below error message: Cannot create index on view "dbo.V_PROD_MANU" because it ...
Ram's user avatar
  • 775
2 votes
1 answer
66 views

Querying a view after creating a clustered index on it still yields the same query plan

I have the following view SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON GO ALTER VIEW web.vGridHotelBooking WITH SCHEMABINDING AS SELECT HBK_ID, COF_ID, COF_CST_ID, ...
Mihail Shishkov's user avatar
4 votes
3 answers
770 views

How to create indexed view of children count

I am trying to take a table with a parent child relationship and get the number of children. I would like to create an indexed view of the number of children by utilizing COUNT_BIG(*). The problem is ...
ParoX's user avatar
  • 5,803
0 votes
0 answers
49 views

Cannot create Index Views

I have read in forums that index views can speed up the performance since it stores the table. How can I modify my below query to use NewDate as a unique index? I also know there are some limitations ...
raghav's user avatar
  • 45
0 votes
1 answer
192 views

Indexed View vs. Table

I had a long running query (relative to the data) that was hitting an indexed view. I thought an indexed view was physically stored data? I dumped everything into a table and ran the same query ...
JMG's user avatar
  • 55
1 vote
1 answer
124 views

Can I use an indexed view in SQL Server to fetch only non duplicate records

We have a huge table with millions of records. We want to fetch only first record based on some key in that table. When I tried using self-join it's resulting in temp db space issue. From the ...
Icarus's user avatar
  • 445
0 votes
0 answers
85 views

Multiple values in single column as an indexed view

I have such problem. My data is like: Numers(Id) Letters(Id, NumberId) If I do Join query, I get output like that: SELECT N.Id, L.Id FROM Numbers N JOIN Letters L ON N.Id = L.NumberId And the ...
Miłosz Wieczorek's user avatar
3 votes
1 answer
820 views

Create index on a view with "Latest record of group" select

I'm trying to improve performance of my views using indexed views, however I'm not sure if I can overcome the limitations. In my view I'm trying to select latest records for a particular group. I'm ...
Liero's user avatar
  • 26.2k
1 vote
1 answer
266 views

SQL Server If Else Indexed View

In SQL Server 2012, I would like to run a query that checks, if an indexed view exists. If it does, I want to run a SELECT statement WITH(NOEXPAND). If it doesn't, I would like to run a select ...
Dixie's user avatar
  • 23
1 vote
0 answers
270 views

SQLServer indexed views cause very slow deletes from table at "top" of dependency tree

Scenario: SSIS packages loading data. Deletes of sections of data prior to reload taking a very long time. Currently done manually with constraints disabled, data loads done, then constraints re-...
mrmoosehead's user avatar
1 vote
0 answers
2k views

How to update Indexed View in SQL Server?

I am executing more than 40 reports on a daily basis using SSRS. These reports are using similar data-set with some changes on condition. I think it is better to use an indexed view rather than ...
Nawaf's user avatar
  • 540
0 votes
1 answer
1k views

Specify decimal precision of column in a SQL Server indexed view

I am wondering if it's possible to override the default column precision of columns within an indexed view. The view seems to always create the columns with the largest possible precision. A ...
Craig's user avatar
  • 21
1 vote
1 answer
834 views

SQL Server Indexed views used instead of tables

I am a little bit confused about using indexed views in SQL Server 2016. Here is my issue. If I have a fact table with a lot of columns and I create an indexed view named IV_Sales as select ...
presto's user avatar
  • 26
0 votes
2 answers
470 views

Can't create indexed view with schemabinding

I'm trying to script a pretty straight-forward indexed view but SQL is simply refusing my efforts. I've tried researching the issue but haven't had any luck, and unfortunately I'm not exactly a SQL ...
thanby's user avatar
  • 323
2 votes
1 answer
694 views

Is there benefit to index base tables of an indexed view?

After I created the indexed view, I tried disabling all the indexes in base tables including the indexes for foreign key column (constraint is still there) and the query plan for the view stays the ...
Steve's user avatar
  • 11.9k
4 votes
1 answer
582 views

How is BLOB stored in an indexed view?

The Question Assuming I make an indexed view on a table containing a varbinary(max) column, will the binary content be physically copied into the indexed view's B-Tree, or will the original fields ...
Branko Dimitrijevic's user avatar
3 votes
1 answer
632 views

Indexed view with datepart, query on datepart is not using the index

I need to do a query by datepart(day, BornDate) and/or month, on a table that has several million rows, which is vey CPU intenstive. I tried using indexed view with the datepart columns, even ...
Michal Řehout's user avatar
0 votes
0 answers
257 views

I can't create clustered index on view in Microsoft SQL Server 2014 Express

I wanted to create clustered index on view in order to obtain materialized view. Unfortunately the option to create index on view is disabled (faded). Do you know why? I am using Microsoft SQL Server ...
Bartosz Siemasz's user avatar
2 votes
1 answer
2k views

SQL Server columnstore clustered index on an indexed view

I want to have an automatically updated structure in SQL Server that can handle aggregate queries well. Can I create an indexed view in SQL server 2014 that has a columnstore index as its clustered ...
uh_big_mike_boi's user avatar
3 votes
1 answer
2k views

Indexed view with data for the last two weeks

I'm trying to create indexed view containing only the data for the last 2 weeks. This part works fine: CREATE VIEW [dbo].[MainLogView] WITH SCHEMABINDING AS SELECT Id, Date, System, [Function]...
BWA's user avatar
  • 5,742
3 votes
1 answer
2k views

Deterministic function for getting today's date

I am trying to create an indexed view using the following code (so that I can publish it to replication it as a table): CREATE VIEW lc.vw_dates WITH SCHEMABINDING AS SELECT DATEADD(day, DATEDIFF(day,...
bbailes's user avatar
  • 371
0 votes
1 answer
214 views

requirements for an Indexed View

I am currently working towards my certification in SQL Server 70-461. I'm working through some practice tests at the moment and have come across a question on requirements for an indexed view. I ...
Beau6601's user avatar
1 vote
2 answers
251 views

Indexed views. Query ignoring view and uses table instead

My task is to optimize this query: Declare @sumBalance NUMERIC = (select SUM(CURRENT_BALANCE) as Balance from dbo.ACCOUNT_DETAILS) select @sumBalance I've read that the best solution for aggregation ...
S. Elmar's user avatar
1 vote
2 answers
132 views

Why does indexed view materialize?

If we create an index to a view, we materialize the view. Why is the view materialized when it is indexed ? What is the signification as opposed to a non-materialized view ? To my understanding, a ...
Kenny's user avatar
  • 1,922
0 votes
0 answers
894 views

Check constraint on partitioned tables in MSSQL

In our MSSQL server 2008 R2 environment, we have a table which we have partitioned based on a yearly partition function. We need to define a view on this table and want to take advantage of table ...
Puneet Jain's user avatar
0 votes
2 answers
936 views

What types of aggregates can I use to create indexed view

I have been trying to figure out what kinds of aggregates I can use to create indexed view. FYI: I was I able to create one with SUM(). I also found that I can't create indexed view with MIN, MAX and ...
Dilshod's user avatar
  • 3,229