Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a SQL Server 2008 R2 database. This database has two tables called Pictures and PictureUse.

Picture table has the following columns:

Id (int)  

PictureName (nvarchar(max))    

CreateDate (datetime ) 

PictureUse table has the following columns :

Id (int) 

Pictureid (int) 

CreateDate (datetime ) 

How to create a computed column in the Picture table which tells me that how many times this picture has been clicked?

share|improve this question
If the question was reworded to ask about the strategy to measure resource usage, it might fit better. For what its worth, I feel metrics are a such a distinct concern they shouldn't share the same logical record space as the resource definition. E.g. the metrics would be a separate table and separate set of queries. – JustinC Nov 21 '12 at 12:46

closed as off topic by thorsten müller, gnat, ChrisF Nov 21 '12 at 8:56

Questions on Programmers Stack Exchange are expected to relate to software development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

You can't create calculated fields which use other tables. You can create a View instead. e.g.

Create View V_PictureUseCnt as
Select p.ID,p.Picturename
,(Select Count(*) from PictureUue u where u.PictureID = p.ID) as cnt
From Picture p 
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.