Create Computed Column using data from another table

后端 未结 5 731
忘掉有多难
忘掉有多难 2020-12-01 16:52

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)          


        
5条回答
  •  天命终不由人
    2020-12-01 17:34

    you dont have to add the computed column to your table, because, after its updated,if the original table data got changed, then data become inconsistent , you can always use this select statement to get the column count, or create it as a view

    select p.id,count(*) as count 
    from Picture P
    join PictureUse  U
    on p.id=u.Pictureid 
    group by p.id
    

提交回复
热议问题