Re: index on a view

From: Hugo Kornelis (hugo_at_pe_NO_rFact.in_SPAM_fo)
Date: 02/21/05


Date: Mon, 21 Feb 2005 11:28:33 +0100

On Fri, 18 Feb 2005 14:58:31 GMT, cmarano wrote:

>Hello,
>
>I have two applications !
>
>In one i have a tabel : TAB with 2 fields cod and descr , length 3 and 60
>( varchar)
>
>In the other application i have to read e write in this table , but i have
>different field name :
>cod1 and des (alias). I repair to this with a view .
>
>Now i have to chain this table with key (cod1) this is the problem.
(snip)

Hi Carlo,

Thanks for posting your explanation and the CREATE TABLE and CREATE VIEW
statements.

In this case, there is no reason to index the view. In fact: if you do,
SQL Server will have to maintain a copy of all data in the table and
change that copy whenever the data in the table changes. You double the
storage space required, give SQL Server extra work to do on updates and
you gain nothing from it.

To be able to use your other application without changing it, you just
need a normal (non-indexed) view. In queries, SQL Server will substitute
the view's name with the view's definition (and since that is simple, it
comes at no extra cost). Similar, updates to the view will be translated
back into updates to the table - and again, at a performance price you
won't notice, since it's a very simple one-on-one translation.

You also don't need the TOP 100 PERCENT in the view (you'll get all rows
by default - only use TOP if you want less than all rows) and you should
remove the ORDER BY (it's not guaranteed to work anyway - it'll be only
used to determine which rows are or are not in the TOP 100 PERCENT, not to
determine the ordering of rows returned by the view).

CREATE VIEW dbo.TABCE05F
AS
SELECT cod_zona AS T5COAR, des_zona AS T5DEAR
FROM dbo.CO_ZONE
GO

Best, Hugo

-- 
(Remove _NO_ and _SPAM_ to get my e-mail address)


Relevant Pages

  • Re: Cannot update
    ... not install the updates you referred to. ... highly recommend way for the later one is to install SQL server, ... Microsoft CSS Online Newsgroup Support ...
    (microsoft.public.windows.server.sbs)
  • RE: Ad hoc updates to system catalogs are not enabled
    ... Thank you for choosing Microsoft! ... system tables even after you disable allow updates. ... Prevent other users from accessing SQL Server while you are directly updating system ... This command starts an instance of SQL Server in single-user mode and enables allow ...
    (microsoft.public.sqlserver.security)
  • Re: Bulk inserting into database using ADO.NET... deadly slow?
    ... program (look in your SQL Server documentation for "BULK INSERT"). ... > the DataSet, so to reduce the DB updates, but I found that when reaching ... > about 100K rows the DataSet becomes slower and slower, ... why is it so painfully slow to insert big chunks ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Cascading Changes in SQL Server
    ... is this article saying that SQL server ... >> relationship had cascading deletes and updates. ... or modify other FOREIGN KEY constraints. ...
    (microsoft.public.sqlserver.server)
  • Re: [PATCH 1/5] HOWTO: add Japanese translation of Documentation/HOWTO
    ... Add the japanese translation of the Documentation/HOWTO file. ... new file mode 100644 ... "This is a version of Documentation/HOWTO translated into Japanese". ... +comments or updates of this file, ...
    (Linux-Kernel)