If I have a table MyTable like this:
Value1 decimal
Then I have a view MyView:
Select SUM(Value1) as SumValue1 from MyTable
When I look at the view's column data type in SSMS under the view's columns section it is a decimal.
Now if I modify the table to:
Value1 real
If I refresh the view's column section in SSMS the data type is still a decimal. Now if I open the view and resave it, the datatype becomes a float.
Is this how it is supposed to be? It seems that the view doesn't change until I resave it.
Yes, this is expected. Tables can be changed in ways that make the views completely invalid. If you want to prevent this from happening, you can use the WITH SCHEMABINDING option when creating the view. From the linked article:
Binds the view to the schema of the underlying table or tables. When SCHEMABINDING is specified, the base table or tables cannot be modified in a way that would affect the view definition. The view definition itself must first be modified or dropped to remove dependencies on the table that is to be modified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With