🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.bazy-danych
Article #183238

Re: MSSQL - problem z widokiem

#183238
From: Adam
Date: Thu, 02 Jul 2009 08:20
60 lines
3124 bytes
Przemysław Rachwał wrote:
> Adam wrote:
>> Mam 3 tabele magazynowe: Towar (TW), Ceny (CN), Stany (SM)
>>
>> W Ceny mam różne ceny mnie interesują ceny zakupu i sprzedaży 
>> (rozróżniane po polu typ)
>> W Stany mam stany magazynowe towarów dla różnych magazynów
>>
>> Chcę mieć widok który mogę aktualizować:
>> twId, twName, cenaZ, cenaS, stanSuma
>>
>> Dla stanów wykonałem widok stanów magazynowych vSM_Sum poprzez 
>> grupowanie:
>> twId, Sum(stan) -> wyciągam sumę stanów na wszystkich magazynach
>>
>>
>> Gdy połączę ze sobą tabele TW, CN i widok vSM_Sum :
>>
>> SELECT TW.id, TW.name, CN.type, CN.price, vSM_Sum.state
>> FROM         dbo.TW INNER JOIN
>>                       dbo.CN ON dbo.TW.id = dbo.CN.twId INNER JOIN
>>                       dbo.vSM_Sum ON dbo.TW.id = dbo.vSM_Sum.twId
>>
>> Wynik dla Select jest OK ale próba edycji tego kończy się błędem:
>> "Niedostateczne informacje o kolumnie klucza w celu aktualizacji i 
>> odświeżenia"
>>
>> Co robię nie tak?
> 
> nie zrobisz takiego widoku z funkcją agregującą
> 
> czytaj dokumentację tam o tym piszą
> 
> Updatable Views
> You can modify the data of an underlying base table through a view, as 
> long as the following conditions are true:
> 
> Any modifications, including UPDATE, INSERT, and DELETE statements, must 
> reference columns from only one base table.
> 
> The columns being modified in the view must directly reference the 
> underlying data in the table columns. The columns cannot be derived in 
> any other way, such as through the following:
> 
> An aggregate function: AVG, COUNT, SUM, MIN, MAX, GROUPING, STDEV, 
> STDEVP, VAR, and VARP.
> 
> A computation. The column cannot be computed from an expression that 
> uses other columns. Columns that are formed by using the set operators 
> UNION, UNION ALL, CROSSJOIN, EXCEPT, and INTERSECT amount to a 
> computation and are also not updatable.
> 
> The columns being modified are not affected by GROUP BY, HAVING, or 
> DISTINCT clauses.
> 
> TOP is not used anywhere in the select_statement of the view together 
> with the WITH CHECK OPTION clause.
> 
Jak w takim razie można wykonać aktualizację pola stan_magazynów jako 
sumę stanów z kilku rekordów innej tabeli?
Technical Details
Message-ID: <h2hql6$d46$1@news.onet.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!not-for-mail
References: <h2hhl9$mp6$1@news.onet.pl> <h2hkm8$aum$1@inews.gazeta.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!not-for-mail
From: Adam <adam70191@op.pl>
Newsgroups: pl.comp.bazy-danych
Subject: Re: MSSQL - problem z widokiem
Date: Thu, 02 Jul 2009 10:20:51 +0200
Organization: http://onet.pl
Lines: 60
Message-ID: <h2hql6$d46$1@news.onet.pl>
References: <h2hhl9$mp6$1@news.onet.pl> <h2hkm8$aum$1@inews.gazeta.pl>
NNTP-Posting-Host: ffg130.internetdsl.tpnet.pl
Mime-Version: 1.0
X-Trace: news.onet.pl 1246522854 13446 83.13.136.130 (2 Jul 2009 08:20:54 GMT)
X-Complaints-To: niusy@onet.pl
NNTP-Posting-Date: Thu, 2 Jul 2009 08:20:54 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.21 (Windows/20090302)
In-Reply-To: <h2hkm8$aum$1@inews.gazeta.pl>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit