Selectively overriding a computed column

时间:2015-05-04 19:23:58

标签: sql-server sequences

I have a feeling this is a simple yes or no answer but I am going to ask it anyways.

I am using a sequence to populate a given ClientID column in my table. This ClientID however can be persisted across multiple records within the table, each one representing a different version of the record, of which only a single is "Active".

My concern is that the first time I preform a revision on the record, which will "Delete" the record by setting it's Deleted bit, and create a new record in the same table with the new values. The new record will have a new ClientID value given to it where it should have persisted the previous ClientID value.

UID ClientID Name        Deleted
20   1        Vendor A    0
21   2        Vendor B    0

If I were to add a new record (non-revision), I would expect the following:

UID ClientID Name        Deleted
20   1        Vendor A    0
21   2        Vendor B    0
22   3        Vendor C    0

But if I were to want to rename (Vendor B) to say ABC Corp, I would want to mark record 22 as deleted and create a new record for "ABC Corp" with a ClientID of 2. (see Below)

UID ClientID Name        Deleted
20   1        Vendor A    0
21   2        Vendor B    1
22   3        Vendor C    0
23   2        ABC Corp    0  <-- FK relationships are still in tact.

But with the sequence in place, I am expecting to see this instead...

UID ClientID Name        Deleted
20   1        Vendor A    0
21   2        Vendor B    1
22   3        Vendor C    0
23   4        ABC Corp    0  <-- Incorrect ClientID (Loss of FK relationship)

Can you selectively override a computed column calculation and insert your own value in it's place?

0 个答案:

没有答案