Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
e-milio
Starting Member
1 Post |
Posted - 2008-12-08 : 23:40:21
|
| Hi everyone, I have this problem:I want to restrict by the model meta-data (on create table sentence), that one of my primary key that is an identity field (seed 1, and increment step also 1), must increment depending on others key fields, i.e.:My table ‘InteractionMultimediaParts’ has 3 primary keys: - Id (interaction id) - Section - Part number => Identity fieldSo I want that the Part field grows automatically –say it, by model definition, in a identity special feature I suppose- relative to fields Id and Section. For example, this inserts will create the rows: - Insert… (Id, Section) values (1, 1) => Creates row (1, 1, Part = 1) - Insert… (Id, Section) values (1, 1) => Creates row (1, 1, Part = 2) - Insert… (Id, Section) values (1, 2) => Creates row (1, 2, Part = 1) - ...Obviously using usual identity -field part defined as “...IDENTITY(1, 1)”- I have a non relative increment Part field auto increment. As obvious too, I can achieve this with a store procedure, but I still prefer, if it’s possible, to specify on table SQL script creation this increment behavior by default on table insert.Thanks a lot in advance, greetings,e-milio. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-09 : 02:08:04
|
| seems like what you need is to define part_no as a calculated field with value as count of records where id=id and section< current section. |
 |
|
|
|
|
|
|
|