How to put foreign key constraints on a computed fields in sql server?

天涯浪子 提交于 2019-12-01 03:43:02

The computed field is composed of char(M), char(N) and so on, that add up to M+N+.. = 50, but the computed field itself is varchar(50). Changing RefersToComputed1 to varchar(50) instead of char(50) solves the problem.

Computed fields foreign keys require no special treatment (although persisted might be required on the computed column).

Is RefersToComputed1 a primary key of type char(50)?

Is RefersToComputed1 exactly the same datatype, length and collation exactly as Computed1?

Double check it... for example, do you need a final CAST or COLLATE on Computed1 to make sure it is what you expect? I say this because the error is saying that the 2 columns are different

Edit: char and varchar are not identical datatypes, so you'll need a CAST to change it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!