What problems can occur if a view contains a value that exceeds its field's CHARACTER_MAX_LENGTH?

StackOverflow https://stackoverflow.com/questions/23381357

  •  12-07-2023
  •  | 
  •  

Pergunta

If I have a view that has a column of length 1 that points to a column in a table that has length 2, then I am still able to select the value from the view, even though the value exceeds the length of the view's column.

See e.g. http://sqlfiddle.com/#!6/76a39/1

I am not sure why this is allowed, but could this cause any problems down the line, when the view is referenced?

Foi útil?

Solução

If you want to make sure that the metadata about a view is always accurate, use the SCHEMABINDING option when you create it:

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. When you use SCHEMABINDING, the select_statement must include the two-part names (schema.object) of tables, views, or user-defined functions that are referenced. All referenced objects must be in the same database.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top