I'm trying to make an updatable view on a table with an identity column, but the view keeps complaining that the identity column can't be null (where the table itself allows this fine.)The situation: I have a series of devices, distinguished by a unique name, each of which belongs to a cluster, each of which is itself distinguished by a unique name. However, both cluster names and device names are long and referenced many times by other tables; to save storage space we tie each name to an identity key.A simplified example:create table cluster ( id int identity unique, name varchar(1000) primary key)create table device_storage_test ( id int identity unique, name varchar(1000) primary key, cluster_id int foreign key references cluster (id ))create view device_test as select device_storage_test.id, device_storage_test.name, cluster.name as clusterfrom device_storage_test inner join cluster on cluster_id = cluster.idcreate trigger device_test_inserton device_test instead of insertas begin -- insert the cluster if it does not already exist insert into cluster ( name ) select inserted.cluster from inserted left outer join cluster on inserted.cluster = cluster.name where cluster.name is null -- insert the device insert into device_storage_test (name, cluster_id) select inserted.name, cluster.id from inserted left outer join cluster on inserted.cluster = cluster.name end
Using insert into device_storage_test (name, cluster_id) values ('device1', 1) works fine (so long as cluster_id 1 exists) but insert into device_test (name, cluster) values ('device2', 'cluster2') results in the message: "The column 'id' in table 'device_test' cannot be null."