147
questions
-1
votes
1
answer
20
views
Can SQL views cache the execution plan? [closed]
As I understand it, SQL stored procedures can cache the execution plan, thereby improving performance. Are there anything like indexed views that can achieve the same?
I tried to research the benefits ...
0
votes
0
answers
65
views
Is it recommended to use indexed view on static columns in a frequent changing table?
I am learning indexed views in SQL Server, and I know some general limitation (like we can't do cross database joins etc) and in general, the benefit may not be that significant when the underlying ...
0
votes
0
answers
84
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?
0
votes
1
answer
127
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) ...
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 ...
0
votes
1
answer
64
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 ...
1
vote
2
answers
169
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 ...
1
vote
2
answers
462
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 (.....
2
votes
1
answer
675
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]...
1
vote
1
answer
432
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 '...
0
votes
2
answers
124
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:
...
0
votes
0
answers
157
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.
...
0
votes
1
answer
65
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 ...
-1
votes
2
answers
146
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 ...
0
votes
0
answers
396
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) ...
0
votes
1
answer
377
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 ...
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,
...
1
vote
0
answers
2k
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
...
1
vote
1
answer
838
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 ...
0
votes
1
answer
61
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 ...
2
votes
0
answers
949
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
...
1
vote
2
answers
809
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 ...
0
votes
2
answers
85
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 ...
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 ...
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,...
0
votes
1
answer
538
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/...
0
votes
1
answer
602
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 ...
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,
...
4
votes
3
answers
776
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 ...
0
votes
0
answers
51
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 ...
0
votes
1
answer
198
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 ...
1
vote
1
answer
133
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 ...
0
votes
0
answers
86
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 ...
3
votes
1
answer
870
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 ...
1
vote
1
answer
274
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 ...
1
vote
0
answers
287
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-...
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 ...
0
votes
1
answer
2k
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 ...
1
vote
1
answer
916
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
...
0
votes
2
answers
511
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 ...
2
votes
1
answer
747
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 ...
4
votes
1
answer
634
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 ...
3
votes
1
answer
642
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 ...
0
votes
0
answers
268
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 ...
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 ...
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]...
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,...
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 ...
1
vote
2
answers
266
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 ...
1
vote
2
answers
134
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 ...