Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Index View or Table?
Message
De
11/03/2016 13:34:19
 
 
À
10/03/2016 16:13:05
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Indexation
Versions des environnements
SQL Server:
SQL Server 2008 R2
Divers
Thread ID:
01632781
Message ID:
01632873
Vues:
42
>>Hi,
>>
>>a system I have has a table called Transactions, then a view based on that called viewTransactions and then another view based on the first view called viewTopTransactions.
>>
>>Should I create indexes on the underlying table and that will speed up queries against the views? Or should I create indexes on the views? or should I index both table and views?
>>
>>The queries are like this:
>>
>>SELECT DISTINCT [PNRStatus] FROM [viewTransactions] ORDER BY [PNRStatus]
>
>HI, Frank - you can create materialized indexes from views. I have an online article that talks about an example:
>
>http://www.codemag.com/Article/1601051 (the first of the thirteen items). Go to the section called "Answer 1: Knowing the Differences Between Materialized Views and Standard Views"
>
>One thing I would definitely avoid (as Naomi said) is creating views off of views. Once someone does that, it usually paves the way for views off views off views. These can impact performance and can be difficult to maintain.
>
>When you say you want to view Top Transactions, what would the "top" be based on?
>
>Also, can you post the structure of the Transactions table?

Thanks Kevin, I'll check out your article.

The top is based on Timestamp descending (so the latest transactions are returned)

This is the Create script:
CREATE TABLE [dbo].[Transactions](
	[GUID] [uniqueidentifier] NOT NULL,
	[DateImported] [datetime] NULL,
	[OID] [nvarchar](10) NULL,
	[PNR] [nvarchar](6) NULL,
	[StoredFare] [float] NULL,
	[RMQ] [nvarchar](60) NULL,
	[LowerFare] [float] NULL,
	[Timestamp] [datetime] NULL,
	[Month] [nvarchar](50) NULL,
	[Day] [int] NULL,
	[Year] [int] NULL,
	[Time] [varchar](50) NULL,
	[MFRA] [int] NULL,
	[AgentID] [varchar](6) NULL,
	[PNRStatus] [varchar](10) NULL,
	[Segments] [varchar](20) NULL,
	[Currency] [varchar](3) NULL,
	[ScriptResult] [varchar](10) NULL,
 CONSTRAINT [PK_Transactions] PRIMARY KEY CLUSTERED 
(
	[GUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Transactions] ADD  CONSTRAINT [DF_Transactions_GUID]  DEFAULT (newsequentialid()) FOR [GUID]
GO

ALTER TABLE [dbo].[Transactions] ADD  CONSTRAINT [DF_Transactions_DateImported]  DEFAULT (getdate()) FOR [DateImported]
GO
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform