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 |
|
dewacorp.alliances
452 Posts |
Posted - 2002-12-09 : 02:42:05
|
| HI thereI have this following table called tblAccount1. AccountCode (varchar 4 .. not INT)2. RegionID (varchar 2)3. LocationID (varchar2)I want to make the AccountCode becoming primary key which the value comes from combination of RegionID and LocationID. So when the regionid and locationid get entered (10 and AB for instance) .. the value for AccountCOde will be 10ABTherefore:AccountCode; RegionID; LocationID10AB; 10; AB20AB; 20; ABIs there anyaway that you can do this? Can I use trigger? Any example that I can follow?ThanksVal |
|
|
rihardh
Constraint Violating Yak Guru
307 Posts |
Posted - 2002-12-09 : 04:19:56
|
| A trigger will fail, because it will fire AFTER RegionID and LocationID are inserted (AccountCode = null). Because the column AccountCode is a primary key, a value is required at the time of insertion.I presume that the values for RegionID and LocationID are inserted from some sort of GUI. If so, combine the values there and insert the combined value, but remember, it has to be UNIQUE! |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2002-12-09 : 09:15:50
|
| Your primary key of your table should be RegionID and LocationID. AccountCode is just a formula you can derive from RegionID and LocationID whenever you need to, or do it in a view so you don't have to worry about it.People seem to think primary keys can or should be only 1 field, but they should be whatever the true indicator of uniqueness is for that particular table.- Jeff |
 |
|
|
|
|
|