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 |
|
tomwms
Starting Member
2 Posts |
Posted - 2010-04-11 : 20:44:30
|
| I have a table with a field called "floor_number" which is a INT.I want to prevent anyone from changing the data in this field once it has been initially entered. The field is NOT primary or unique. I simply don't want the first value saved to it to ever be able to be changed later on.I need to have this protection at the DB level because I don't know where the changes might be coming from.Please! I know "in theory" about Constraints and Triggers etc. What I really need is some "workable code". I don't think what I am looking for is more than 4-5 lines of code. I just can't figure that part out.Please help!!! ThanksTom |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-04-11 : 20:51:36
|
add this 1 line code to your update trigger to restore the floor_number if it was changedupdate a set floor_number = d.floor_number from atable a inner join deleted d on a.pk = d.pk where a.floor_number <> d.floor_number you can also use exists() to detect changes and raise an error in the update trigger KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
tomwms
Starting Member
2 Posts |
Posted - 2010-04-11 : 23:43:38
|
| Khtan,I appreciate your help but as a newbie I am a little confused by the abbreviations such as "a" "d" "atable".Could you refine your code to include my actual table name so that I know what is real and what is simply an example.My table name is "Building_one"Thanks,Tom |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-04-12 : 00:11:21
|
atable is your actual table name. replace it with your table name Building_onea, d are just table alias KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|