I want the computed column to store count totals from another table, how would I do it? (would the following work)
create table sample ( column1 AS (SELECT COUNT(*) FROM table2) PERSISTED )
I want the computed column to store count totals from another table, how would I do it? (would the following work)
create table sample ( column1 AS (SELECT COUNT(*) FROM table2) PERSISTED )
For SQL Server you could potentially do this with an Indexed View.
Those present a host of other restrictions, though, so be sure the value is enough to justify the increased effort in maintenance.
One of the handier aspects of indexed views is that you don't need to query them directly to get the benefits - if the optimizer detects you querying an aggregate that is indexed it'll make use of it "behind the scenes".
Per MSDN:
A computed column is computed from an expression that can use other columns in the same table. The expression can be a noncomputed column name, constant, function, and any combination of these connected by one or more operators. The expression cannot be a subquery.